1 21 package oracle.toplink.essentials.internal.ejb.cmp3.transaction.base; 23 24 import java.sql.Connection ; 25 import java.sql.SQLException ; 26 import javax.transaction.*; 27 import oracle.toplink.essentials.internal.ejb.cmp3.base.ExceptionFactory; 28 import oracle.toplink.essentials.internal.ejb.cmp3.jdbc.base.DataSourceImpl; 29 30 35 public class TransactionManagerImpl implements TransactionManager, UserTransaction { 36 TransactionImpl tx; 38 39 40 41 42 private void debug(String s) { 43 System.out.println(s); 44 } 45 46 49 public TransactionManagerImpl() { 50 this.tx = null; 51 } 52 53 56 public boolean isTransactionActive() { 57 return tx != null; 58 } 59 60 63 public Connection getConnection(DataSourceImpl ds, String user, String password) throws SQLException { 64 return (tx == null) ? null : tx.getConnection(ds, user, password); 65 } 66 67 68 69 70 public void begin() throws NotSupportedException, SystemException { 71 debug("Tx - begin"); 72 73 if (isTransactionActive()) { 74 throw new ExceptionFactory().txActiveException(); 75 } 76 77 tx = new TransactionImpl(); 79 } 80 81 public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException , IllegalStateException , SystemException { 82 debug("Tx - commit"); 83 84 if (!isTransactionActive()) { 85 throw new ExceptionFactory().txNotActiveException(); 86 } 87 try{ 88 tx.commit(); 89 }finally{ 90 tx = null; 91 } 92 } 93 94 public int getStatus() throws SystemException { 95 return (!isTransactionActive()) ? Status.STATUS_NO_TRANSACTION : tx.getStatus(); 96 } 97 98 public Transaction getTransaction() throws SystemException { 99 return tx; 100 101 } 102 103 public void rollback() throws IllegalStateException , SecurityException , SystemException { 104 debug("Tx - rollback"); 105 106 if (!isTransactionActive()) { 107 throw new ExceptionFactory().txNotActiveException(); 108 } 109 try{ 110 tx.rollback(); 111 }finally{ 112 tx = null; 113 } 114 } 115 116 public void setRollbackOnly() throws IllegalStateException , SystemException { 117 debug("Tx - rollback"); 118 119 if (!isTransactionActive()) { 120 throw new ExceptionFactory().txNotActiveException(); 121 } 122 tx.setRollbackOnly(); 123 } 124 125 126 127 128 public Transaction suspend() throws SystemException { 129 return null; 130 } 131 132 public void resume(Transaction transaction) throws InvalidTransactionException, IllegalStateException , SystemException { 133 } 135 136 public void setTransactionTimeout(int i) throws SystemException { 137 } 139 } 140 | Popular Tags |