1 package org.enhydra.dods.xa; 2 3 import java.sql.SQLException ; 4 import java.util.Vector ; 5 6 import javax.naming.InitialContext ; 7 import javax.transaction.HeuristicMixedException ; 8 import javax.transaction.HeuristicRollbackException ; 9 import javax.transaction.RollbackException ; 10 import javax.transaction.SystemException ; 11 import javax.transaction.UserTransaction ; 12 13 import org.enhydra.dods.cache.DOCache; 14 15 import com.lutris.appserver.server.sql.CachedDBTransaction; 16 import com.lutris.appserver.server.sql.CoreDO; 17 import com.lutris.appserver.server.sql.DBConnection; 18 import com.lutris.appserver.server.sql.DBQuery; 19 import com.lutris.appserver.server.sql.DBTransaction; 20 import com.lutris.appserver.server.sql.Transaction; 21 22 25 public class XAUserTransaction implements CachedDBTransaction { 26 27 UserTransaction utInternal = null; 28 29 CachedDBTransaction dbtInternal = null; 30 31 XAUserTransactionFactory factory = null; 32 33 protected XAUserTransaction(DBConnection conn, String utln, int defaultTimeout, XAUserTransactionFactory factory, 34 XATransactionFactory xaTnFactory) throws DodsJtaException { 35 try { 36 this.factory = factory; 37 InitialContext ictx = new InitialContext (); 38 utInternal = (UserTransaction ) ictx.lookup(utln); 39 this.factory.makeDodsJtaThreadContext(this); 40 utInternal.setTransactionTimeout(defaultTimeout); 41 utInternal.begin(); 42 dbtInternal = (CachedDBTransaction) (xaTnFactory.getTransaction(conn)); 43 } catch (Exception e) { 44 e.printStackTrace(); 45 throw new DodsJtaException("Error during XAUserTransaction creation"); 46 } 47 } 48 49 54 public boolean isReleased() { 55 return dbtInternal.isReleased(); 56 } 57 58 63 public CoreDO[] getDOs() { 64 return dbtInternal.getDOs(); 65 } 66 67 72 public void saveDirtyDOs() { 73 dbtInternal.saveDirtyDOs(); 74 } 75 76 81 public DOCache getTransactionCache() { 82 return dbtInternal.getTransactionCache(); 83 } 84 85 90 public Vector getDeletedDOs() { 91 return dbtInternal.getDeletedDOs(); 92 } 93 94 99 public void addDeletedDO(CoreDO DO) { 100 dbtInternal.addDeletedDO(DO); 101 102 } 103 104 109 public void resetDeletedDOs() { 110 dbtInternal.resetDeletedDOs(); 111 } 112 113 118 public void dontAggregateDOModifications() { 119 dbtInternal.dontAggregateDOModifications(); 120 121 } 122 123 128 public boolean getAutoWrite() { 129 return dbtInternal.getAutoWrite(); 130 } 131 132 137 public boolean isFirstWrite() { 138 return dbtInternal.isFirstWrite(); 139 } 140 141 146 public void setFirstWrite(boolean newfw) { 147 dbtInternal.setFirstWrite(newfw); 148 } 149 150 155 public boolean wasReadOnly() { 156 return dbtInternal.wasReadOnly(); 157 } 158 159 164 public void update(Transaction transaction) { 165 dbtInternal.update(transaction); 166 } 167 168 173 public void delete(Transaction transaction) { 174 dbtInternal.delete(transaction); 175 } 176 177 182 public void insert(Transaction transaction) { 183 dbtInternal.insert(transaction); 184 } 185 186 191 public void commit() throws SQLException { 192 try { 193 utInternal.commit(); 194 } catch (SecurityException e) { 195 e.printStackTrace(); 196 throw new SQLException ("SecurityException in commit:" + e.getMessage()); 197 } catch (IllegalStateException e) { 198 e.printStackTrace(); 199 throw new SQLException ("IllegalStateException in commit:" + e.getMessage()); 200 } catch (RollbackException e) { 201 e.printStackTrace(); 202 throw new SQLException ("RollbackException in commit:" + e.getMessage()); 203 } catch (HeuristicMixedException e) { 204 e.printStackTrace(); 205 throw new SQLException ("HeuristicMixedException in commit:" + e.getMessage()); 206 } catch (HeuristicRollbackException e) { 207 e.printStackTrace(); 208 throw new SQLException ("HeuristicRollbackException in commit:" + e.getMessage()); 209 } catch (SystemException e) { 210 e.printStackTrace(); 211 throw new SQLException ("SystemException in commit:" + e.getMessage()); 212 } finally { 213 this.factory.closeDodsJtaThreadContext(this); 214 } 215 } 216 217 222 public void rollback() throws SQLException { 223 try { 224 utInternal.rollback(); 225 } catch (IllegalStateException e) { 226 e.printStackTrace(); 227 throw new SQLException ("IllegalStateException in rollback:" + e.getMessage()); 228 } catch (SecurityException e) { 229 e.printStackTrace(); 230 throw new SQLException ("SecurityException in rollback:" + e.getMessage()); 231 } catch (SystemException e) { 232 e.printStackTrace(); 233 throw new SQLException ("SystemException in rollback:" + e.getMessage()); 234 } finally { 235 this.factory.closeDodsJtaThreadContext(this); 236 } 237 238 } 239 240 245 public void release() { 246 dbtInternal.release(); 247 } 248 249 254 public boolean handleException(SQLException e) { 255 return dbtInternal.handleException(e); 256 } 257 258 263 public Transaction getDO(Transaction transaction) { 264 return dbtInternal.getDO(transaction); 265 } 266 267 273 public Transaction getDO(Transaction transaction, int action) { 274 return dbtInternal.getDO(transaction, action); 275 } 276 277 282 public String getDatabaseName() { 283 return dbtInternal.getDatabaseName(); 284 } 285 286 291 public void setDatabaseName(String dbName) { 292 dbtInternal.setDatabaseName(dbName); 293 } 294 295 300 public void write() throws SQLException { 301 dbtInternal.write(); 302 } 303 304 309 public void lockDO(Transaction cdo) throws SQLException { 310 dbtInternal.lockDO(cdo); 311 } 312 313 318 public DBQuery createQuery() throws SQLException { 319 return dbtInternal.createQuery(); 320 } 321 322 327 public boolean preventCacheQueries() { 328 return dbtInternal.preventCacheQueries(); 329 } 330 331 public boolean equals(Object trans) { 332 if (trans instanceof XAUserTransaction) { 333 XAUserTransaction xaUserTrans = (XAUserTransaction) trans; 334 return trans == this; 335 } else if (trans instanceof XATransaction) { 336 XATransaction xaTrans = (XATransaction) trans; 337 return dbtInternal.equals(xaTrans.current); 338 } else if (trans instanceof DBTransaction) { 339 DBTransaction dbTrans = (DBTransaction) trans; 340 return dbtInternal.equals(dbTrans); 341 } 342 return false; 343 } 344 } 345 | Popular Tags |