Author: jacopoc
Date: Fri Aug 22 17:19:54 2014 New Revision: 1619868 URL: http://svn.apache.org/r1619868 Log: Removed all but one of the (static) method of TransactionFactory: * getCursorConnection(...) has been moved to TransactionUtil where it makes more sense * removed all the wrappers method around TransactionFactoryInterface methods: they are not required now that the client code can use the interface methods Modified: ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/jdbc/ConnectionFactory.java ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/DumbFactory.java ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/GenericXaResource.java ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/JNDIFactory.java ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactory.java ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java ofbiz/branches/framework-api-cleanup/framework/service/src/org/ofbiz/service/ServiceSynchronization.java Modified: ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java?rev=1619868&r1=1619867&r2=1619868&view=diff ============================================================================== --- ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java (original) +++ ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java Fri Aug 22 17:19:54 2014 @@ -45,6 +45,7 @@ import org.ofbiz.entity.config.model.Inl import org.ofbiz.entity.config.model.JdbcElement; import org.ofbiz.entity.datasource.GenericHelperInfo; import org.ofbiz.entity.transaction.TransactionFactory; +import org.ofbiz.entity.transaction.TransactionUtil; /** * Apache Commons DBCP connection factory. @@ -60,14 +61,14 @@ public class DBCPConnectionFactory imple String cacheKey = helperInfo.getHelperFullName(); ManagedDataSource mds = dsCache.get(cacheKey); if (mds != null) { - return TransactionFactory.getCursorConnection(helperInfo, mds.getConnection()); + return TransactionUtil.getCursorConnection(helperInfo, mds.getConnection()); } if (!(abstractJdbc instanceof InlineJdbc)) { throw new GenericEntityConfException("DBCP requires an <inline-jdbc> child element in the <datasource> element"); } InlineJdbc jdbcElement = (InlineJdbc) abstractJdbc; // connection properties - TransactionManager txMgr = TransactionFactory.getTransactionManager(); + TransactionManager txMgr = TransactionFactory.getInstance().getTransactionManager(); String driverName = jdbcElement.getJdbcDriver(); String jdbcUri = helperInfo.getOverrideJdbcUri(jdbcElement.getJdbcUri()); @@ -152,7 +153,7 @@ public class DBCPConnectionFactory imple dsCache.putIfAbsent(cacheKey, mds); mds = dsCache.get(cacheKey); - return TransactionFactory.getCursorConnection(helperInfo, mds.getConnection()); + return TransactionUtil.getCursorConnection(helperInfo, mds.getConnection()); } public void closeAll() { Modified: ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/jdbc/ConnectionFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/jdbc/ConnectionFactory.java?rev=1619868&r1=1619867&r2=1619868&view=diff ============================================================================== --- ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/jdbc/ConnectionFactory.java (original) +++ ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/jdbc/ConnectionFactory.java Fri Aug 22 17:19:54 2014 @@ -84,7 +84,7 @@ public class ConnectionFactory { public static Connection getConnection(String helperName) throws SQLException, GenericEntityException { // Debug.logVerbose("Getting a connection", module); - Connection con = TransactionFactory.getConnection(new GenericHelperInfo(null, helperName)); + Connection con = TransactionFactory.getInstance().getConnection(new GenericHelperInfo(null, helperName)); if (con == null) { Debug.logError("******* ERROR: No database connection found for helperName \"" + helperName + "\"", module); } @@ -94,7 +94,7 @@ public class ConnectionFactory { public static Connection getConnection(GenericHelperInfo helperInfo) throws SQLException, GenericEntityException { // Debug.logVerbose("Getting a connection", module); - Connection con = TransactionFactory.getConnection(helperInfo); + Connection con = TransactionFactory.getInstance().getConnection(helperInfo); if (con == null) { Debug.logError("******* ERROR: No database connection found for helperName \"" + helperInfo.getHelperFullName() + "\"", module); } Modified: ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/DumbFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/DumbFactory.java?rev=1619868&r1=1619867&r2=1619868&view=diff ============================================================================== --- ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/DumbFactory.java (original) +++ ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/DumbFactory.java Fri Aug 22 17:19:54 2014 @@ -112,7 +112,7 @@ public class DumbFactory implements Tran if (datasourceInfo.getInlineJdbc() != null) { Connection otherCon = ConnectionFactory.getManagedConnection(helperInfo, datasourceInfo.getInlineJdbc()); - return TransactionFactory.getCursorConnection(helperInfo, otherCon); + return TransactionUtil.getCursorConnection(helperInfo, otherCon); } else { Debug.logError("Dumb/Empty is the configured transaction manager but no inline-jdbc element was specified in the " + helperInfo.getHelperBaseName() + " datasource. Please check your configuration", module); return null; Modified: ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/GenericXaResource.java URL: http://svn.apache.org/viewvc/ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/GenericXaResource.java?rev=1619868&r1=1619867&r2=1619868&view=diff ============================================================================== --- ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/GenericXaResource.java (original) +++ ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/GenericXaResource.java Fri Aug 22 17:19:54 2014 @@ -47,7 +47,7 @@ public abstract class GenericXaResource * @throws XAException */ public void enlist() throws XAException { - TransactionManager tm = TransactionFactory.getTransactionManager(); + TransactionManager tm = TransactionFactory.getInstance().getTransactionManager(); try { if (tm != null && tm.getStatus() == Status.STATUS_ACTIVE) { Transaction tx = tm.getTransaction(); Modified: ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/JNDIFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/JNDIFactory.java?rev=1619868&r1=1619867&r2=1619868&view=diff ============================================================================== --- ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/JNDIFactory.java (original) +++ ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/JNDIFactory.java Fri Aug 22 17:19:54 2014 @@ -141,14 +141,14 @@ public class JNDIFactory implements Tran String jndiName = jndiJdbcElement.getJndiName(); String jndiServerName = jndiJdbcElement.getJndiServerName(); Connection con = getJndiConnection(jndiName, jndiServerName); - if (con != null) return TransactionFactory.getCursorConnection(helperInfo, con); + if (con != null) return TransactionUtil.getCursorConnection(helperInfo, con); } else { // Debug.logError("JNDI loaded is the configured transaction manager but no jndi-jdbc element was specified in the " + helperName + " datasource. Please check your configuration.", module); } if (datasourceInfo.getInlineJdbc() != null) { Connection otherCon = ConnectionFactory.getManagedConnection(helperInfo, datasourceInfo.getInlineJdbc()); - return TransactionFactory.getCursorConnection(helperInfo, otherCon); + return TransactionUtil.getCursorConnection(helperInfo, otherCon); } else { //no real need to print an error here return null; Modified: ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactory.java?rev=1619868&r1=1619867&r2=1619868&view=diff ============================================================================== --- ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactory.java (original) +++ ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactory.java Fri Aug 22 17:19:54 2014 @@ -18,19 +18,9 @@ *******************************************************************************/ package org.ofbiz.entity.transaction; -import java.sql.Connection; -import java.sql.SQLException; - -import javax.transaction.TransactionManager; -import javax.transaction.UserTransaction; - import org.ofbiz.base.util.Debug; import org.ofbiz.entity.GenericEntityConfException; -import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.config.EntityConfigUtil; -import org.ofbiz.entity.config.model.Datasource; -import org.ofbiz.entity.datasource.GenericHelperInfo; -import org.ofbiz.entity.jdbc.CursorConnection; /** * TransactionFactory - central source for JTA objects @@ -60,46 +50,10 @@ public class TransactionFactory { return instance; } - private static TransactionFactoryInterface getTransactionFactory() { + public static TransactionFactoryInterface getInstance() { if (txFactory == null) { throw new IllegalStateException("The Transaction Factory is not initialized."); } return txFactory; } - - public static TransactionManager getTransactionManager() { - return getTransactionFactory().getTransactionManager(); - } - - public static UserTransaction getUserTransaction() { - return getTransactionFactory().getUserTransaction(); - } - - public static String getTxMgrName() { - return getTransactionFactory().getTxMgrName(); - } - - public static Connection getConnection(GenericHelperInfo helperInfo) throws SQLException, GenericEntityException { - return getTransactionFactory().getConnection(helperInfo); - } - - public static void shutdown() { - getTransactionFactory().shutdown(); - } - - public static Connection getCursorConnection(GenericHelperInfo helperInfo, Connection con) { - Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperInfo.getHelperBaseName()); - if (datasourceInfo == null) { - Debug.logWarning("Could not find configuration for " + helperInfo.getHelperBaseName() + " datasource.", module); - return con; - } else if (datasourceInfo.getUseProxyCursor()) { - try { - if (datasourceInfo.getResultFetchSize() > 1) - con = CursorConnection.newCursorConnection(con, datasourceInfo.getProxyCursorName(), datasourceInfo.getResultFetchSize()); - } catch (Exception ex) { - Debug.logWarning(ex, "Error creating the cursor connection proxy " + helperInfo.getHelperBaseName() + " datasource.", module); - } - } - return con; - } } Modified: ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java URL: http://svn.apache.org/viewvc/ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java?rev=1619868&r1=1619867&r2=1619868&view=diff ============================================================================== --- ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java (original) +++ ofbiz/branches/framework-api-cleanup/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java Fri Aug 22 17:19:54 2014 @@ -52,6 +52,9 @@ import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericEntityConfException; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.config.EntityConfigUtil; +import org.ofbiz.entity.config.model.Datasource; +import org.ofbiz.entity.datasource.GenericHelperInfo; +import org.ofbiz.entity.jdbc.CursorConnection; /** * <p>Transaction Utility to help with some common transaction tasks @@ -130,7 +133,7 @@ public class TransactionUtil implements * a transaction is already in place it will return false and do nothing. */ public static boolean begin(int timeout) throws GenericTransactionException { - UserTransaction ut = TransactionFactory.getUserTransaction(); + UserTransaction ut = TransactionFactory.getInstance().getUserTransaction(); if (ut != null) { try { int currentStatus = ut.getStatus(); @@ -218,7 +221,7 @@ public class TransactionUtil implements /** Gets the status of the transaction in the current thread IF * transactions are available, otherwise returns STATUS_NO_TRANSACTION */ public static int getStatus() throws GenericTransactionException { - UserTransaction ut = TransactionFactory.getUserTransaction(); + UserTransaction ut = TransactionFactory.getInstance().getUserTransaction(); if (ut != null) { try { return ut.getStatus(); @@ -255,7 +258,7 @@ public class TransactionUtil implements /** Commits the transaction in the current thread IF transactions are available */ public static void commit() throws GenericTransactionException { - UserTransaction ut = TransactionFactory.getUserTransaction(); + UserTransaction ut = TransactionFactory.getInstance().getUserTransaction(); if (ut != null) { try { @@ -327,7 +330,7 @@ public class TransactionUtil implements /** Rolls back transaction in the current thread IF transactions are available */ public static void rollback(Throwable causeThrowable) throws GenericTransactionException { - UserTransaction ut = TransactionFactory.getUserTransaction(); + UserTransaction ut = TransactionFactory.getInstance().getUserTransaction(); if (ut != null) { try { @@ -366,7 +369,7 @@ public class TransactionUtil implements /** Makes a rollback the only possible outcome of the transaction in the current thread IF transactions are available */ public static void setRollbackOnly(String causeMessage, Throwable causeThrowable) throws GenericTransactionException { - UserTransaction ut = TransactionFactory.getUserTransaction(); + UserTransaction ut = TransactionFactory.getInstance().getUserTransaction(); if (ut != null) { try { int status = ut.getStatus(); @@ -400,7 +403,7 @@ public class TransactionUtil implements public static Transaction suspend() throws GenericTransactionException { try { if (TransactionUtil.getStatus() != STATUS_NO_TRANSACTION) { - TransactionManager txMgr = TransactionFactory.getTransactionManager(); + TransactionManager txMgr = TransactionFactory.getInstance().getTransactionManager(); if (txMgr != null) { pushTransactionBeginStackSave(clearTransactionBeginStack()); pushSetRollbackOnlyCauseSave(clearSetRollbackOnlyCause()); @@ -423,7 +426,7 @@ public class TransactionUtil implements if (parentTx == null) { return; } - TransactionManager txMgr = TransactionFactory.getTransactionManager(); + TransactionManager txMgr = TransactionFactory.getInstance().getTransactionManager(); try { if (txMgr != null) { setTransactionBeginStack(popTransactionBeginStackSave()); @@ -452,7 +455,7 @@ public class TransactionUtil implements /** Sets the timeout of the transaction in the current thread IF transactions are available */ public static void setTransactionTimeout(int seconds) throws GenericTransactionException { - UserTransaction ut = TransactionFactory.getUserTransaction(); + UserTransaction ut = TransactionFactory.getInstance().getUserTransaction(); if (ut != null) { try { ut.setTransactionTimeout(seconds); @@ -482,7 +485,7 @@ public class TransactionUtil implements } try { - TransactionManager tm = TransactionFactory.getTransactionManager(); + TransactionManager tm = TransactionFactory.getInstance().getTransactionManager(); if (tm != null && tm.getStatus() == STATUS_ACTIVE) { Transaction tx = tm.getTransaction(); if (tx != null) { @@ -562,7 +565,7 @@ public class TransactionUtil implements } try { - TransactionManager tm = TransactionFactory.getTransactionManager(); + TransactionManager tm = TransactionFactory.getInstance().getTransactionManager(); if (tm != null && tm.getStatus() == STATUS_ACTIVE) { Transaction tx = tm.getTransaction(); if (tx != null) { @@ -1051,4 +1054,21 @@ public class TransactionUtil implements } } } + + public static Connection getCursorConnection(GenericHelperInfo helperInfo, Connection con) { + Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperInfo.getHelperBaseName()); + if (datasourceInfo == null) { + Debug.logWarning("Could not find configuration for " + helperInfo.getHelperBaseName() + " datasource.", module); + return con; + } else if (datasourceInfo.getUseProxyCursor()) { + try { + if (datasourceInfo.getResultFetchSize() > 1) + con = CursorConnection.newCursorConnection(con, datasourceInfo.getProxyCursorName(), datasourceInfo.getResultFetchSize()); + } catch (Exception ex) { + Debug.logWarning(ex, "Error creating the cursor connection proxy " + helperInfo.getHelperBaseName() + " datasource.", module); + } + } + return con; + } + } Modified: ofbiz/branches/framework-api-cleanup/framework/service/src/org/ofbiz/service/ServiceSynchronization.java URL: http://svn.apache.org/viewvc/ofbiz/branches/framework-api-cleanup/framework/service/src/org/ofbiz/service/ServiceSynchronization.java?rev=1619868&r1=1619867&r2=1619868&view=diff ============================================================================== --- ofbiz/branches/framework-api-cleanup/framework/service/src/org/ofbiz/service/ServiceSynchronization.java (original) +++ ofbiz/branches/framework-api-cleanup/framework/service/src/org/ofbiz/service/ServiceSynchronization.java Fri Aug 22 17:19:54 2014 @@ -49,7 +49,7 @@ public class ServiceSynchronization impl protected static ServiceSynchronization getInstance() throws GenericServiceException { ServiceSynchronization sync = null; try { - Transaction transaction = TransactionFactory.getTransactionManager().getTransaction(); + Transaction transaction = TransactionFactory.getInstance().getTransactionManager().getTransaction(); synchronized (transaction) { sync = syncingleton.get(transaction); if (sync == null) { |
Free forum by Nabble | Edit this page |