1 17 package org.alfresco.repo.transaction; 18 19 import javax.transaction.UserTransaction ; 20 21 import org.alfresco.service.transaction.TransactionService; 22 import org.alfresco.util.transaction.SpringAwareUserTransaction; 23 import org.springframework.transaction.PlatformTransactionManager; 24 import org.springframework.transaction.TransactionDefinition; 25 26 31 public class TransactionComponent implements TransactionService 32 { 33 private PlatformTransactionManager transactionManager; 34 private boolean readOnly = false; 35 36 41 public void setTransactionManager(PlatformTransactionManager transactionManager) 42 { 43 this.transactionManager = transactionManager; 44 } 45 46 51 public void setAllowWrite(boolean allowWrite) 52 { 53 this.readOnly = !allowWrite; 54 } 55 56 public boolean isReadOnly() 57 { 58 return readOnly; 59 } 60 61 64 public UserTransaction getUserTransaction() 65 { 66 SpringAwareUserTransaction txn = new SpringAwareUserTransaction( 67 transactionManager, 68 this.readOnly, 69 TransactionDefinition.ISOLATION_DEFAULT, 70 TransactionDefinition.PROPAGATION_REQUIRED, 71 TransactionDefinition.TIMEOUT_DEFAULT); 72 return txn; 73 } 74 75 78 public UserTransaction getUserTransaction(boolean readOnly) 79 { 80 SpringAwareUserTransaction txn = new SpringAwareUserTransaction( 81 transactionManager, 82 (readOnly | this.readOnly), 83 TransactionDefinition.ISOLATION_DEFAULT, 84 TransactionDefinition.PROPAGATION_REQUIRED, 85 TransactionDefinition.TIMEOUT_DEFAULT); 86 return txn; 87 } 88 89 92 public UserTransaction getNonPropagatingUserTransaction() 93 { 94 SpringAwareUserTransaction txn = new SpringAwareUserTransaction( 95 transactionManager, 96 this.readOnly, 97 TransactionDefinition.ISOLATION_DEFAULT, 98 TransactionDefinition.PROPAGATION_REQUIRES_NEW, 99 TransactionDefinition.TIMEOUT_DEFAULT); 100 return txn; 101 } 102 103 106 public UserTransaction getNonPropagatingUserTransaction(boolean readOnly) 107 { 108 SpringAwareUserTransaction txn = new SpringAwareUserTransaction( 109 transactionManager, 110 (readOnly | this.readOnly), 111 TransactionDefinition.ISOLATION_DEFAULT, 112 TransactionDefinition.PROPAGATION_REQUIRES_NEW, 113 TransactionDefinition.TIMEOUT_DEFAULT); 114 return txn; 115 } 116 } 117 | Popular Tags |