|
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java Fri Jun 7 08:39:44 2013 @@ -37,7 +37,7 @@ import org.ofbiz.entity.GenericEntityExc import org.ofbiz.entity.GenericNotImplementedException; import org.ofbiz.entity.GenericPK; import org.ofbiz.entity.GenericValue; -import org.ofbiz.entity.config.DatasourceInfo; +import org.ofbiz.entity.config.model.Datasource; import org.ofbiz.entity.config.EntityConfigUtil; import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.jdbc.SqlJdbcUtil; @@ -280,8 +280,8 @@ public class MemoryHelper implements Gen public MemoryHelper(String helperName) { this.helperName = helperName; modelFieldTypeReader = ModelFieldTypeReader.getModelFieldTypeReader(helperName); - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName); - this.executor = ExecutionPool.getExecutor(MEMORY_HELPER_THREAD_GROUP, "OFBiz-entity-datasource(" + helperName + ")", datasourceInfo.maxWorkerPoolSize, false); + Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperName); + this.executor = ExecutionPool.getExecutor(MEMORY_HELPER_THREAD_GROUP, "OFBiz-entity-datasource(" + helperName + ")", datasourceInfo.getMaxWorkerPoolSize(), false); } public String getHelperName() { Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/ConnectionFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/ConnectionFactory.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/ConnectionFactory.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/ConnectionFactory.java Fri Jun 7 08:39:44 2013 @@ -18,20 +18,23 @@ *******************************************************************************/ package org.ofbiz.entity.jdbc; +import java.sql.Connection; +import java.sql.Driver; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicReference; + import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.config.EntityConfigListener; import org.ofbiz.entity.config.EntityConfigUtil; +import org.ofbiz.entity.config.model.EntityConfig; +import org.ofbiz.entity.config.model.JdbcElement; import org.ofbiz.entity.connection.ConnectionFactoryInterface; import org.ofbiz.entity.datasource.GenericHelperInfo; import org.ofbiz.entity.transaction.TransactionFactory; -import org.w3c.dom.Element; - -import java.sql.Connection; -import java.sql.Driver; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.Properties; /** * ConnectionFactory - central source for JDBC connections @@ -40,7 +43,34 @@ import java.util.Properties; public class ConnectionFactory { // Debug module name public static final String module = ConnectionFactory.class.getName(); - private static ConnectionFactoryInterface _factory = null; + private static final AtomicReference<ConnectionFactoryInterface> connFactoryRef = new AtomicReference<ConnectionFactoryInterface>(null); + private static final EntityConfigListener configListener = new EntityConfigListener() { + @Override + public void onEntityConfigChange(EntityConfig entityConfig) throws Exception { + ConnectionFactoryInterface instance = createConnectionFactoryInterface(); + ConnectionFactoryInterface previousInstance = connFactoryRef.getAndSet(instance); + if (previousInstance != null) { + previousInstance.closeAll(); + Debug.logInfo("Listener shut down ConnectionFactoryInterface instance " + previousInstance, module); + } + Debug.logInfo("Listener created new ConnectionFactoryInterface instance " + instance, module); + } + }; + + public static EntityConfigListener getConfigListener() { + return configListener; + } + + private static ConnectionFactoryInterface createConnectionFactoryInterface() throws Exception { + String className = EntityConfigUtil.getConnectionFactoryClass(); + if (className == null) { + throw new IllegalStateException("Could not find connection factory class name definition"); + } + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + Class<?> tfClass = loader.loadClass(className); + return (ConnectionFactoryInterface) tfClass.newInstance(); + } + public static Connection getConnection(String driverName, String connectionUrl, Properties props, String userName, String password) throws SQLException { // first register the JDBC driver with the DriverManager @@ -89,50 +119,26 @@ public class ConnectionFactory { return con; } - public static ConnectionFactoryInterface getManagedConnectionFactory() { - if (_factory == null) { // don't want to block here - synchronized (ConnectionFactory.class) { - // must check if null again as one of the blocked threads can still enter - if (_factory == null) { - try { - String className = EntityConfigUtil.getConnectionFactoryClass(); - - if (className == null) { - throw new IllegalStateException("Could not find connection factory class name definition"); - } - Class<?> cfClass = null; - - if (UtilValidate.isNotEmpty(className)) { - try { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - cfClass = loader.loadClass(className); - } catch (ClassNotFoundException e) { - Debug.logWarning(e, module); - throw new IllegalStateException("Error loading ConnectionFactoryInterface class \"" + className + "\": " + e.getMessage()); - } - } - - try { - _factory = (ConnectionFactoryInterface) cfClass.newInstance(); - } catch (IllegalAccessException e) { - Debug.logWarning(e, module); - throw new IllegalStateException("Error loading ConnectionFactoryInterface class \"" + className + "\": " + e.getMessage()); - } catch (InstantiationException e) { - Debug.logWarning(e, module); - throw new IllegalStateException("Error loading ConnectionFactoryInterface class \"" + className + "\": " + e.getMessage()); - } - } catch (SecurityException e) { - Debug.logError(e, module); - throw new IllegalStateException("Error loading ConnectionFactoryInterface class: " + e.getMessage()); - } + private static ConnectionFactoryInterface getManagedConnectionFactory() { + ConnectionFactoryInterface instance = connFactoryRef.get(); + if (instance == null) { + try { + instance = createConnectionFactoryInterface(); + if (connFactoryRef.compareAndSet(null, instance)) { + Debug.logInfo("Factory method created new ConnectionFactoryInterface instance " + instance, module); + } else { + instance = connFactoryRef.get(); } + } catch (Exception e) { + Debug.logError(e, "Exception thrown while creating ConnectionFactoryInterface instance: ", module); + throw new IllegalStateException("Error loading ConnectionFactoryInterface class: " + e); } } - return _factory; + return instance; } - public static Connection getManagedConnection(GenericHelperInfo helperInfo, Element inlineJdbcElement) throws SQLException, GenericEntityException { - return getManagedConnectionFactory().getConnection(helperInfo, inlineJdbcElement); + public static Connection getManagedConnection(GenericHelperInfo helperInfo, JdbcElement jdbcElement) throws SQLException, GenericEntityException { + return getManagedConnectionFactory().getConnection(helperInfo, jdbcElement); } public static void closeAllManagedConnections() { Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java Fri Jun 7 08:39:44 2013 @@ -46,7 +46,7 @@ import org.ofbiz.base.util.UtilTimer; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.config.DatasourceInfo; +import org.ofbiz.entity.config.model.Datasource; import org.ofbiz.entity.config.EntityConfigUtil; import org.ofbiz.entity.datasource.GenericHelperInfo; import org.ofbiz.entity.model.ModelEntity; @@ -71,7 +71,7 @@ public class DatabaseUtil { // OFBiz Connections protected ModelFieldTypeReader modelFieldTypeReader = null; - protected DatasourceInfo datasourceInfo = null; + protected Datasource datasourceInfo = null; protected GenericHelperInfo helperInfo = null; // Legacy Connections @@ -91,7 +91,7 @@ public class DatabaseUtil { public DatabaseUtil(GenericHelperInfo helperInfo, ExecutorService executor) { this.helperInfo = helperInfo; this.modelFieldTypeReader = ModelFieldTypeReader.getModelFieldTypeReader(helperInfo.getHelperBaseName()); - this.datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperInfo.getHelperBaseName()); + this.datasourceInfo = EntityConfigUtil.getDatasource(helperInfo.getHelperBaseName()); this.executor = executor; } @@ -166,7 +166,7 @@ public class DatabaseUtil { } } - public DatasourceInfo getDatasourceInfo() { + public Datasource getDatasource() { return this.datasourceInfo; } @@ -175,7 +175,7 @@ public class DatabaseUtil { /* ====================================================================== */ public void checkDb(Map<String, ModelEntity> modelEntities, List<String> messages, boolean addMissing) { - checkDb(modelEntities, null, messages, datasourceInfo.checkPrimaryKeysOnStart, (datasourceInfo.useFks && datasourceInfo.checkForeignKeysOnStart), (datasourceInfo.useFkIndices && datasourceInfo.checkFkIndicesOnStart), addMissing); + checkDb(modelEntities, null, messages, datasourceInfo.getCheckPksOnStart(), (datasourceInfo.getUseForeignKeys() && datasourceInfo.getCheckFksOnStart()), (datasourceInfo.getUseForeignKeyIndices() && datasourceInfo.getCheckFkIndicesOnStart()), addMissing); } public void checkDb(Map<String, ModelEntity> modelEntities, List<String> colWrongSize, List<String> messages, boolean checkPks, boolean checkFks, boolean checkFkIdx, boolean addMissing) { @@ -439,14 +439,14 @@ public class DatabaseUtil { } // for each newly added table, add fk indices - if (datasourceInfo.useFkIndices) { + if (datasourceInfo.getUseForeignKeyIndices()) { int totalFkIndices = 0; List<Future<AbstractCountingCallable>> fkIndicesFutures = new LinkedList<Future<AbstractCountingCallable>>(); for (ModelEntity curEntity: entitiesAdded) { if (curEntity.getRelationsOneSize() > 0) { fkIndicesFutures.add(submitWork(new AbstractCountingCallable(curEntity, modelEntities) { public AbstractCountingCallable call() throws Exception { - count = createForeignKeyIndices(entity, datasourceInfo.constraintNameClipLength, messages); + count = createForeignKeyIndices(entity, datasourceInfo.getConstraintNameClipLength(), messages); return this; } })); @@ -459,16 +459,16 @@ public class DatabaseUtil { } // for each newly added table, add fks - if (datasourceInfo.useFks) { + if (datasourceInfo.getUseForeignKeys()) { int totalFks = 0; for (ModelEntity curEntity: entitiesAdded) { - totalFks += this.createForeignKeys(curEntity, modelEntities, datasourceInfo.constraintNameClipLength, datasourceInfo.fkStyle, datasourceInfo.useFkInitiallyDeferred, messages); + totalFks += this.createForeignKeys(curEntity, modelEntities, datasourceInfo.getConstraintNameClipLength(), datasourceInfo.getFkStyle(), datasourceInfo.getUseFkInitiallyDeferred(), messages); } if (totalFks > 0) Debug.logImportant("==== TOTAL Foreign Keys Created: " + totalFks, module); } // for each newly added table, add declared indexes - if (datasourceInfo.useIndices) { + if (datasourceInfo.getUseIndices()) { int totalDis = 0; List<Future<AbstractCountingCallable>> disFutures = new LinkedList<Future<AbstractCountingCallable>>(); for (ModelEntity curEntity: entitiesAdded) { @@ -490,7 +490,7 @@ public class DatabaseUtil { // make sure each one-relation has an FK if (checkFks) { - //if (!justColumns && datasourceInfo.useFks && datasourceInfo.checkForeignKeysOnStart) { + //if (!justColumns && datasourceInfo.getUseForeignKeys() && datasourceInfo.checkForeignKeysOnStart) { // NOTE: This ISN'T working for Postgres or MySQL, who knows about others, may be from JDBC driver bugs... int numFksCreated = 0; // TODO: check each key-map to make sure it exists in the FK, if any differences warn and then remove FK and recreate it @@ -534,7 +534,7 @@ public class DatabaseUtil { Debug.logError("No such relation: " + entity.getEntityName() + " -> " + modelRelation.getRelEntityName(), module); continue; } - String relConstraintName = makeFkConstraintName(modelRelation, datasourceInfo.constraintNameClipLength); + String relConstraintName = makeFkConstraintName(modelRelation, datasourceInfo.getConstraintNameClipLength()); ReferenceCheckInfo rcInfo = null; if (rcInfoMap != null) { @@ -550,7 +550,7 @@ public class DatabaseUtil { if (Debug.infoOn()) Debug.logInfo(noFkMessage, module); if (addMissing) { - String errMsg = createForeignKey(entity, modelRelation, relModelEntity, datasourceInfo.constraintNameClipLength, datasourceInfo.fkStyle, datasourceInfo.useFkInitiallyDeferred); + String errMsg = createForeignKey(entity, modelRelation, relModelEntity, datasourceInfo.getConstraintNameClipLength(), datasourceInfo.getFkStyle(), datasourceInfo.getUseFkInitiallyDeferred()); if (UtilValidate.isNotEmpty(errMsg)) { String message = "Could not create foreign key " + relConstraintName + " for entity [" + entity.getEntityName() + "]: " + errMsg; Debug.logError(message, module); @@ -585,8 +585,8 @@ public class DatabaseUtil { } // make sure each one-relation has an index - if (checkFkIdx || datasourceInfo.checkIndicesOnStart) { - //if (!justColumns && datasourceInfo.useFkIndices && datasourceInfo.checkFkIndicesOnStart) { + if (checkFkIdx || datasourceInfo.getCheckIndicesOnStart()) { + //if (!justColumns && datasourceInfo.getUseForeignKeyIndices() && datasourceInfo.checkFkIndicesOnStart) { int numIndicesCreated = 0; // TODO: check each key-map to make sure it exists in the index, if any differences warn and then remove the index and recreate it @@ -618,9 +618,9 @@ public class DatabaseUtil { if (tableIndexList == null) { // evidently no indexes in the database for this table, do the create all if (checkFkIdx) { - this.createForeignKeyIndices(entity, datasourceInfo.constraintNameClipLength, messages); + this.createForeignKeyIndices(entity, datasourceInfo.getConstraintNameClipLength(), messages); } - if (datasourceInfo.checkIndicesOnStart) { + if (datasourceInfo.getCheckIndicesOnStart()) { this.createDeclaredIndices(entity, messages); } continue; @@ -634,7 +634,7 @@ public class DatabaseUtil { continue; } - String relConstraintName = makeFkConstraintName(modelRelation, datasourceInfo.constraintNameClipLength); + String relConstraintName = makeFkConstraintName(modelRelation, datasourceInfo.getConstraintNameClipLength()); if (tableIndexList.contains(relConstraintName)) { tableIndexList.remove(relConstraintName); } else { @@ -645,7 +645,7 @@ public class DatabaseUtil { if (Debug.infoOn()) Debug.logInfo(noIdxMessage, module); if (addMissing) { - String errMsg = createForeignKeyIndex(entity, modelRelation, datasourceInfo.constraintNameClipLength); + String errMsg = createForeignKeyIndex(entity, modelRelation, datasourceInfo.getConstraintNameClipLength()); if (UtilValidate.isNotEmpty(errMsg)) { String message = "Could not create foreign key index " + relConstraintName + " for entity [" + entity.getEntityName() + "]: " + errMsg; Debug.logError(message, module); @@ -673,12 +673,12 @@ public class DatabaseUtil { while (indexes.hasNext()) { ModelIndex modelIndex = indexes.next(); - String relIndexName = makeIndexName(modelIndex, datasourceInfo.constraintNameClipLength); + String relIndexName = makeIndexName(modelIndex, datasourceInfo.getConstraintNameClipLength()); String checkIndexName = needsUpperCase[0] ? relIndexName.toUpperCase() : relIndexName; if (tableIndexList.contains(checkIndexName)) { tableIndexList.remove(checkIndexName); } else { - if (datasourceInfo.checkIndicesOnStart) { + if (datasourceInfo.getCheckIndicesOnStart()) { // if not, create one String noIdxMessage = "No Index [" + relIndexName + "] found for entity [" + entityName + "]"; if (messages != null) messages.add(noIdxMessage); @@ -1676,19 +1676,19 @@ public class DatabaseUtil { if ("String".equals(type.getJavaType()) || "java.lang.String".equals(type.getJavaType())) { // if there is a characterSet, add the CHARACTER SET arg here - if (UtilValidate.isNotEmpty(this.datasourceInfo.characterSet)) { + if (UtilValidate.isNotEmpty(this.datasourceInfo.getCharacterSet())) { sqlBuf.append(" CHARACTER SET "); - sqlBuf.append(this.datasourceInfo.characterSet); + sqlBuf.append(this.datasourceInfo.getCharacterSet()); } // if there is a collate, add the COLLATE arg here - if (UtilValidate.isNotEmpty(this.datasourceInfo.collate)) { + if (UtilValidate.isNotEmpty(this.datasourceInfo.getCollate())) { sqlBuf.append(" COLLATE "); - sqlBuf.append(this.datasourceInfo.collate); + sqlBuf.append(this.datasourceInfo.getCollate()); } } if (field.getIsNotNull() || field.getIsPk()) { - if (this.datasourceInfo.alwaysUseConstraintKeyword) { + if (this.datasourceInfo.getAlwaysUseConstraintKeyword()) { sqlBuf.append(" CONSTRAINT NOT NULL, "); } else { sqlBuf.append(" NOT NULL, "); @@ -1698,8 +1698,8 @@ public class DatabaseUtil { } } - String pkName = makePkConstraintName(entity, this.datasourceInfo.constraintNameClipLength); - if (this.datasourceInfo.usePkConstraintNames) { + String pkName = makePkConstraintName(entity, this.datasourceInfo.getConstraintNameClipLength()); + if (this.datasourceInfo.getUsePkConstraintNames()) { sqlBuf.append("CONSTRAINT "); sqlBuf.append(pkName); } @@ -1725,7 +1725,7 @@ public class DatabaseUtil { continue; } - String fkConstraintClause = makeFkConstraintClause(entity, modelRelation, relModelEntity, this.datasourceInfo.constraintNameClipLength, this.datasourceInfo.fkStyle, this.datasourceInfo.useFkInitiallyDeferred); + String fkConstraintClause = makeFkConstraintClause(entity, modelRelation, relModelEntity, this.datasourceInfo.getConstraintNameClipLength(), this.datasourceInfo.getFkStyle(), this.datasourceInfo.getUseFkInitiallyDeferred()); if (UtilValidate.isNotEmpty(fkConstraintClause)) { sqlBuf.append(", "); sqlBuf.append(fkConstraintClause); @@ -1739,25 +1739,25 @@ public class DatabaseUtil { sqlBuf.append(")"); // if there is a tableType, add the TYPE arg here - if (UtilValidate.isNotEmpty(this.datasourceInfo.tableType)) { + if (UtilValidate.isNotEmpty(this.datasourceInfo.getTableType())) { // jaz:20101229 - This appears to be only used by mysql and now mysql has // deprecated (and in 5.5.x removed) the use of the TYPE keyword. This is // changed to ENGINE which is supported starting at 4.1 sqlBuf.append(" ENGINE "); //sqlBuf.append(" TYPE "); - sqlBuf.append(this.datasourceInfo.tableType); + sqlBuf.append(this.datasourceInfo.getTableType()); } // if there is a characterSet, add the CHARACTER SET arg here - if (UtilValidate.isNotEmpty(this.datasourceInfo.characterSet)) { + if (UtilValidate.isNotEmpty(this.datasourceInfo.getCharacterSet())) { sqlBuf.append(" CHARACTER SET "); - sqlBuf.append(this.datasourceInfo.characterSet); + sqlBuf.append(this.datasourceInfo.getCharacterSet()); } // if there is a collate, add the COLLATE arg here - if (UtilValidate.isNotEmpty(this.datasourceInfo.collate)) { + if (UtilValidate.isNotEmpty(this.datasourceInfo.getCollate())) { sqlBuf.append(" COLLATE "); - sqlBuf.append(this.datasourceInfo.collate); + sqlBuf.append(this.datasourceInfo.getCollate()); } if (Debug.verboseOn()) Debug.logVerbose("[createTable] sql=" + sqlBuf.toString(), module); @@ -1870,15 +1870,15 @@ public class DatabaseUtil { if ("String".equals(type.getJavaType()) || "java.lang.String".equals(type.getJavaType())) { // if there is a characterSet, add the CHARACTER SET arg here - if (UtilValidate.isNotEmpty(this.datasourceInfo.characterSet)) { + if (UtilValidate.isNotEmpty(this.datasourceInfo.getCharacterSet())) { sqlBuf.append(" CHARACTER SET "); - sqlBuf.append(this.datasourceInfo.characterSet); + sqlBuf.append(this.datasourceInfo.getCharacterSet()); } // if there is a collate, add the COLLATE arg here - if (UtilValidate.isNotEmpty(this.datasourceInfo.collate)) { + if (UtilValidate.isNotEmpty(this.datasourceInfo.getCollate())) { sqlBuf.append(" COLLATE "); - sqlBuf.append(this.datasourceInfo.collate); + sqlBuf.append(this.datasourceInfo.getCollate()); } } @@ -1898,15 +1898,15 @@ public class DatabaseUtil { if ("String".equals(type.getJavaType()) || "java.lang.String".equals(type.getJavaType())) { // if there is a characterSet, add the CHARACTER SET arg here - if (UtilValidate.isNotEmpty(this.datasourceInfo.characterSet)) { + if (UtilValidate.isNotEmpty(this.datasourceInfo.getCharacterSet())) { sql2Buf.append(" CHARACTER SET "); - sql2Buf.append(this.datasourceInfo.characterSet); + sql2Buf.append(this.datasourceInfo.getCharacterSet()); } // if there is a collate, add the COLLATE arg here - if (UtilValidate.isNotEmpty(this.datasourceInfo.collate)) { + if (UtilValidate.isNotEmpty(this.datasourceInfo.getCollate())) { sql2Buf.append(" COLLATE "); - sql2Buf.append(this.datasourceInfo.collate); + sql2Buf.append(this.datasourceInfo.getCollate()); } } @@ -2169,7 +2169,7 @@ public class DatabaseUtil { /* ====================================================================== */ public int createForeignKeys(ModelEntity entity, Map<String, ModelEntity> modelEntities, List<String> messages) { - return this.createForeignKeys(entity, modelEntities, datasourceInfo.constraintNameClipLength, datasourceInfo.fkStyle, datasourceInfo.useFkInitiallyDeferred, messages); + return this.createForeignKeys(entity, modelEntities, datasourceInfo.getConstraintNameClipLength(), datasourceInfo.getFkStyle(), datasourceInfo.getUseFkInitiallyDeferred(), messages); } public int createForeignKeys(ModelEntity entity, Map<String, ModelEntity> modelEntities, int constraintNameClipLength, String fkStyle, boolean useFkInitiallyDeferred, List<String> messages) { if (entity == null) { @@ -2351,7 +2351,7 @@ public class DatabaseUtil { } public void deleteForeignKeys(ModelEntity entity, Map<String, ModelEntity> modelEntities, List<String> messages) { - this.deleteForeignKeys(entity, modelEntities, datasourceInfo.constraintNameClipLength, messages); + this.deleteForeignKeys(entity, modelEntities, datasourceInfo.getConstraintNameClipLength(), messages); } public void deleteForeignKeys(ModelEntity entity, Map<String, ModelEntity> modelEntities, int constraintNameClipLength, List<String> messages) { @@ -2423,7 +2423,7 @@ public class DatabaseUtil { // now add constraint clause StringBuilder sqlBuf = new StringBuilder("ALTER TABLE "); sqlBuf.append(entity.getTableName(datasourceInfo)); - if (datasourceInfo.dropFkUseForeignKeyKeyword) { + if (datasourceInfo.getDropFkUseForeignKeyKeyword()) { sqlBuf.append(" DROP FOREIGN KEY "); } else { sqlBuf.append(" DROP CONSTRAINT "); @@ -2465,11 +2465,11 @@ public class DatabaseUtil { } public void createPrimaryKey(ModelEntity entity, boolean usePkConstraintNames, List<String> messages) { - createPrimaryKey(entity, usePkConstraintNames, datasourceInfo.constraintNameClipLength, messages); + createPrimaryKey(entity, usePkConstraintNames, datasourceInfo.getConstraintNameClipLength(), messages); } public void createPrimaryKey(ModelEntity entity, List<String> messages) { - createPrimaryKey(entity, datasourceInfo.usePkConstraintNames, messages); + createPrimaryKey(entity, datasourceInfo.getUsePkConstraintNames(), messages); } public String createPrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength) { @@ -2548,11 +2548,11 @@ public class DatabaseUtil { } public void deletePrimaryKey(ModelEntity entity, boolean usePkConstraintNames, List<String> messages) { - deletePrimaryKey(entity, usePkConstraintNames, datasourceInfo.constraintNameClipLength, messages); + deletePrimaryKey(entity, usePkConstraintNames, datasourceInfo.getConstraintNameClipLength(), messages); } public void deletePrimaryKey(ModelEntity entity, List<String> messages) { - deletePrimaryKey(entity, datasourceInfo.usePkConstraintNames, messages); + deletePrimaryKey(entity, datasourceInfo.getUsePkConstraintNames(), messages); } public String deletePrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength) { @@ -2728,11 +2728,11 @@ public class DatabaseUtil { } StringBuilder indexSqlBuf = new StringBuilder("CREATE "); - if (datasourceInfo.useIndicesUnique && modelIndex.getUnique()) { + if (datasourceInfo.getUseIndicesUnique() && modelIndex.getUnique()) { indexSqlBuf.append("UNIQUE "); } indexSqlBuf.append("INDEX "); - indexSqlBuf.append(makeIndexName(modelIndex, datasourceInfo.constraintNameClipLength)); + indexSqlBuf.append(makeIndexName(modelIndex, datasourceInfo.getConstraintNameClipLength())); indexSqlBuf.append(" ON "); indexSqlBuf.append(entity.getTableName(datasourceInfo)); @@ -2837,7 +2837,7 @@ public class DatabaseUtil { /* ====================================================================== */ /* ====================================================================== */ public int createForeignKeyIndices(ModelEntity entity, List<String> messages) { - return createForeignKeyIndices(entity, datasourceInfo.constraintNameClipLength, messages); + return createForeignKeyIndices(entity, datasourceInfo.getConstraintNameClipLength(), messages); } public int createForeignKeyIndices(ModelEntity entity, int constraintNameClipLength, List<String> messages) { @@ -2959,7 +2959,7 @@ public class DatabaseUtil { public void deleteForeignKeyIndices(ModelEntity entity, List<String> messages) { if (messages == null) messages = new ArrayList<String>(); - String err = deleteForeignKeyIndices(entity, datasourceInfo.constraintNameClipLength); + String err = deleteForeignKeyIndices(entity, datasourceInfo.getConstraintNameClipLength()); if (!UtilValidate.isEmpty(err)) { messages.add(err); } @@ -3057,14 +3057,14 @@ public class DatabaseUtil { } public String getSchemaName(DatabaseMetaData dbData) throws SQLException { - if (!isLegacy && this.datasourceInfo.useSchemas && dbData.supportsSchemasInTableDefinitions()) { - if (UtilValidate.isNotEmpty(this.datasourceInfo.schemaName)) { + if (!isLegacy && this.datasourceInfo.getUseSchemas() && dbData.supportsSchemasInTableDefinitions()) { + if (UtilValidate.isNotEmpty(this.datasourceInfo.getSchemaName())) { if (dbData.storesLowerCaseIdentifiers()) { - return this.datasourceInfo.schemaName.toLowerCase(); + return this.datasourceInfo.getSchemaName().toLowerCase(); } else if (dbData.storesUpperCaseIdentifiers()) { - return this.datasourceInfo.schemaName.toUpperCase(); + return this.datasourceInfo.getSchemaName().toUpperCase(); } else { - return this.datasourceInfo.schemaName; + return this.datasourceInfo.getSchemaName(); } } else { return dbData.getUserName(); @@ -3079,7 +3079,7 @@ public class DatabaseUtil { if (entity instanceof ModelViewEntity) { return; } - if (UtilValidate.isEmpty(this.datasourceInfo.characterSet) && UtilValidate.isEmpty(this.datasourceInfo.collate)) { + if (UtilValidate.isEmpty(this.datasourceInfo.getCharacterSet()) && UtilValidate.isEmpty(this.datasourceInfo.getCollate())) { messages.add("Not setting character-set and collate for entity [" + entity.getEntityName() + "], options not specified in the datasource definition in the entityengine.xml file."); return; } @@ -3099,14 +3099,14 @@ public class DatabaseUtil { //sqlTableBuf.append(""); // if there is a characterSet, add the CHARACTER SET arg here - if (UtilValidate.isNotEmpty(this.datasourceInfo.characterSet)) { + if (UtilValidate.isNotEmpty(this.datasourceInfo.getCharacterSet())) { sqlTableBuf.append(" DEFAULT CHARACTER SET "); - sqlTableBuf.append(this.datasourceInfo.characterSet); + sqlTableBuf.append(this.datasourceInfo.getCharacterSet()); } // if there is a collate, add the COLLATE arg here - if (UtilValidate.isNotEmpty(this.datasourceInfo.collate)) { + if (UtilValidate.isNotEmpty(this.datasourceInfo.getCollate())) { sqlTableBuf.append(" COLLATE "); - sqlTableBuf.append(this.datasourceInfo.collate); + sqlTableBuf.append(this.datasourceInfo.getCollate()); } if (Debug.verboseOn()) Debug.logVerbose("[updateCharacterSetAndCollation] character-set and collate sql=" + sqlTableBuf, module); @@ -3147,18 +3147,18 @@ public class DatabaseUtil { sqlBuf.append(type.getSqlType()); // if there is a characterSet, add the CHARACTER SET arg here - if (UtilValidate.isNotEmpty(this.datasourceInfo.characterSet)) { + if (UtilValidate.isNotEmpty(this.datasourceInfo.getCharacterSet())) { sqlBuf.append(" CHARACTER SET "); - sqlBuf.append(this.datasourceInfo.characterSet); + sqlBuf.append(this.datasourceInfo.getCharacterSet()); } // if there is a collate, add the COLLATE arg here - if (UtilValidate.isNotEmpty(this.datasourceInfo.collate)) { + if (UtilValidate.isNotEmpty(this.datasourceInfo.getCollate())) { sqlBuf.append(" COLLATE "); - sqlBuf.append(this.datasourceInfo.collate); + sqlBuf.append(this.datasourceInfo.getCollate()); } if (field.getIsPk() || field.getIsNotNull()) { - if (this.datasourceInfo.alwaysUseConstraintKeyword) { + if (this.datasourceInfo.getAlwaysUseConstraintKeyword()) { sqlBuf.append(" CONSTRAINT NOT NULL"); } else { sqlBuf.append(" NOT NULL"); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java Fri Jun 7 08:39:44 2013 @@ -38,7 +38,7 @@ import java.util.List; import org.ofbiz.base.util.Debug; import org.ofbiz.entity.GenericDataSourceException; import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.config.DatasourceInfo; +import org.ofbiz.entity.config.model.Datasource; import org.ofbiz.entity.config.EntityConfigUtil; import org.ofbiz.entity.datasource.GenericHelperInfo; import org.ofbiz.entity.transaction.GenericTransactionException; @@ -744,8 +744,8 @@ public class SQLProcessor { if (field != null) { _ps.setBlob(_ind, field); } else { - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(this.helperInfo.getHelperBaseName()); - if (datasourceInfo.useBinaryTypeForBlob) { + Datasource datasourceInfo = EntityConfigUtil.getDatasource(this.helperInfo.getHelperBaseName()); + if (datasourceInfo.getUseBinaryTypeForBlob()) { _ps.setNull(_ind, Types.BINARY); } else { _ps.setNull(_ind, Types.BLOB); @@ -795,8 +795,8 @@ public class SQLProcessor { throw new SQLException(ex.getMessage()); } } else { - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(this.helperInfo.getHelperBaseName()); - if (datasourceInfo.useBinaryTypeForBlob) { + Datasource datasourceInfo = EntityConfigUtil.getDatasource(this.helperInfo.getHelperBaseName()); + if (datasourceInfo.getUseBinaryTypeForBlob()) { _ps.setNull(_ind, Types.BINARY); } else { _ps.setNull(_ind, Types.BLOB); @@ -818,8 +818,8 @@ public class SQLProcessor { if (bytes != null) { _ps.setBytes(_ind, bytes); } else { - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(this.helperInfo.getHelperBaseName()); - if (datasourceInfo.useBinaryTypeForBlob) { + Datasource datasourceInfo = EntityConfigUtil.getDatasource(this.helperInfo.getHelperBaseName()); + if (datasourceInfo.getUseBinaryTypeForBlob()) { _ps.setNull(_ind, Types.BINARY); } else { _ps.setNull(_ind, Types.BLOB); @@ -856,11 +856,11 @@ public class SQLProcessor { // check if the statement was called with a specific fetch size, if not grab the default from the datasource if (fetchSize < 0) { - DatasourceInfo ds = EntityConfigUtil.getDatasourceInfo(this.helperInfo.getHelperBaseName()); + Datasource ds = EntityConfigUtil.getDatasource(this.helperInfo.getHelperBaseName()); if (ds != null) { - fetchSize = ds.resultFetchSize; + fetchSize = ds.getResultFetchSize(); } else { - Debug.logWarning("DatasourceInfo is null, not setting fetch size!", module); + Debug.logWarning("Datasource is null, not setting fetch size!", module); } } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java Fri Jun 7 08:39:44 2013 @@ -56,7 +56,7 @@ import org.ofbiz.entity.condition.Entity import org.ofbiz.entity.condition.EntityConditionParam; import org.ofbiz.entity.condition.EntityOperator; import org.ofbiz.entity.condition.OrderByList; -import org.ofbiz.entity.config.DatasourceInfo; +import org.ofbiz.entity.config.model.Datasource; import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.model.ModelField; import org.ofbiz.entity.model.ModelFieldType; @@ -74,15 +74,15 @@ public class SqlJdbcUtil { public static final int CHAR_BUFFER_SIZE = 4096; /** Makes the FROM clause and when necessary the JOIN clause(s) as well */ - public static String makeFromClause(ModelEntity modelEntity, ModelFieldTypeReader modelFieldTypeReader, DatasourceInfo datasourceInfo) throws GenericEntityException { + public static String makeFromClause(ModelEntity modelEntity, ModelFieldTypeReader modelFieldTypeReader, Datasource datasourceInfo) throws GenericEntityException { StringBuilder sql = new StringBuilder(" FROM "); if (modelEntity instanceof ModelViewEntity) { ModelViewEntity modelViewEntity = (ModelViewEntity) modelEntity; - if ("ansi".equals(datasourceInfo.joinStyle) || "ansi-no-parenthesis".equals(datasourceInfo.joinStyle)) { + if ("ansi".equals(datasourceInfo.getJoinStyle()) || "ansi-no-parenthesis".equals(datasourceInfo.getJoinStyle())) { boolean useParenthesis = true; - if ("ansi-no-parenthesis".equals(datasourceInfo.joinStyle)) { + if ("ansi-no-parenthesis".equals(datasourceInfo.getJoinStyle())) { useParenthesis = false; } @@ -212,7 +212,7 @@ public class SqlJdbcUtil { } - } else if ("theta-oracle".equals(datasourceInfo.joinStyle) || "theta-mssql".equals(datasourceInfo.joinStyle)) { + } else if ("theta-oracle".equals(datasourceInfo.getJoinStyle()) || "theta-mssql".equals(datasourceInfo.getJoinStyle())) { // FROM clause Iterator<String> meIter = modelViewEntity.getMemberModelMemberEntities().keySet().iterator(); @@ -228,7 +228,7 @@ public class SqlJdbcUtil { // JOIN clause(s): none needed, all the work done in the where clause for theta-oracle } else { - throw new GenericModelException("The join-style " + datasourceInfo.joinStyle + " is not yet supported"); + throw new GenericModelException("The join-style " + datasourceInfo.getJoinStyle() + " is not yet supported"); } } else { sql.append(modelEntity.getTableName(datasourceInfo)); @@ -383,11 +383,11 @@ public class SqlJdbcUtil { return ""; } - public static String makeOrderByClause(ModelEntity modelEntity, List<String> orderBy, DatasourceInfo datasourceInfo) throws GenericModelException { + public static String makeOrderByClause(ModelEntity modelEntity, List<String> orderBy, Datasource datasourceInfo) throws GenericModelException { return makeOrderByClause(modelEntity, orderBy, false, datasourceInfo); } - public static String makeOrderByClause(ModelEntity modelEntity, List<String> orderBy, boolean includeTablenamePrefix, DatasourceInfo datasourceInfo) throws GenericModelException { + public static String makeOrderByClause(ModelEntity modelEntity, List<String> orderBy, boolean includeTablenamePrefix, Datasource datasourceInfo) throws GenericModelException { StringBuilder sql = new StringBuilder(""); //String fieldPrefix = includeTablenamePrefix ? (modelEntity.getTableName(datasourceInfo) + ".") : ""; @@ -401,7 +401,7 @@ public class SqlJdbcUtil { return sql.toString(); } - public static String makeViewTable(ModelEntity modelEntity, ModelFieldTypeReader modelFieldTypeReader, DatasourceInfo datasourceInfo) throws GenericEntityException { + public static String makeViewTable(ModelEntity modelEntity, ModelFieldTypeReader modelFieldTypeReader, Datasource datasourceInfo) throws GenericEntityException { if (modelEntity instanceof ModelViewEntity) { StringBuilder sql = new StringBuilder("(SELECT "); Iterator<ModelField> fieldsIter = modelEntity.getFieldsIterator(); @@ -419,7 +419,7 @@ public class SqlJdbcUtil { } } sql.append(makeFromClause(modelEntity, modelFieldTypeReader, datasourceInfo)); - String viewWhereClause = makeViewWhereClause(modelEntity, datasourceInfo.joinStyle); + String viewWhereClause = makeViewWhereClause(modelEntity, datasourceInfo.getJoinStyle()); ModelViewEntity modelViewEntity = (ModelViewEntity)modelEntity; List<EntityCondition> whereConditions = new LinkedList<EntityCondition>(); List<EntityCondition> havingConditions = new LinkedList<EntityCondition>(); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java Fri Jun 7 08:39:44 2013 @@ -47,7 +47,7 @@ import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; -import org.ofbiz.entity.config.DatasourceInfo; +import org.ofbiz.entity.config.model.Datasource; import org.ofbiz.entity.config.EntityConfigUtil; import org.ofbiz.entity.jdbc.DatabaseUtil; import org.ofbiz.entity.model.ModelIndex.Field; @@ -396,13 +396,13 @@ public class ModelEntity implements Comp /** The table-name of the Entity including a Schema name if specified in the datasource config */ public String getTableName(String helperName) { - return getTableName(EntityConfigUtil.getDatasourceInfo(helperName)); + return getTableName(EntityConfigUtil.getDatasource(helperName)); } /** The table-name of the Entity including a Schema name if specified in the datasource config */ - public String getTableName(DatasourceInfo datasourceInfo) { - if (datasourceInfo != null && UtilValidate.isNotEmpty(datasourceInfo.schemaName)) { - return datasourceInfo.schemaName + "." + this.tableName; + public String getTableName(Datasource datasourceInfo) { + if (datasourceInfo != null && UtilValidate.isNotEmpty(datasourceInfo.getSchemaName())) { + return datasourceInfo.getSchemaName() + "." + this.tableName; } else { return this.tableName; } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldTypeReader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldTypeReader.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldTypeReader.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldTypeReader.java Fri Jun 7 08:39:44 2013 @@ -32,7 +32,7 @@ import org.ofbiz.base.util.UtilTimer; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.cache.UtilCache; -import org.ofbiz.entity.config.DatasourceInfo; +import org.ofbiz.entity.config.model.Datasource; import org.ofbiz.entity.config.EntityConfigUtil; import org.ofbiz.entity.config.FieldTypeInfo; import org.w3c.dom.Document; @@ -65,11 +65,11 @@ public class ModelFieldTypeReader implem } public static ModelFieldTypeReader getModelFieldTypeReader(String helperName) { - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName); + Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperName); if (datasourceInfo == null) { throw new IllegalArgumentException("Could not find a datasource/helper with the name " + helperName); } - String tempModelName = datasourceInfo.fieldTypeName; + String tempModelName = datasourceInfo.getFieldTypeName(); ModelFieldTypeReader reader = readers.get(tempModelName); while (reader == null) { FieldTypeInfo fieldTypeInfo = EntityConfigUtil.getFieldTypeInfo(tempModelName); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java Fri Jun 7 08:39:44 2013 @@ -44,7 +44,7 @@ import org.ofbiz.entity.condition.Entity import org.ofbiz.entity.condition.EntityConditionList; import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityOperator; -import org.ofbiz.entity.config.DatasourceInfo; +import org.ofbiz.entity.config.model.Datasource; import org.ofbiz.entity.config.EntityConfigUtil; import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.model.ModelField; @@ -385,9 +385,9 @@ public class EntityTestSuite extends Ent public void testForeignKeyCreate() { try { String helperName = delegator.getEntityHelper("Testing").getHelperName(); - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName); - if (!datasourceInfo.useFks) { - Debug.logInfo("Datasource " + datasourceInfo.name + " use-foreign-keys set to false, skipping testForeignKeyCreate", module); + Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperName); + if (!datasourceInfo.getUseForeignKeys()) { + Debug.logInfo("Datasource " + datasourceInfo.getName() + " use-foreign-keys set to false, skipping testForeignKeyCreate", module); return; } } catch (GenericEntityException e) { @@ -409,9 +409,9 @@ public class EntityTestSuite extends Ent public void testForeignKeyRemove() { try { String helperName = delegator.getEntityHelper("TestingNode").getHelperName(); - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName); - if (!datasourceInfo.useFks) { - Debug.logInfo("Datasource " + datasourceInfo.name + " use-foreign-keys set to false, skipping testForeignKeyRemove", module); + Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperName); + if (!datasourceInfo.getUseForeignKeys()) { + Debug.logInfo("Datasource " + datasourceInfo.getName() + " use-foreign-keys set to false, skipping testForeignKeyRemove", module); return; } } catch (GenericEntityException e) { @@ -742,7 +742,7 @@ public class EntityTestSuite extends Ent */ /*public void testLimitOffsetOptions() throws Exception { String entityName = "Content"; - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(delegator.getEntityHelper(entityName).getHelperName()); + Datasource datasourceInfo = EntityConfigUtil.getDatasource(delegator.getEntityHelper(entityName).getHelperName()); if (UtilValidate.isEmpty(datasourceInfo.offsetStyle) || datasourceInfo.offsetStyle.equals("none")) { Debug.logInfo("The offset-stype configured in datasource is " + datasourceInfo.offsetStyle + ", this test is skipped.", module); return; Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/DumbFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/DumbFactory.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/DumbFactory.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/DumbFactory.java Fri Jun 7 08:39:44 2013 @@ -34,7 +34,7 @@ import javax.transaction.UserTransaction import org.ofbiz.base.util.Debug; import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.config.DatasourceInfo; +import org.ofbiz.entity.config.model.Datasource; import org.ofbiz.entity.config.EntityConfigUtil; import org.ofbiz.entity.datasource.GenericHelperInfo; import org.ofbiz.entity.jdbc.ConnectionFactory; @@ -108,10 +108,10 @@ public class DumbFactory implements Tran } public Connection getConnection(GenericHelperInfo helperInfo) throws SQLException, GenericEntityException { - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperInfo.getHelperBaseName()); + Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperInfo.getHelperBaseName()); - if (datasourceInfo.inlineJdbcElement != null) { - Connection otherCon = ConnectionFactory.getManagedConnection(helperInfo, datasourceInfo.inlineJdbcElement); + if (datasourceInfo.getInlineJdbc() != null) { + Connection otherCon = ConnectionFactory.getManagedConnection(helperInfo, datasourceInfo.getInlineJdbc()); return TransactionFactory.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); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/JNDIFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/JNDIFactory.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/JNDIFactory.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/JNDIFactory.java Fri Jun 7 08:39:44 2013 @@ -37,7 +37,7 @@ import org.ofbiz.base.util.GeneralExcept import org.ofbiz.base.util.JNDIContextFactory; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.config.DatasourceInfo; +import org.ofbiz.entity.config.model.*; import org.ofbiz.entity.config.EntityConfigUtil; import org.ofbiz.entity.datasource.GenericHelperInfo; import org.ofbiz.entity.jdbc.ConnectionFactory; @@ -134,20 +134,20 @@ public class JNDIFactory implements Tran } public Connection getConnection(GenericHelperInfo helperInfo) throws SQLException, GenericEntityException { - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperInfo.getHelperBaseName()); + Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperInfo.getHelperBaseName()); - if (datasourceInfo.jndiJdbcElement != null) { - Element jndiJdbcElement = datasourceInfo.jndiJdbcElement; - String jndiName = jndiJdbcElement.getAttribute("jndi-name"); - String jndiServerName = jndiJdbcElement.getAttribute("jndi-server-name"); + if (datasourceInfo.getJndiJdbc() != null) { + JndiJdbc jndiJdbcElement = datasourceInfo.getJndiJdbc(); + String jndiName = jndiJdbcElement.getJndiName(); + String jndiServerName = jndiJdbcElement.getJndiServerName(); Connection con = getJndiConnection(jndiName, jndiServerName); if (con != null) return TransactionFactory.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.inlineJdbcElement != null) { - Connection otherCon = ConnectionFactory.getManagedConnection(helperInfo, datasourceInfo.inlineJdbcElement); + if (datasourceInfo.getInlineJdbc() != null) { + Connection otherCon = ConnectionFactory.getManagedConnection(helperInfo, datasourceInfo.getInlineJdbc()); return TransactionFactory.getCursorConnection(helperInfo, otherCon); } else { //no real need to print an error here Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactory.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactory.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactory.java Fri Jun 7 08:39:44 2013 @@ -20,14 +20,17 @@ package org.ofbiz.entity.transaction; import java.sql.Connection; import java.sql.SQLException; +import java.util.concurrent.atomic.AtomicReference; + import javax.transaction.TransactionManager; import javax.transaction.UserTransaction; import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.config.DatasourceInfo; +import org.ofbiz.entity.config.model.Datasource; +import org.ofbiz.entity.config.EntityConfigListener; import org.ofbiz.entity.config.EntityConfigUtil; +import org.ofbiz.entity.config.model.EntityConfig; import org.ofbiz.entity.datasource.GenericHelperInfo; import org.ofbiz.entity.jdbc.CursorConnection; @@ -37,48 +40,50 @@ import org.ofbiz.entity.jdbc.CursorConne public class TransactionFactory { public static final String module = TransactionFactory.class.getName(); - public static TransactionFactoryInterface transactionFactory = null; + private static final AtomicReference<TransactionFactoryInterface> txFactoryRef = new AtomicReference<TransactionFactoryInterface>(null); + private static final EntityConfigListener configListener = new EntityConfigListener() { + @Override + public void onEntityConfigChange(EntityConfig entityConfig) throws Exception { + TransactionFactoryInterface instance = createTransactionFactoryInterface(); + TransactionFactoryInterface previousInstance = txFactoryRef.getAndSet(instance); + if (previousInstance != null) { + previousInstance.shutdown(); + Debug.logInfo("Listener shut down TransactionFactoryInterface instance " + previousInstance, module); + } + Debug.logInfo("Listener created new TransactionFactoryInterface instance " + instance, module); + } + }; + + public static EntityConfigListener getConfigListener() { + return configListener; + } - public static TransactionFactoryInterface getTransactionFactory() { - if (transactionFactory == null) { // don't want to block here - synchronized (TransactionFactory.class) { - // must check if null again as one of the blocked threads can still enter - if (transactionFactory == null) { - try { - String className = EntityConfigUtil.getTxFactoryClass(); - - if (className == null) { - throw new IllegalStateException("Could not find transaction factory class name definition"); - } - Class<?> tfClass = null; - - if (UtilValidate.isNotEmpty(className)) { - try { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - tfClass = loader.loadClass(className); - } catch (ClassNotFoundException e) { - Debug.logWarning(e, module); - throw new IllegalStateException("Error loading TransactionFactory class \"" + className + "\": " + e.getMessage()); - } - } - - try { - transactionFactory = (TransactionFactoryInterface) tfClass.newInstance(); - } catch (IllegalAccessException e) { - Debug.logWarning(e, module); - throw new IllegalStateException("Error loading TransactionFactory class \"" + className + "\": " + e.getMessage()); - } catch (InstantiationException e) { - Debug.logWarning(e, module); - throw new IllegalStateException("Error loading TransactionFactory class \"" + className + "\": " + e.getMessage()); - } - } catch (SecurityException e) { - Debug.logError(e, module); - throw new IllegalStateException("Error loading TransactionFactory class: " + e.getMessage()); - } + private static TransactionFactoryInterface createTransactionFactoryInterface() throws Exception { + String className = EntityConfigUtil.getTxFactoryClass(); + if (className == null) { + throw new IllegalStateException("Could not find transaction factory class name definition"); + } + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + Class<?> tfClass = loader.loadClass(className); + return (TransactionFactoryInterface) tfClass.newInstance(); + } + + private static TransactionFactoryInterface getTransactionFactory() { + TransactionFactoryInterface instance = txFactoryRef.get(); + if (instance == null) { + try { + instance = createTransactionFactoryInterface(); + if (txFactoryRef.compareAndSet(null, instance)) { + Debug.logInfo("Factory method created new TransactionFactoryInterface instance " + instance, module); + } else { + instance = txFactoryRef.get(); } + } catch (Exception e) { + Debug.logError(e, "Exception thrown while creating TransactionFactoryInterface instance: ", module); + throw new IllegalStateException("Error loading TransactionFactory class: " + e); } } - return transactionFactory; + return instance; } public static TransactionManager getTransactionManager() { @@ -102,14 +107,14 @@ public class TransactionFactory { } public static Connection getCursorConnection(GenericHelperInfo helperInfo, Connection con) { - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperInfo.getHelperBaseName()); + 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.useProxyCursor) { + } else if (datasourceInfo.getUseProxyCursor()) { try { - if (datasourceInfo.resultFetchSize > 1) - con = CursorConnection.newCursorConnection(con, datasourceInfo.cursorName, datasourceInfo.resultFetchSize); + 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); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java Fri Jun 7 08:39:44 2013 @@ -49,6 +49,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.GenericEntityConfException; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.config.EntityConfigUtil; @@ -60,7 +61,6 @@ public class TransactionUtil implements // Debug module name public static final String module = TransactionUtil.class.getName(); public static Map<Xid, DebugXaResource> debugResMap = Collections.<Xid, DebugXaResource>synchronizedMap(new HashMap<Xid, DebugXaResource>()); - public static boolean debugResources = EntityConfigUtil.isDebugXAResource(); private static ThreadLocal<List<Transaction>> suspendedTxStack = new ThreadLocal<List<Transaction>>(); private static ThreadLocal<List<Exception>> suspendedTxLocationStack = new ThreadLocal<List<Exception>>(); @@ -169,7 +169,7 @@ public class TransactionUtil implements setTransactionBeginStack(); // initialize the debug resource - if (debugResources) { + if (EntityConfigUtil.isDebugXAResource()) { DebugXaResource dxa = new DebugXaResource(); try { dxa.enlist(); @@ -185,6 +185,8 @@ public class TransactionUtil implements } catch (SystemException e) { //This is Java 1.4 only, but useful for certain debuggins: Throwable t = e.getCause() == null ? e : e.getCause(); throw new GenericTransactionException("System error, could not begin transaction", e); + } catch (GenericEntityConfException e) { + throw new GenericTransactionException("Configuration error, could not begin transaction", e); } } else { if (Debug.infoOn()) Debug.logInfo("[TransactionUtil.begin] no user transaction, so no transaction begun", module); @@ -536,13 +538,21 @@ public class TransactionUtil implements } } + public static boolean debugResources() throws GenericEntityConfException { + return EntityConfigUtil.isDebugXAResource(); + } + public static void logRunningTx() { - if (debugResources) { - if (UtilValidate.isNotEmpty(debugResMap)) { - for (DebugXaResource dxa: debugResMap.values()) { - dxa.log(); + try { + if (EntityConfigUtil.isDebugXAResource()) { + if (UtilValidate.isNotEmpty(debugResMap)) { + for (DebugXaResource dxa: debugResMap.values()) { + dxa.log(); + } } } + } catch (GenericEntityConfException e) { + Debug.logWarning("Exception thrown while logging: " + e, module); } } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataLoader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataLoader.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataLoader.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataLoader.java Fri Jun 7 08:39:44 2013 @@ -35,9 +35,9 @@ import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; -import org.ofbiz.entity.config.DatasourceInfo; import org.ofbiz.entity.config.EntityConfigUtil; import org.ofbiz.entity.config.EntityDataReaderInfo; +import org.ofbiz.entity.config.model.*; import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.model.ModelReader; import org.ofbiz.entity.model.ModelUtil; @@ -54,28 +54,28 @@ public class EntityDataLoader { public static String getPathsString(String helperName) { StringBuilder pathBuffer = new StringBuilder(); if (UtilValidate.isNotEmpty(helperName)) { - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName); - for (Element sqlLoadPathElement: datasourceInfo.sqlLoadPaths) { - String prependEnv = sqlLoadPathElement.getAttribute("prepend-env"); + Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperName); + for (SqlLoadPath sqlLoadPath : datasourceInfo.getSqlLoadPathList()) { + String prependEnv = sqlLoadPath.getPrependEnv(); pathBuffer.append(pathBuffer.length() == 0 ? "" : ";"); if (UtilValidate.isNotEmpty(prependEnv)) { pathBuffer.append(System.getProperty(prependEnv)); pathBuffer.append("/"); } - pathBuffer.append(sqlLoadPathElement.getAttribute("path")); + pathBuffer.append(sqlLoadPath.getPath()); } } return pathBuffer.toString(); } public static List<URL> getUrlList(String helperName) { - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName); - return getUrlList(helperName, null, datasourceInfo.readDatas); + Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperName); + return getUrlList(helperName, null, datasourceInfo.getReadDataList()); } public static List<URL> getUrlList(String helperName, String componentName) { - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName); - return getUrlList(helperName, componentName, datasourceInfo.readDatas); + Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperName); + return getUrlList(helperName, componentName, datasourceInfo.getReadDataList()); } public static <E> List<URL> getUrlList(String helperName, List<E> readerNames) { @@ -92,6 +92,8 @@ public class EntityDataLoader { String readerName = null; if (readerInfo instanceof String) { readerName = (String) readerInfo; + } else if (readerInfo instanceof ReadData) { + readerName = ((ReadData) readerInfo).getReaderName(); } else if (readerInfo instanceof Element) { readerName = ((Element) readerInfo).getAttribute("reader-name"); } else { @@ -195,16 +197,10 @@ public class EntityDataLoader { } public static List<URL> getUrlByComponentList(String helperName, List<String> components) { - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName); + Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperName); List<String> readerNames = new LinkedList<String>(); - for (Object readerInfo : datasourceInfo.readDatas) { - String readerName = null; - if (readerInfo instanceof Element) { - readerName = ((Element) readerInfo).getAttribute("reader-name"); - } else { - throw new IllegalArgumentException("Reader name list does not contain String(s) or Element(s)"); - } - + for (ReadData readerInfo : datasourceInfo.getReadDataList()) { + String readerName = readerInfo.getReaderName(); // ignore the "tenant" reader if the multitenant property is "N" if ("tenant".equals(readerName) && "N".equals(UtilProperties.getPropertyValue("general.properties", "multitenant"))) { continue; Modified: ofbiz/trunk/framework/geronimo/src/org/ofbiz/geronimo/GeronimoTransactionFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/geronimo/src/org/ofbiz/geronimo/GeronimoTransactionFactory.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/geronimo/src/org/ofbiz/geronimo/GeronimoTransactionFactory.java (original) +++ ofbiz/trunk/framework/geronimo/src/org/ofbiz/geronimo/GeronimoTransactionFactory.java Fri Jun 7 08:39:44 2013 @@ -31,7 +31,7 @@ import org.apache.geronimo.transaction.m import org.apache.geronimo.transaction.manager.XidFactoryImpl; import org.ofbiz.base.util.Debug; import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.config.DatasourceInfo; +import org.ofbiz.entity.config.model.Datasource; import org.ofbiz.entity.config.EntityConfigUtil; import org.ofbiz.entity.datasource.GenericHelperInfo; import org.ofbiz.entity.jdbc.ConnectionFactory; @@ -77,10 +77,10 @@ public class GeronimoTransactionFactory } public Connection getConnection(GenericHelperInfo helperInfo) throws SQLException, GenericEntityException { - DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperInfo.getHelperBaseName()); + Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperInfo.getHelperBaseName()); - if (datasourceInfo != null && datasourceInfo.inlineJdbcElement != null) { - return ConnectionFactory.getManagedConnection(helperInfo, datasourceInfo.inlineJdbcElement); + if (datasourceInfo != null && datasourceInfo.getInlineJdbc() != null) { + return ConnectionFactory.getManagedConnection(helperInfo, datasourceInfo.getInlineJdbc()); } else { Debug.logError("Geronimo 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/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?rev=1490541&r1=1490540&r2=1490541&view=diff ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Fri Jun 7 08:39:44 2013 @@ -38,6 +38,7 @@ import org.ofbiz.base.util.UtilXml; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.DelegatorFactory; import org.ofbiz.entity.GenericDelegator; +import org.ofbiz.entity.GenericEntityConfException; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.transaction.DebugXaResource; @@ -299,7 +300,7 @@ public class ServiceDispatcher { beganTrans = TransactionUtil.begin(modelService.transactionTimeout); } // enlist for XAResource debugging - if (beganTrans && TransactionUtil.debugResources) { + if (beganTrans && TransactionUtil.debugResources()) { DebugXaResource dxa = new DebugXaResource(modelService.name); try { dxa.enlist(); @@ -420,7 +421,7 @@ public class ServiceDispatcher { beganTrans = TransactionUtil.begin(modelService.transactionTimeout); // enlist for XAResource debugging - if (beganTrans && TransactionUtil.debugResources) { + if (beganTrans && TransactionUtil.debugResources()) { DebugXaResource dxa = new DebugXaResource(modelService.name); try { dxa.enlist(); @@ -546,6 +547,9 @@ public class ServiceDispatcher { } catch (GenericTransactionException te) { Debug.logError(te, "Problems with the transaction", module); throw new GenericServiceException("Problems with the transaction.", te.getNested()); + } catch (GenericEntityConfException e) { + Debug.logError(e, "Problems with the transaction", module); + throw new GenericServiceException("Problems with the transaction.", e); } finally { if (lock != null) { // release the semaphore lock @@ -652,7 +656,7 @@ public class ServiceDispatcher { beganTrans = TransactionUtil.begin(service.transactionTimeout); } // enlist for XAResource debugging - if (beganTrans && TransactionUtil.debugResources) { + if (beganTrans && TransactionUtil.debugResources()) { DebugXaResource dxa = new DebugXaResource(service.name); try { dxa.enlist(); @@ -739,6 +743,9 @@ public class ServiceDispatcher { } catch (GenericTransactionException se) { Debug.logError(se, "Problems with the transaction", module); throw new GenericServiceException("Problems with the transaction: " + se.getMessage() + "; See logs for more detail"); + } catch (GenericEntityConfException e) { + Debug.logError(e, "Problems with the transaction", module); + throw new GenericServiceException("Problems with the transaction: " + e.getMessage() + "; See logs for more detail"); } finally { // resume the parent transaction if (parentTransaction != null) { |
| Free forum by Nabble | Edit this page |
