package net.sourceforge.fenixedu.persistenceTier; import org.apache.ojb.broker.PersistenceBroker; import pt.ist.fenixWebFramework.services.ServiceManager; import pt.ist.fenixframework.pstm.FenixCache; import pt.ist.fenixframework.pstm.Transaction; import pt.utl.ist.berserk.storage.ITransactionBroker; import pt.utl.ist.berserk.storage.exceptions.StorageException; import com.linkare.commons.metainfo.Linkare; public class SuportePersistenteOJB implements ISuportePersistente, ITransactionBroker { private static SuportePersistenteOJB _instance = null; public static synchronized SuportePersistenteOJB getInstance() { if (_instance == null) { _instance = new SuportePersistenteOJB(); } return _instance; } /** Creates a new instance of SuportePersistenteOJB */ private SuportePersistenteOJB() { } public void iniciarTransaccao() { // commit any current transaction if (Transaction.current() != null) { Transaction.commit(); } Transaction.begin(); } public void confirmarTransaccao() { Transaction.checkpoint(); Transaction.currentFenixTransaction().setReadOnly(); } public void cancelarTransaccao() { Transaction.abort(); Transaction.begin(); Transaction.currentFenixTransaction().setReadOnly(); } public void beginTransaction() { if (ServiceManager.isInsideBerserkService()) this.iniciarTransaccao(); } public void commitTransaction() { if (ServiceManager.isInsideBerserkService()) this.confirmarTransaccao(); } public void abortTransaction() throws StorageException { if (ServiceManager.isInsideBerserkService()) this.cancelarTransaccao(); } public void lockRead(java.util.List list) throws StorageException { } public void lockRead(Object obj) throws StorageException { } public void lockWrite(Object obj) throws StorageException { } @Linkare(author = "José Pereira") public static PersistenceBroker getCurrentPersistenceBroker() { return Transaction.getOJBBroker(); } @Linkare(author = "José Pereira") public void clearCache() { getCurrentPersistenceBroker().clearCache(); } @Linkare(author = "José Pereira") public Integer getNumberCachedItems() { return Integer.valueOf(FenixCache.getNumberOfCachedItems()); } }