1 package org.enhydra.dods.xa; 2 3 import java.sql.SQLException ; 4 import java.util.Hashtable ; 5 6 import javax.naming.InitialContext ; 7 import javax.transaction.Transaction ; 8 9 import org.enhydra.dods.CommonConstants; 10 import org.enhydra.dods.DODS; 11 12 import com.lutris.appserver.server.sql.AbstractDBTransactionFactory; 13 import com.lutris.appserver.server.sql.DBConnection; 14 import com.lutris.appserver.server.sql.DBTransaction; 15 import com.lutris.appserver.server.sql.DBTransactionFactoryCreator; 16 import com.lutris.appserver.server.sql.LogicalDatabase; 17 import com.lutris.appserver.server.sql.standard.DatabaseConfiguration; 18 import com.lutris.appserver.server.sql.standard.StandardLogicalDatabase; 19 import com.lutris.logging.Logger; 20 21 28 29 30 public class XATransactionFactory implements AbstractDBTransactionFactory { 31 32 35 AbstractDBTransactionFactory adbtf; 36 37 Hashtable dodsTransactions = new Hashtable (128); 38 39 public static final int XA_INGORE = 0; 40 public static final int XA_WARN = 1; 41 public static final int XA_WARN_WITH_TRACE = 2; 42 public static final int XA_THROW_EXCEPTION = 3; 43 public static final int XA_THROW_ERROR = 4; 44 45 46 private boolean configured = false; 47 private int defaultTimeout = CommonConstants.DEFAULT_XA_DEFAULT_TIMEOUT; 48 private int xaUsageCase = XA_INGORE; 49 private String strTransactionManagerLookupName; 50 private String strWrappedImplFactory; 51 52 55 private LogicalDatabase logicalDb = null; 56 57 60 public void setLogicalDb(LogicalDatabase ldb) { 61 logicalDb = ldb; 62 } 63 64 67 public LogicalDatabase getLogicalDb() { 68 return logicalDb; 69 } 70 ; 71 72 75 public int getDefaultTimeout() { 76 return defaultTimeout; 77 } 78 79 80 81 public DBTransaction getTransaction(DBConnection conn) throws SQLException { 82 if(!configured) { 83 try { 84 DatabaseConfiguration dbco = ((StandardLogicalDatabase)getLogicalDb()).getDatabaseConfiguration(); 85 defaultTimeout = dbco.getXaDefaultTimeout(); 86 strTransactionManagerLookupName = dbco.getXaTransactonManagerLookupName(); 87 strWrappedImplFactory = dbco.getXaWrappedTransImplFactory(); 88 xaUsageCase = dbco.getXaUsageCase(); 89 configured = true; 90 } catch (Exception e) { 91 DODS.getLogChannel().write(Logger.CRITICAL,"Creating XATransactionFactory faild" ); 92 e.printStackTrace(); 93 } 94 } 95 synchronized (XATransactionFactory.class) { 96 if (null == adbtf) { 97 adbtf = DBTransactionFactoryCreator.getDBTransactionFactory(strWrappedImplFactory,getLogicalDb()); 98 } 99 } 100 Transaction xaTrans = null; 101 try { 102 InitialContext ictx = new InitialContext (); 103 javax.transaction.TransactionManager tm = (javax.transaction.TransactionManager ) ictx.lookup(strTransactionManagerLookupName); 104 tm.setTransactionTimeout(defaultTimeout); 105 xaTrans = tm.getTransaction(); 106 } catch (Exception e) { 107 e.printStackTrace(); 108 throw new SQLException (e.getMessage()); 109 } 110 XATransaction ret = new XATransaction(xaTrans,adbtf,conn,xaUsageCase,defaultTimeout,dodsTransactions); 111 try { 112 xaTrans.enlistResource(ret); 113 } catch (Exception e) { 114 e.printStackTrace(); 115 throw new SQLException (e.getMessage()); 116 } 117 return ret; 118 } 119 120 } 121 | Popular Tags |