1 17 package org.alfresco.repo.version.common.counter.hibernate; 18 19 import org.alfresco.repo.domain.StoreKey; 20 import org.alfresco.repo.domain.VersionCount; 21 import org.alfresco.repo.domain.hibernate.VersionCountImpl; 22 import org.alfresco.repo.version.common.counter.VersionCounterDaoService; 23 import org.alfresco.service.cmr.repository.StoreRef; 24 import org.springframework.orm.hibernate3.support.HibernateDaoSupport; 25 26 36 public class HibernateVersionCounterDaoServiceImpl extends HibernateDaoSupport implements VersionCounterDaoService 37 { 38 44 private VersionCount getVersionCounter(StoreRef storeRef) 45 { 46 StoreKey storeKey = new StoreKey(storeRef.getProtocol(), storeRef.getIdentifier()); 47 VersionCount versionCounter = (VersionCount) getHibernateTemplate().get(VersionCountImpl.class, storeKey); 49 if (versionCounter == null) 51 { 52 versionCounter = new VersionCountImpl(); 54 versionCounter.setKey(storeKey); 55 getHibernateTemplate().save(versionCounter); 56 } 57 return versionCounter; 58 } 59 60 66 public synchronized int nextVersionNumber(StoreRef storeRef) 67 { 68 VersionCount versionCounter = getVersionCounter(storeRef); 70 return versionCounter.incrementVersionCount(); 72 } 73 74 80 public synchronized int currentVersionNumber(StoreRef storeRef) 81 { 82 VersionCount versionCounter = getVersionCounter(storeRef); 84 return versionCounter.getVersionCount(); 86 } 87 88 96 public synchronized void resetVersionNumber(StoreRef storeRef) 97 { 98 VersionCount versionCounter = getVersionCounter(storeRef); 100 versionCounter.resetVersionCount(); 102 } 103 } 104 | Popular Tags |