1 25 package org.ofbiz.entity.transaction; 26 27 import java.sql.Connection ; 28 import java.sql.SQLException ; 29 30 import javax.naming.NamingException ; 31 import javax.transaction.TransactionManager ; 32 import javax.transaction.UserTransaction ; 33 34 import org.objectweb.jotm.Jotm; 35 import org.objectweb.transaction.jta.TMService; 36 import org.ofbiz.base.util.Debug; 37 import org.ofbiz.entity.GenericEntityException; 38 import org.ofbiz.entity.config.DatasourceInfo; 39 import org.ofbiz.entity.config.EntityConfigUtil; 40 import org.ofbiz.entity.jdbc.ConnectionFactory; 41 42 49 public class JotmFactory implements TransactionFactoryInterface { 50 51 public static final String module = JotmFactory.class.getName(); 52 53 private static TMService jotm; 54 static { 55 try { 56 jotm = new Jotm(true, false); 58 } catch (NamingException ne) { 59 Debug.logError(ne, "Problems creating JOTM instance", module); 60 } 61 } 62 63 66 public TransactionManager getTransactionManager() { 67 if (jotm != null) { 68 return jotm.getTransactionManager(); 69 } else { 70 Debug.logError("Cannot get TransactionManager, JOTM object is null", module); 71 return null; 72 } 73 } 74 75 78 public UserTransaction getUserTransaction() { 79 if (jotm != null) { 80 return jotm.getUserTransaction(); 81 } else { 82 Debug.logError("Cannot get UserTransaction, JOTM object is null", module); 83 return null; 84 } 85 } 86 87 public String getTxMgrName() { 88 return "jotm"; 89 } 90 91 public Connection getConnection(String helperName) throws SQLException , GenericEntityException { 92 DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName); 93 94 if (datasourceInfo != null && datasourceInfo.inlineJdbcElement != null) { 95 try { 97 Connection con = MinervaConnectionFactory.getConnection(helperName, datasourceInfo.inlineJdbcElement); 98 if (con != null) return con; 99 } catch (Exception ex) { 100 Debug.logError(ex, "JOTM is the configured transaction manager but there was an error getting a database Connection through JOTM for the " + helperName + " datasource. Please check your configuration, class path, etc.", module); 101 } 102 103 Connection otherCon = ConnectionFactory.tryGenericConnectionSources(helperName, datasourceInfo.inlineJdbcElement); 104 return otherCon; 105 } else { 106 Debug.logError("JOTM is the configured transaction manager but no inline-jdbc element was specified in the " + helperName + " datasource. Please check your configuration", module); 107 return null; 108 } 109 } 110 111 public void shutdown() { 112 MinervaConnectionFactory.closeAll(); 113 if (jotm != null) { 114 jotm.stop(); 115 jotm = null; 116 } 117 } 118 } 119 | Popular Tags |