1 21 package oracle.toplink.essentials.internal.ejb.cmp3.transaction.base; 23 24 import javax.persistence.TransactionRequiredException; 25 26 import oracle.toplink.essentials.internal.ejb.cmp3.base.*; 27 import oracle.toplink.essentials.exceptions.TransactionException; 28 import oracle.toplink.essentials.internal.localization.ExceptionLocalization; 29 import oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl; 30 31 42 public class EntityTransactionWrapper extends TransactionWrapperImpl { 43 44 protected EntityTransactionImpl entityTransaction; 45 46 public EntityTransactionWrapper(EntityManagerImpl entityManager) { 47 super(entityManager); 48 } 49 50 51 57 public Object checkForTransaction(boolean validateExistence){ 58 if (entityTransaction != null && entityTransaction.isActive()) { 59 return entityTransaction; 60 } 61 if (validateExistence){ 62 throwCheckTransactionFailedException(); 63 } 64 return null; 65 } 66 67 73 public RepeatableWriteUnitOfWork getTransactionalUnitOfWork(Object transaction){ 74 if (transaction == null){ 75 return null; 76 } 77 if (this.localUOW == null){ 78 this.localUOW = new RepeatableWriteUnitOfWork(entityManager.getServerSession().acquireClientSession()); 79 this.localUOW.setShouldCascadeCloneToJoinedRelationship(true); 80 } 81 return (RepeatableWriteUnitOfWork)this.localUOW; 82 } 83 84 public EntityManagerImpl getEntityManager(){ 85 return entityManager; 86 } 87 88 public void registerUnitOfWorkWithTxn(UnitOfWorkImpl uow){ 89 throw new TransactionRequiredException(ExceptionLocalization.buildMessage("join_trans_called_on_entity_trans")); } 91 92 public boolean shouldClose() { 93 return (this.entityTransaction == null || ! this.entityTransaction.isActive()); 94 } 95 96 public boolean shouldFlushBeforeQuery(UnitOfWorkImpl uow){ 97 return true; 98 } 99 100 protected void throwCheckTransactionFailedException() { 101 throw TransactionException.transactionNotActive(); 102 } 103 104 109 public void markLastTransaction() { 110 if(entityTransaction != null) { 111 entityTransaction.markLastTransaction(); 112 } 113 } 114 public boolean hasLastTransactionCompleted() { 115 return entityTransaction != null && entityTransaction.hasLastTransactionCompleted(); 116 } 117 118 } 119 | Popular Tags |