You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2013/06/07 10:39:45 UTC
svn commit: r1490541 [1/2] - in /ofbiz/trunk:
applications/product/src/org/ofbiz/product/product/
framework/common/src/org/ofbiz/common/ framework/entity/src/org/ofbiz/entity/
framework/entity/src/org/ofbiz/entity/condition/
framework/entity/src/org/of...
Author: adrianc
Date: Fri Jun 7 08:39:44 2013
New Revision: 1490541
URL: http://svn.apache.org/r1490541
Log:
First pass at removing cached DOM tree code from EntityConfigUtil.java. I converted some of the code to use the new thread-safe models. I also fixed some concurrency problems in related classes by replacing DCL with java.util.concurrent classes. I discovered the new multi-threaded component loader was creating duplicate resources, so these changes fix that.
Removed:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/DatasourceInfo.java
Modified:
ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java
ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBase.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigListener.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigUtil.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/EntityConfig.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/ConnectionFactoryInterface.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperFactory.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/ConnectionFactory.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldTypeReader.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/DumbFactory.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/JNDIFactory.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactory.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataLoader.java
ofbiz/trunk/framework/geronimo/src/org/ofbiz/geronimo/GeronimoTransactionFactory.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java Fri Jun 7 08:39:44 2013
@@ -647,7 +647,7 @@ public class ProductSearch {
this.entityConditionList.add(topCond);
- Debug.logInfo("topCond=" + topCond.makeWhereString(null, FastList.<EntityConditionParam>newInstance(), EntityConfigUtil.getDatasourceInfo(delegator.getEntityHelperName("Product"))), module);
+ Debug.logInfo("topCond=" + topCond.makeWhereString(null, FastList.<EntityConditionParam>newInstance(), EntityConfigUtil.getDatasource(delegator.getEntityHelperName("Product"))), module);
}
public EntityListIterator doQuery(Delegator delegator) {
Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java (original)
+++ ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java Fri Jun 7 08:39:44 2013
@@ -56,6 +56,7 @@ import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.GenericEntityConfException;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.model.ModelEntity;
@@ -367,14 +368,18 @@ public class CommonServices {
}
public static Map<String, Object> displayXaDebugInfo(DispatchContext dctx, Map<String, ?> context) {
- if (TransactionUtil.debugResources) {
- if (UtilValidate.isNotEmpty(TransactionUtil.debugResMap)) {
- TransactionUtil.logRunningTx();
+ try {
+ if (TransactionUtil.debugResources()) {
+ if (UtilValidate.isNotEmpty(TransactionUtil.debugResMap)) {
+ TransactionUtil.logRunningTx();
+ } else {
+ Debug.logInfo("No running transaction to display.", module);
+ }
} else {
- Debug.logInfo("No running transaction to display.", module);
+ Debug.logInfo("Debug resources is disabled.", module);
}
- } else {
- Debug.logInfo("Debug resources is disabled.", module);
+ } catch (GenericEntityConfException e) {
+ return ServiceUtil.returnError(e.getMessage());
}
return ServiceUtil.returnSuccess();
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Fri Jun 7 08:39:44 2013
@@ -48,9 +48,9 @@ import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.UtilXml;
import org.ofbiz.entity.cache.Cache;
import org.ofbiz.entity.condition.EntityCondition;
-import org.ofbiz.entity.config.DatasourceInfo;
import org.ofbiz.entity.config.DelegatorInfo;
import org.ofbiz.entity.config.EntityConfigUtil;
+import org.ofbiz.entity.config.model.Datasource;
import org.ofbiz.entity.datasource.GenericHelper;
import org.ofbiz.entity.datasource.GenericHelperFactory;
import org.ofbiz.entity.datasource.GenericHelperInfo;
@@ -271,16 +271,16 @@ public class GenericDelegator implements
// get the helper and if configured, do the datasource check
GenericHelper helper = GenericHelperFactory.getHelper(helperInfo);
- DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperBaseName);
- if (datasourceInfo.checkOnStart) {
- if (Debug.infoOn()) {
- Debug.logInfo("Doing database check as requested in entityengine.xml with addMissing=" + datasourceInfo.addMissingOnStart, module);
- }
- try {
- helper.checkDataSource(this.getModelEntityMapByGroup(groupName), null, datasourceInfo.addMissingOnStart);
- } catch (GenericEntityException e) {
- Debug.logWarning(e, e.getMessage(), module);
+ try {
+ Datasource datasource = EntityConfigUtil.getDatasource(helperBaseName);
+ if (datasource.getCheckOnStart()) {
+ if (Debug.infoOn()) {
+ Debug.logInfo("Doing database check as requested in entityengine.xml with addMissing=" + datasource.getAddMissingOnStart(), module);
+ }
+ helper.checkDataSource(this.getModelEntityMapByGroup(groupName), null, datasource.getAddMissingOnStart());
}
+ } catch (GenericEntityException e) {
+ Debug.logWarning(e, e.getMessage(), module);
}
}
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java Fri Jun 7 08:39:44 2013
@@ -30,7 +30,7 @@ import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericModelException;
-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;
@@ -76,7 +76,7 @@ public abstract class EntityComparisonOp
}
@Override
- public void addSqlValue(StringBuilder sql, ModelEntity entity, List<EntityConditionParam> entityConditionParams, boolean compat, L lhs, R rhs, DatasourceInfo datasourceInfo) {
+ public void addSqlValue(StringBuilder sql, ModelEntity entity, List<EntityConditionParam> entityConditionParams, boolean compat, L lhs, R rhs, Datasource datasourceInfo) {
//Debug.logInfo("EntityComparisonOperator.addSqlValue field=" + lhs + ", value=" + rhs + ", value type=" + (rhs == null ? "null object" : rhs.getClass().getName()), module);
// if this is an IN operator and the rhs Object isEmpty, add "1=0" instead of the normal SQL. Note that "FALSE" does not work with all databases.
@@ -110,12 +110,12 @@ public abstract class EntityComparisonOp
return false;
}
- protected void makeRHSWhereString(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sql, ModelField field, R rhs, DatasourceInfo datasourceInfo) {
+ protected void makeRHSWhereString(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sql, ModelField field, R rhs, Datasource datasourceInfo) {
sql.append(' ').append(getCode()).append(' ');
makeRHSWhereStringValue(entity, entityConditionParams, sql, field, rhs, datasourceInfo);
}
- protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sql, ModelField field, R rhs, DatasourceInfo datasourceInfo) {
+ protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sql, ModelField field, R rhs, Datasource datasourceInfo) {
if (rhs instanceof EntityConditionValue) {
EntityConditionValue ecv = (EntityConditionValue) rhs;
ecv.addSqlValue(sql, entity, entityConditionParams, false, datasourceInfo);
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java Fri Jun 7 08:39:44 2013
@@ -30,7 +30,7 @@ import org.ofbiz.base.lang.IsEmpty;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntity;
import org.ofbiz.entity.GenericModelException;
-import org.ofbiz.entity.config.DatasourceInfo;
+import org.ofbiz.entity.config.model.Datasource;
import org.ofbiz.entity.model.ModelEntity;
/**
@@ -146,7 +146,7 @@ public abstract class EntityCondition ex
throw new IllegalArgumentException(getClass().getName() + ".accept not implemented");
}
- abstract public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo);
+ abstract public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, Datasource datasourceInfo);
abstract public void checkCondition(ModelEntity modelEntity) throws GenericModelException;
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBase.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBase.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBase.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBase.java Fri Jun 7 08:39:44 2013
@@ -25,7 +25,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.ofbiz.entity.config.DatasourceInfo;
+import org.ofbiz.entity.config.model.Datasource;
import org.ofbiz.entity.jdbc.SqlJdbcUtil;
import org.ofbiz.entity.model.ModelEntity;
import org.ofbiz.entity.model.ModelField;
@@ -58,7 +58,7 @@ public abstract class EntityConditionBas
return modelField;
}
- protected String getColName(Map<String, String> tableAliases, ModelEntity modelEntity, String fieldName, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) {
+ protected String getColName(Map<String, String> tableAliases, ModelEntity modelEntity, String fieldName, boolean includeTableNamePrefix, Datasource datasourceInfo) {
if (modelEntity == null) return fieldName;
return getColName(tableAliases, modelEntity, getField(modelEntity, fieldName), fieldName, includeTableNamePrefix, datasourceInfo);
}
@@ -73,11 +73,11 @@ public abstract class EntityConditionBas
return colName;
}
- protected String getColName(Map<String, String> tableAliases, ModelEntity modelEntity, ModelField modelField, String fieldName, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) {
+ protected String getColName(Map<String, String> tableAliases, ModelEntity modelEntity, ModelField modelField, String fieldName, boolean includeTableNamePrefix, Datasource datasourceInfo) {
if (modelEntity == null || modelField == null) return fieldName;
// if this is a view entity and we are configured to alias the views, use the alias here instead of the composite (ie table.column) field name
- if (datasourceInfo != null && datasourceInfo.aliasViews && modelEntity instanceof ModelViewEntity) {
+ if (datasourceInfo != null && datasourceInfo.getAliasViewColumns() && modelEntity instanceof ModelViewEntity) {
ModelViewEntity modelViewEntity = (ModelViewEntity) modelEntity;
ModelAlias modelAlias = modelViewEntity.getAlias(fieldName);
if (modelAlias != null) {
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java Fri Jun 7 08:39:44 2013
@@ -24,7 +24,7 @@ import java.util.Map;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericModelException;
-import org.ofbiz.entity.config.DatasourceInfo;
+import org.ofbiz.entity.config.model.Datasource;
import org.ofbiz.entity.model.ModelEntity;
/**
@@ -106,7 +106,7 @@ public abstract class EntityConditionFun
}
@Override
- public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo) {
+ public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, Datasource datasourceInfo) {
StringBuilder sb = new StringBuilder();
sb.append(codeString).append('(');
sb.append(condition.makeWhereString(modelEntity, entityConditionParams, datasourceInfo));
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java Fri Jun 7 08:39:44 2013
@@ -26,7 +26,7 @@ import java.util.Map;
import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericModelException;
-import org.ofbiz.entity.config.DatasourceInfo;
+import org.ofbiz.entity.config.model.Datasource;
import org.ofbiz.entity.model.ModelEntity;
/**
@@ -92,7 +92,7 @@ public abstract class EntityConditionLis
}
@Override
- public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo) {
+ public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, Datasource datasourceInfo) {
// if (Debug.verboseOn()) Debug.logVerbose("makeWhereString for entity " + modelEntity.getEntityName(), module);
StringBuilder sql = new StringBuilder();
operator.addSqlValue(sql, modelEntity, entityConditionParams, conditionList, datasourceInfo);
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java Fri Jun 7 08:39:44 2013
@@ -25,7 +25,7 @@ import org.ofbiz.base.util.Debug;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericModelException;
-import org.ofbiz.entity.config.DatasourceInfo;
+import org.ofbiz.entity.config.model.Datasource;
import org.ofbiz.entity.jdbc.SqlJdbcUtil;
import org.ofbiz.entity.model.ModelEntity;
import org.ofbiz.entity.model.ModelField;
@@ -58,7 +58,7 @@ public class EntityConditionSubSelect ex
@Override
public void addSqlValue(StringBuilder sql, Map<String, String> tableAliases, ModelEntity parentModelEntity, List<EntityConditionParam> entityConditionParams,
- boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) {
+ boolean includeTableNamePrefix, Datasource datasourceInfo) {
if (localModelEntity instanceof ModelViewEntity && datasourceInfo == null) {
throw new IllegalArgumentException("Call to EntityConditionSubSelect.addSqlValue with datasourceInfo=null which is not allowed because the local entity [" + this.localModelEntity.getEntityName() + "] is a view entity");
}
@@ -85,7 +85,7 @@ public class EntityConditionSubSelect ex
entityCondWhereString = this.whereCond.makeWhereString(localModelEntity, entityConditionParams, datasourceInfo);
}
- String viewClause = SqlJdbcUtil.makeViewWhereClause(localModelEntity, (datasourceInfo != null ? datasourceInfo.joinStyle : null));
+ String viewClause = SqlJdbcUtil.makeViewWhereClause(localModelEntity, (datasourceInfo != null ? datasourceInfo.getJoinStyle() : null));
if (viewClause.length() > 0) {
if (entityCondWhereString.length() > 0) {
whereString.append("(");
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java Fri Jun 7 08:39:44 2013
@@ -25,7 +25,7 @@ import java.util.Map;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntity;
import org.ofbiz.entity.GenericModelException;
-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;
@@ -39,12 +39,12 @@ public abstract class EntityConditionVal
public abstract ModelField getModelField(ModelEntity modelEntity);
public void addSqlValue(StringBuilder sql, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean includeTableNamePrefix,
- DatasourceInfo datasourceinfo) {
+ Datasource datasourceinfo) {
addSqlValue(sql, emptyAliases, modelEntity, entityConditionParams, includeTableNamePrefix, datasourceinfo);
}
public abstract void addSqlValue(StringBuilder sql, Map<String, String> tableAliases, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams,
- boolean includeTableNamePrefix, DatasourceInfo datasourceinfo);
+ boolean includeTableNamePrefix, Datasource datasourceinfo);
public abstract void validateSql(ModelEntity modelEntity) throws GenericModelException;
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java Fri Jun 7 08:39:44 2013
@@ -26,7 +26,7 @@ import java.util.Map;
import org.ofbiz.base.util.UtilDateTime;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericModelException;
-import org.ofbiz.entity.config.DatasourceInfo;
+import org.ofbiz.entity.config.model.Datasource;
import org.ofbiz.entity.model.ModelEntity;
/**
@@ -55,7 +55,7 @@ public class EntityDateFilterCondition e
}
@Override
- public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo) {
+ public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, Datasource datasourceInfo) {
EntityCondition condition = makeCondition();
return condition.makeWhereString(modelEntity, entityConditionParams, datasourceInfo);
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java Fri Jun 7 08:39:44 2013
@@ -31,7 +31,7 @@ import org.ofbiz.entity.EntityCryptoExce
import org.ofbiz.entity.GenericEntity;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericModelException;
-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;
@@ -119,7 +119,7 @@ public class EntityExpr extends EntityCo
}
@Override
- public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo) {
+ public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, Datasource datasourceInfo) {
// if (Debug.verboseOn()) Debug.logVerbose("makeWhereString for entity " + modelEntity.getEntityName(), module);
this.checkRhsType(modelEntity, null);
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java Fri Jun 7 08:39:44 2013
@@ -28,7 +28,7 @@ import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntity;
import org.ofbiz.entity.GenericModelException;
-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.ModelViewEntity;
@@ -123,7 +123,7 @@ public class EntityFieldValue extends En
}
@Override
- public void addSqlValue(StringBuilder sql, Map<String, String> tableAliases, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) {
+ public void addSqlValue(StringBuilder sql, Map<String, String> tableAliases, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean includeTableNamePrefix, Datasource datasourceInfo) {
if (this.modelViewEntity != null) {
// NOTE: this section is a bit of a hack; the other code is terribly complex and really needs to be refactored to incorporate support for this
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java Fri Jun 7 08:39:44 2013
@@ -28,7 +28,7 @@ import javolution.lang.Reusable;
import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericModelException;
-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;
@@ -246,7 +246,7 @@ public abstract class EntityFunction<T e
}
@Override
- public void addSqlValue(StringBuilder sql, Map<String, String> tableAliases, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean includeTableNamePrefix, DatasourceInfo datasourceinfo) {
+ public void addSqlValue(StringBuilder sql, Map<String, String> tableAliases, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean includeTableNamePrefix, Datasource datasourceinfo) {
sql.append(function.name()).append('(');
if (nested != null) {
nested.addSqlValue(sql, tableAliases, modelEntity, entityConditionParams, includeTableNamePrefix, datasourceinfo);
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java Fri Jun 7 08:39:44 2013
@@ -29,7 +29,7 @@ import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntity;
import org.ofbiz.entity.GenericModelException;
-import org.ofbiz.entity.config.DatasourceInfo;
+import org.ofbiz.entity.config.model.Datasource;
import org.ofbiz.entity.model.ModelEntity;
/**
@@ -47,14 +47,14 @@ public class EntityJoinOperator extends
}
@Override
- public void addSqlValue(StringBuilder sql, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean compat, EntityCondition lhs, EntityCondition rhs, DatasourceInfo datasourceInfo) {
+ public void addSqlValue(StringBuilder sql, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean compat, EntityCondition lhs, EntityCondition rhs, Datasource datasourceInfo) {
List<EntityCondition> conditions = new LinkedList<EntityCondition>();
conditions.add(lhs);
conditions.add(rhs);
addSqlValue(sql, modelEntity, entityConditionParams, conditions, datasourceInfo);
}
- public void addSqlValue(StringBuilder sql, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, List<? extends EntityCondition> conditionList, DatasourceInfo datasourceInfo) {
+ public void addSqlValue(StringBuilder sql, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, List<? extends EntityCondition> conditionList, Datasource datasourceInfo) {
if (UtilValidate.isNotEmpty(conditionList)) {
boolean hadSomething = false;
Iterator<? extends EntityCondition> conditionIter = conditionList.iterator();
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java Fri Jun 7 08:39:44 2013
@@ -30,7 +30,7 @@ import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntity;
import org.ofbiz.entity.GenericModelException;
-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;
@@ -96,7 +96,7 @@ public abstract class EntityOperator<L,
@Override
public boolean compare(Comparable<Object> lhs, Object rhs) { return EntityComparisonOperator.compareEqual(lhs, rhs); }
@Override
- protected void makeRHSWhereString(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs, DatasourceInfo datasourceInfo) {
+ protected void makeRHSWhereString(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs, Datasource datasourceInfo) {
if (rhs == null || rhs == GenericEntity.NULL_FIELD) {
//Debug.logInfo("makeRHSWhereString: field IS NULL: " + field.getName(), module);
sb.append(" IS NULL");
@@ -112,7 +112,7 @@ public abstract class EntityOperator<L,
@Override
public boolean compare(Comparable<Object> lhs, Object rhs) { return EntityComparisonOperator.compareNotEqual(lhs, rhs); }
@Override
- protected void makeRHSWhereString(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs, DatasourceInfo datasourceInfo) {
+ protected void makeRHSWhereString(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs, Datasource datasourceInfo) {
if (rhs == null || rhs == GenericEntity.NULL_FIELD) {
sb.append(" IS NOT NULL");
} else {
@@ -161,14 +161,14 @@ public abstract class EntityOperator<L,
@Override
public boolean compare(Comparable<Object> lhs, Collection<Comparable<Object>> rhs) { return EntityComparisonOperator.compareIn(lhs, rhs); }
@Override
- protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Collection<Comparable<Object>> rhs, DatasourceInfo datasourceInfo) { appendRHSList(entityConditionParams, sb, field, rhs); }
+ protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Collection<Comparable<Object>> rhs, Datasource datasourceInfo) { appendRHSList(entityConditionParams, sb, field, rhs); }
};
static { register("in", IN); }
public static final EntityComparisonOperator<?,?> BETWEEN = new CollectionEntityComparisonOperator<Object>(ID_BETWEEN, "BETWEEN") {
@Override
public boolean compare(Comparable<Object> lhs, Collection<Comparable<Object>> rhs) { return EntityComparisonOperator.compareIn(lhs, rhs); }
@Override
- protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Collection<Comparable<Object>> rhs, DatasourceInfo datasourceInfo) { appendRHSBetweenList(entityConditionParams, sb, field, rhs); }
+ protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Collection<Comparable<Object>> rhs, Datasource datasourceInfo) { appendRHSBetweenList(entityConditionParams, sb, field, rhs); }
};
static { register("between", BETWEEN); }
public static final EntityComparisonOperator<?,?> NOT = new EntityComparisonOperator<Object, EntityCondition>(ID_NOT, "NOT") {
@@ -194,7 +194,7 @@ public abstract class EntityOperator<L,
@Override
public boolean compare(Comparable<Object> lhs, Collection<Comparable<Object>> rhs) { return !EntityComparisonOperator.compareIn(lhs, rhs); }
@Override
- protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Collection<Comparable<Object>> rhs, DatasourceInfo datasourceInfo) { appendRHSList(entityConditionParams, sb, field, rhs); }
+ protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Collection<Comparable<Object>> rhs, Datasource datasourceInfo) { appendRHSList(entityConditionParams, sb, field, rhs); }
};
static { register("not-in", NOT_IN); }
@@ -290,11 +290,11 @@ public abstract class EntityOperator<L,
public abstract boolean isEmpty(L lhs, R rhs);
public abstract boolean mapMatches(Delegator delegator, Map<String, ? extends Object> map, L lhs, R rhs);
public abstract void validateSql(ModelEntity entity, L lhs, R rhs) throws GenericModelException;
- public void addSqlValue(StringBuilder sql, ModelEntity entity, List<EntityConditionParam> entityConditionParams, L lhs, R rhs, DatasourceInfo datasourceInfo) {
+ public void addSqlValue(StringBuilder sql, ModelEntity entity, List<EntityConditionParam> entityConditionParams, L lhs, R rhs, Datasource datasourceInfo) {
addSqlValue(sql, entity, entityConditionParams, true, lhs, rhs, datasourceInfo);
}
- public abstract void addSqlValue(StringBuilder sql, ModelEntity entity, List<EntityConditionParam> entityConditionParams, boolean compat, L lhs, R rhs, DatasourceInfo datasourceInfo);
+ public abstract void addSqlValue(StringBuilder sql, ModelEntity entity, List<EntityConditionParam> entityConditionParams, boolean compat, L lhs, R rhs, Datasource datasourceInfo);
public abstract EntityCondition freeze(L lhs, R rhs);
public abstract void visit(EntityConditionVisitor visitor, L lhs, R rhs);
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java Fri Jun 7 08:39:44 2013
@@ -25,7 +25,7 @@ import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntity;
import org.ofbiz.entity.GenericModelException;
-import org.ofbiz.entity.config.DatasourceInfo;
+import org.ofbiz.entity.config.model.Datasource;
import org.ofbiz.entity.model.ModelEntity;
/**
@@ -58,7 +58,7 @@ public class EntityWhereString extends E
}
@Override
- public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo) {
+ public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, Datasource datasourceInfo) {
return sqlString;
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java Fri Jun 7 08:39:44 2013
@@ -24,7 +24,7 @@ import java.util.Comparator;
import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.entity.GenericEntity;
import org.ofbiz.entity.GenericModelException;
-import org.ofbiz.entity.config.DatasourceInfo;
+import org.ofbiz.entity.config.model.Datasource;
import org.ofbiz.entity.model.ModelEntity;
public class OrderByItem implements Comparator<GenericEntity> {
@@ -167,14 +167,14 @@ public class OrderByItem implements Comp
return descending ? -result : result;
}
- public String makeOrderByString(ModelEntity modelEntity, boolean includeTablenamePrefix, DatasourceInfo datasourceInfo) {
+ public String makeOrderByString(ModelEntity modelEntity, boolean includeTablenamePrefix, Datasource datasourceInfo) {
StringBuilder sb = new StringBuilder();
makeOrderByString(sb, modelEntity, includeTablenamePrefix, datasourceInfo);
return sb.toString();
}
- public void makeOrderByString(StringBuilder sb, ModelEntity modelEntity, boolean includeTablenamePrefix, DatasourceInfo datasourceInfo) {
- if ((nullsFirst != null) && (!datasourceInfo.useOrderByNulls)) {
+ public void makeOrderByString(StringBuilder sb, ModelEntity modelEntity, boolean includeTablenamePrefix, Datasource datasourceInfo) {
+ if ((nullsFirst != null) && (!datasourceInfo.getUseOrderByNulls())) {
sb.append("CASE WHEN ");
getValue().addSqlValue(sb, modelEntity, null, includeTablenamePrefix, datasourceInfo);
sb.append(" IS NULL THEN ");
@@ -187,7 +187,7 @@ public class OrderByItem implements Comp
getValue().addSqlValue(sb, modelEntity, null, includeTablenamePrefix, datasourceInfo);
sb.append(descending ? " DESC" : " ASC");
- if ((nullsFirst != null) && (datasourceInfo.useOrderByNulls)) {
+ if ((nullsFirst != null) && (datasourceInfo.getUseOrderByNulls())) {
sb.append(nullsFirst ? " NULLS FIRST" : " NULLS LAST");
}
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java Fri Jun 7 08:39:44 2013
@@ -26,7 +26,7 @@ import java.util.List;
import org.ofbiz.entity.GenericEntity;
import org.ofbiz.entity.GenericModelException;
-import org.ofbiz.entity.config.DatasourceInfo;
+import org.ofbiz.entity.config.model.Datasource;
import org.ofbiz.entity.model.ModelEntity;
public class OrderByList implements Comparator<GenericEntity> {
@@ -77,13 +77,13 @@ public class OrderByList implements Comp
}
}
- public String makeOrderByString(ModelEntity modelEntity, boolean includeTablenamePrefix, DatasourceInfo datasourceInfo) {
+ public String makeOrderByString(ModelEntity modelEntity, boolean includeTablenamePrefix, Datasource datasourceInfo) {
StringBuilder sb = new StringBuilder();
makeOrderByString(sb, modelEntity, includeTablenamePrefix, datasourceInfo);
return sb.toString();
}
- public void makeOrderByString(StringBuilder sb, ModelEntity modelEntity, boolean includeTablenamePrefix, DatasourceInfo datasourceInfo) {
+ public void makeOrderByString(StringBuilder sb, ModelEntity modelEntity, boolean includeTablenamePrefix, Datasource datasourceInfo) {
if (!orderByList.isEmpty()) {
sb.append(" ORDER BY ");
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigListener.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigListener.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigListener.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigListener.java Fri Jun 7 08:39:44 2013
@@ -30,6 +30,6 @@ public interface EntityConfigListener {
*
* @param entityConfig The new <code>EntityConfig</code> instance.
*/
- void onEntityConfigChange(EntityConfig entityConfig);
+ void onEntityConfigChange(EntityConfig entityConfig) throws Exception;
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigUtil.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigUtil.java Fri Jun 7 08:39:44 2013
@@ -19,10 +19,10 @@
package org.ofbiz.entity.config;
import java.net.URL;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicReference;
import org.ofbiz.base.config.GenericConfigException;
@@ -35,7 +35,11 @@ import org.ofbiz.base.util.UtilXml;
import org.ofbiz.base.util.cache.UtilCache;
import org.ofbiz.entity.GenericEntityConfException;
import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.config.model.Datasource;
import org.ofbiz.entity.config.model.EntityConfig;
+import org.ofbiz.entity.config.model.InlineJdbc;
+import org.ofbiz.entity.jdbc.ConnectionFactory;
+import org.ofbiz.entity.transaction.TransactionFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -49,7 +53,6 @@ public class EntityConfigUtil {
public static final String ENTITY_ENGINE_XML_FILENAME = "entityengine.xml";
// Keep the EntityConfig instance in a cache - so the configuration can be reloaded at run-time. There will be only one EntityConfig instance in the cache.
private static final UtilCache<String, EntityConfig> entityConfigCache = UtilCache.createUtilCache("entity.EntityConfig", 0, 0, false);
- private static final List<EntityConfigListener> configListeners = new CopyOnWriteArrayList<EntityConfigListener>();
public static String createConfigFileLineNumberText(Element element) {
if (element.getUserData("startLine") != null) {
@@ -65,15 +68,20 @@ public class EntityConfigUtil {
public static EntityConfig getEntityConfig() throws GenericEntityConfException {
EntityConfig instance = entityConfigCache.get("instance");
if (instance == null) {
- Element entityConfigElement = getXmlDocument().getDocumentElement();
- instance = new EntityConfig(entityConfigElement);
- entityConfigCache.putIfAbsent("instance", instance);
- instance = entityConfigCache.get("instance");
- for (EntityConfigListener listener : configListeners) {
- try {
- listener.onEntityConfigChange(instance);
- } catch (Exception e) {
- Debug.logError(e, "Exception thrown while notifying listener " + listener + ": ", module);
+ synchronized (EntityConfigUtil.class) {
+ // Sync ensures resources are initialized properly - do not remove.
+ Element entityConfigElement = getXmlDocument().getDocumentElement();
+ instance = new EntityConfig(entityConfigElement);
+ EntityConfig previousInstance = entityConfigCache.putIfAbsent("instance", instance);
+ instance = entityConfigCache.get("instance");
+ if (previousInstance == null) {
+ for (EntityConfigListener listener : getConfigListeners()) {
+ try {
+ listener.onEntityConfigChange(instance);
+ } catch (Exception e) {
+ Debug.logError(e, "Exception thrown while notifying listener " + listener + ": ", module);
+ }
+ }
}
}
}
@@ -92,20 +100,18 @@ public class EntityConfigUtil {
}
}
+ private static List<EntityConfigListener> getConfigListeners() {
+ // TODO: Build a list of listeners. Listeners must be notified in a specific order
+ // so resources can be deallocated/allocated properly and so dependencies can be followed.
+ List<EntityConfigListener> configListeners = new ArrayList<EntityConfigListener>();
+ configListeners.add(TransactionFactory.getConfigListener());
+ configListeners.add(ConnectionFactory.getConfigListener());
+ return configListeners;
+ }
+
private static volatile AtomicReference<EntityConfigUtil> configRef = new AtomicReference<EntityConfigUtil>();
// ========== engine info fields ==========
- private final String txFactoryClass;
- private final String txFactoryUserTxJndiName;
- private final String txFactoryUserTxJndiServerName;
- private final String txFactoryTxMgrJndiName;
- private final String txFactoryTxMgrJndiServerName;
- private final String connFactoryClass;
- /**
- * Create Begin stacktrace when enlisting transactions
- */
- private final Boolean debugXAResources;
-
private final Map<String, ResourceLoaderInfo> resourceLoaderInfos = new HashMap<String, ResourceLoaderInfo>();
private final Map<String, DelegatorInfo> delegatorInfos = new HashMap<String, DelegatorInfo>();
private final Map<String, EntityModelReaderInfo> entityModelReaderInfos = new HashMap<String, EntityModelReaderInfo>();
@@ -113,7 +119,6 @@ public class EntityConfigUtil {
private final Map<String, EntityEcaReaderInfo> entityEcaReaderInfos = new HashMap<String, EntityEcaReaderInfo>();
private final Map<String, EntityDataReaderInfo> entityDataReaderInfos = new HashMap<String, EntityDataReaderInfo>();
private final Map<String, FieldTypeInfo> fieldTypeInfos = new HashMap<String, FieldTypeInfo>();
- private final Map<String, DatasourceInfo> datasourceInfos = new HashMap<String, DatasourceInfo>();
private static Element getXmlRootElement() throws GenericEntityConfException {
try {
@@ -145,46 +150,6 @@ public class EntityConfigUtil {
}
private EntityConfigUtil(Element rootElement) throws GenericEntityException {
- // load the transaction factory
- Element transactionFactoryElement = UtilXml.firstChildElement(rootElement, "transaction-factory");
- if (transactionFactoryElement == null) {
- throw new GenericEntityConfException("ERROR: no transaction-factory definition was found in " + ENTITY_ENGINE_XML_FILENAME);
- }
-
- txFactoryClass = transactionFactoryElement.getAttribute("class");
-
- Element userTxJndiElement = UtilXml.firstChildElement(transactionFactoryElement, "user-transaction-jndi");
- if (userTxJndiElement != null) {
- txFactoryUserTxJndiName = userTxJndiElement.getAttribute("jndi-name");
- txFactoryUserTxJndiServerName = userTxJndiElement.getAttribute("jndi-server-name");
- } else {
- txFactoryUserTxJndiName = null;
- txFactoryUserTxJndiServerName = null;
- }
-
- Element txMgrJndiElement = UtilXml.firstChildElement(transactionFactoryElement, "transaction-manager-jndi");
- if (txMgrJndiElement != null) {
- txFactoryTxMgrJndiName = txMgrJndiElement.getAttribute("jndi-name");
- txFactoryTxMgrJndiServerName = txMgrJndiElement.getAttribute("jndi-server-name");
- } else {
- txFactoryTxMgrJndiName = null;
- txFactoryTxMgrJndiServerName = null;
- }
-
- // load the connection factory
- Element connectionFactoryElement = UtilXml.firstChildElement(rootElement, "connection-factory");
- if (connectionFactoryElement == null) {
- throw new GenericEntityConfException("ERROR: no connection-factory definition was found in " + ENTITY_ENGINE_XML_FILENAME);
- }
-
- connFactoryClass = connectionFactoryElement.getAttribute("class");
-
- Element debugXaResourcesElement = UtilXml.firstChildElement(rootElement, "debug-xa-resources");
- if (debugXaResourcesElement == null) { // This should not be since debug-xa-resources is required, but safer...
- debugXAResources = false;
- } else {
- debugXAResources = "true".equals(debugXaResourcesElement.getAttribute("value"));
- }
// not load all of the maps...
// resource-loader - resourceLoaderInfos
@@ -228,43 +193,38 @@ public class EntityConfigUtil {
FieldTypeInfo fieldTypeInfo = new FieldTypeInfo(curElement);
fieldTypeInfos.put(fieldTypeInfo.name, fieldTypeInfo);
}
+ }
- // datasource - datasourceInfos
- for (Element curElement: UtilXml.childElementList(rootElement, "datasource")) {
- DatasourceInfo datasourceInfo = new DatasourceInfo(curElement);
- datasourceInfos.put(datasourceInfo.name, datasourceInfo);
- }
+ public static String getTxFactoryClass() throws GenericEntityConfException {
+ return getEntityConfig().getTransactionFactory().getClassName();
}
- public static String getTxFactoryClass() {
- return configRef.get().txFactoryClass;
+ public static String getTxFactoryUserTxJndiName() throws GenericEntityConfException {
+ return getEntityConfig().getTransactionFactory().getUserTransactionJndi().getJndiName();
}
- public static String getTxFactoryUserTxJndiName() {
- return configRef.get().txFactoryUserTxJndiName;
+ public static String getTxFactoryUserTxJndiServerName() throws GenericEntityConfException {
+ return getEntityConfig().getTransactionFactory().getUserTransactionJndi().getJndiServerName();
}
- public static String getTxFactoryUserTxJndiServerName() {
- return configRef.get().txFactoryUserTxJndiServerName;
+ public static String getTxFactoryTxMgrJndiName() throws GenericEntityConfException {
+ return getEntityConfig().getTransactionFactory().getTransactionManagerJndi().getJndiName();
}
- public static String getTxFactoryTxMgrJndiName() {
- return configRef.get().txFactoryTxMgrJndiName;
+ public static String getTxFactoryTxMgrJndiServerName() throws GenericEntityConfException {
+ return getEntityConfig().getTransactionFactory().getTransactionManagerJndi().getJndiServerName();
}
/**
* @return true Create Begin stacktrace when enlisting transactions
+ * @throws GenericEntityConfException
*/
- public static boolean isDebugXAResource() {
- return configRef.get().debugXAResources;
- }
-
- public static String getTxFactoryTxMgrJndiServerName() {
- return configRef.get().txFactoryTxMgrJndiServerName;
+ public static boolean isDebugXAResource() throws GenericEntityConfException {
+ return getEntityConfig().getDebugXaResources().getValue();
}
- public static String getConnectionFactoryClass() {
- return configRef.get().connFactoryClass;
+ public static String getConnectionFactoryClass() throws GenericEntityConfException {
+ return getEntityConfig().getConnectionFactory().getClassName();
}
public static ResourceLoaderInfo getResourceLoaderInfo(String name) {
@@ -295,29 +255,37 @@ public class EntityConfigUtil {
return configRef.get().fieldTypeInfos.get(name);
}
- public static DatasourceInfo getDatasourceInfo(String name) {
- return configRef.get().datasourceInfos.get(name);
+ public static Datasource getDatasource(String name) {
+ try {
+ return getEntityConfig().getDatasource(name);
+ } catch (GenericEntityConfException e) {
+ // FIXME: Doing this so we don't have to rewrite the entire API.
+ throw new RuntimeException(e);
+ }
}
- public static Map<String, DatasourceInfo> getDatasourceInfos() {
- return configRef.get().datasourceInfos;
+ public static Map<String, Datasource> getDatasources() throws GenericEntityConfException {
+ return getEntityConfig().getDatasourceMap();
}
- public static String getJdbcPassword(Element inlineJdbcElement) {
- String jdbcPassword = inlineJdbcElement.getAttribute("jdbc-password");
+ public static String getJdbcPassword(InlineJdbc inlineJdbcElement) {
+ String jdbcPassword = inlineJdbcElement.getJdbcPassword();
if (UtilValidate.isNotEmpty(jdbcPassword)) {
return jdbcPassword;
}
- String jdbcPasswordLookup = inlineJdbcElement.getAttribute("jdbc-password-lookup");
+ String jdbcPasswordLookup = inlineJdbcElement.getJdbcPasswordLookup();
if (UtilValidate.isEmpty(jdbcPasswordLookup)) {
- Debug.logError("no @jdbc-password or @jdbc-password-lookup specified for inline-jdbc element: %s@%d:%d", module, inlineJdbcElement.getUserData("systemId"), inlineJdbcElement.getUserData("startLine"), inlineJdbcElement.getUserData("startColumn"));
+ // FIXME: Include line number in model
+ // Debug.logError("no @jdbc-password or @jdbc-password-lookup specified for inline-jdbc element: %s@%d:%d", module, inlineJdbcElement.getUserData("systemId"), inlineJdbcElement.getUserData("startLine"), inlineJdbcElement.getUserData("startColumn"));
+ Debug.logError("no jdbc-password or jdbc-password-lookup specified for inline-jdbc element", module);
return null;
}
String key = "jdbc-password." + jdbcPasswordLookup;
jdbcPassword = UtilProperties.getPropertyValue("passwords.properties", key);
if (UtilValidate.isEmpty(jdbcPassword)) {
- // This is a warning, not an error, as the
- Debug.logError("Could not find password %s specified for inline-jdbc element: %s@%d:%d", module, key, inlineJdbcElement.getUserData("systemId"), inlineJdbcElement.getUserData("startLine"), inlineJdbcElement.getUserData("startColumn"));
+ // FIXME: Include line number in model
+ // Debug.logError("no @jdbc-password or @jdbc-password-lookup specified for inline-jdbc element: %s@%d:%d", module, inlineJdbcElement.getUserData("systemId"), inlineJdbcElement.getUserData("startLine"), inlineJdbcElement.getUserData("startColumn"));
+ Debug.logError("no jdbc-password or jdbc-password-lookup specified for inline-jdbc element", module);
}
return jdbcPassword;
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/EntityConfig.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/EntityConfig.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/EntityConfig.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/EntityConfig.java Fri Jun 7 08:39:44 2013
@@ -21,6 +21,8 @@ package org.ofbiz.entity.config.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
import org.ofbiz.base.lang.ThreadSafe;
import org.ofbiz.base.util.UtilXml;
@@ -46,6 +48,7 @@ public final class EntityConfig {
private final List<EntityDataReader> entityDataReaderList; // <entity-data-reader>
private final List<FieldType> fieldTypeList; // <field-type>
private final List<Datasource> datasourceList; // <datasource>
+ private final Map<String, Datasource> datasourceMap;
public EntityConfig(Element element) throws GenericEntityConfException {
List<? extends Element> resourceLoaderElementList = UtilXml.childElementList(element, "resource-loader");
@@ -141,10 +144,14 @@ public final class EntityConfig {
throw new GenericEntityConfException("<" + element.getNodeName() + "> element child elements <datasource> are missing");
} else {
List<Datasource> datasourceList = new ArrayList<Datasource>(datasourceElementList.size());
+ Map<String, Datasource> datasourceMap = new HashMap<String, Datasource>();
for (Element datasourceElement : datasourceElementList) {
- datasourceList.add(new Datasource(datasourceElement));
+ Datasource datasource = new Datasource(datasourceElement);
+ datasourceList.add(datasource);
+ datasourceMap.put(datasource.getName(), datasource);
}
this.datasourceList = Collections.unmodifiableList(datasourceList);
+ this.datasourceMap = Collections.unmodifiableMap(datasourceMap);
}
}
@@ -202,4 +209,14 @@ public final class EntityConfig {
public List<Datasource> getDatasourceList() {
return this.datasourceList;
}
+
+ /** Returns the specified <code><datasource></code> child element or <code>null</code> if it does not exist. */
+ public Datasource getDatasource(String name) {
+ return this.datasourceMap.get(name);
+ }
+
+ /** Returns the <code><datasource></code> child elements as a <code>Map</code>. */
+ public Map<String, Datasource> getDatasourceMap() {
+ return this.datasourceMap;
+ }
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/ConnectionFactoryInterface.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/ConnectionFactoryInterface.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/ConnectionFactoryInterface.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/ConnectionFactoryInterface.java Fri Jun 7 08:39:44 2013
@@ -21,8 +21,8 @@ package org.ofbiz.entity.connection;
import java.sql.Connection;
import java.sql.SQLException;
-import org.w3c.dom.Element;
import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.config.model.JdbcElement;
import org.ofbiz.entity.datasource.GenericHelperInfo;
/**
@@ -30,6 +30,6 @@ import org.ofbiz.entity.datasource.Gener
*/
public interface ConnectionFactoryInterface {
- public Connection getConnection(GenericHelperInfo helperInfo, Element configElement) throws SQLException, GenericEntityException;
+ public Connection getConnection(GenericHelperInfo helperInfo, JdbcElement jdbcElement) throws SQLException, GenericEntityException;
public void closeAll();
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java Fri Jun 7 08:39:44 2013
@@ -38,11 +38,13 @@ import org.apache.commons.dbcp.managed.X
import org.apache.commons.pool.impl.GenericObjectPool;
import org.ofbiz.base.util.Debug;
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.InlineJdbc;
+import org.ofbiz.entity.config.model.JdbcElement;
import org.ofbiz.entity.datasource.GenericHelperInfo;
import org.ofbiz.entity.transaction.TransactionFactory;
-import org.w3c.dom.Element;
/**
* DBCPConnectionFactory
@@ -52,64 +54,31 @@ public class DBCPConnectionFactory imple
public static final String module = DBCPConnectionFactory.class.getName();
protected static final ConcurrentHashMap<String, ManagedDataSource> dsCache = new ConcurrentHashMap<String, ManagedDataSource>();
- public Connection getConnection(GenericHelperInfo helperInfo, Element jdbcElement) throws SQLException, GenericEntityException {
+ public Connection getConnection(GenericHelperInfo helperInfo, JdbcElement abstractJdbc) throws SQLException, GenericEntityException {
String cacheKey = helperInfo.getHelperFullName();
ManagedDataSource mds = dsCache.get(cacheKey);
if (mds != null) {
return TransactionFactory.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();
- String driverName = jdbcElement.getAttribute("jdbc-driver");
+ String driverName = jdbcElement.getJdbcDriver();
- String jdbcUri = UtilValidate.isNotEmpty(helperInfo.getOverrideJdbcUri()) ? helperInfo.getOverrideJdbcUri() : jdbcElement.getAttribute("jdbc-uri");
- String jdbcUsername = UtilValidate.isNotEmpty(helperInfo.getOverrideUsername()) ? helperInfo.getOverrideUsername() : jdbcElement.getAttribute("jdbc-username");
+ String jdbcUri = UtilValidate.isNotEmpty(helperInfo.getOverrideJdbcUri()) ? helperInfo.getOverrideJdbcUri() : jdbcElement.getJdbcUri();
+ String jdbcUsername = UtilValidate.isNotEmpty(helperInfo.getOverrideUsername()) ? helperInfo.getOverrideUsername() : jdbcElement.getJdbcUsername();
String jdbcPassword = UtilValidate.isNotEmpty(helperInfo.getOverridePassword()) ? helperInfo.getOverridePassword() : EntityConfigUtil.getJdbcPassword(jdbcElement);
// pool settings
- int maxSize, minSize, timeBetweenEvictionRunsMillis;
- try {
- maxSize = Integer.parseInt(jdbcElement.getAttribute("pool-maxsize"));
- } catch (NumberFormatException nfe) {
- Debug.logError("Problems with pool settings [pool-maxsize=" + jdbcElement.getAttribute("pool-maxsize") + "]; the values MUST be numbers, using default of 20.", module);
- maxSize = 20;
- } catch (Exception e) {
- Debug.logError("Problems with pool settings [pool-maxsize], using default of 20.", module);
- maxSize = 20;
- }
- try {
- minSize = Integer.parseInt(jdbcElement.getAttribute("pool-minsize"));
- } catch (NumberFormatException nfe) {
- Debug.logError("Problems with pool settings [pool-minsize=" + jdbcElement.getAttribute("pool-minsize") + "]; the values MUST be numbers, using default of 2.", module);
- minSize = 2;
- } catch (Exception e) {
- Debug.logError("Problems with pool settings [pool-minsize], using default of 2.", module);
- minSize = 2;
- }
- // idle-maxsize, default to half of pool-maxsize
- int maxIdle = maxSize / 2;
- if (jdbcElement.hasAttribute("idle-maxsize")) {
- try {
- maxIdle = Integer.parseInt(jdbcElement.getAttribute("idle-maxsize"));
- } catch (NumberFormatException nfe) {
- Debug.logError("Problems with pool settings [idle-maxsize=" + jdbcElement.getAttribute("idle-maxsize") + "]; the values MUST be numbers, using calculated default of" + (maxIdle > minSize ? maxIdle : minSize) + ".", module);
- } catch (Exception e) {
- Debug.logError("Problems with pool settings [idle-maxsize], using calculated default of" + (maxIdle > minSize ? maxIdle : minSize) + ".", module);
- }
- }
+ int maxSize = jdbcElement.getPoolMaxsize();
+ int minSize = jdbcElement.getPoolMinsize();
+ int timeBetweenEvictionRunsMillis = jdbcElement.getTimeBetweenEvictionRunsMillis();
+ int maxIdle = jdbcElement.getIdleMaxsize();
// Don't allow a maxIdle of less than pool-minsize
maxIdle = maxIdle > minSize ? maxIdle : minSize;
-
- try {
- timeBetweenEvictionRunsMillis = Integer.parseInt(jdbcElement.getAttribute("time-between-eviction-runs-millis"));
- } catch (NumberFormatException nfe) {
- Debug.logError("Problems with pool settings [time-between-eviction-runs-millis=" + jdbcElement.getAttribute("time-between-eviction-runs-millis") + "]; the values MUST be numbers, using default of 600000.", module);
- timeBetweenEvictionRunsMillis = 600000;
- } catch (Exception e) {
- Debug.logError("Problems with pool settings [time-between-eviction-runs-millis], using default of 600000.", module);
- timeBetweenEvictionRunsMillis = 600000;
- }
-
// load the driver
Driver jdbcDriver;
try {
@@ -144,7 +113,7 @@ public class DBCPConnectionFactory imple
factory.setValidationQuery("select 1 from entity_key_store where key_name = ''");
factory.setDefaultReadOnly(false);
- String transIso = jdbcElement.getAttribute("isolation-level");
+ String transIso = jdbcElement.getIsolationLevel();
if (UtilValidate.isNotEmpty(transIso)) {
if ("Serializable".equals(transIso)) {
factory.setDefaultTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
@@ -173,6 +142,7 @@ public class DBCPConnectionFactory imple
public void closeAll() {
// no methods on the pool to shutdown; so just clearing for GC
+ // Hmm... then how do we close the JDBC connections?
dsCache.clear();
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java Fri Jun 7 08:39:44 2013
@@ -43,6 +43,7 @@ import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.EntityLockedException;
import org.ofbiz.entity.GenericDataSourceException;
import org.ofbiz.entity.GenericEntity;
+import org.ofbiz.entity.GenericEntityConfException;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericEntityNotFoundException;
import org.ofbiz.entity.GenericModelException;
@@ -51,7 +52,7 @@ import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.condition.EntityConditionParam;
import org.ofbiz.entity.condition.EntityOperator;
-import org.ofbiz.entity.config.DatasourceInfo;
+import org.ofbiz.entity.config.model.*;
import org.ofbiz.entity.config.EntityConfigUtil;
import org.ofbiz.entity.jdbc.DatabaseUtil;
import org.ofbiz.entity.jdbc.SQLProcessor;
@@ -78,7 +79,7 @@ public class GenericDAO {
private static final ThreadGroup GENERIC_DAO_THREAD_GROUP = new ThreadGroup("GenericDAO");
private final GenericHelperInfo helperInfo;
private final ModelFieldTypeReader modelFieldTypeReader;
- private final DatasourceInfo datasourceInfo;
+ private final Datasource datasource;
private final ExecutorService executor;
public static GenericDAO getGenericDAO(GenericHelperInfo helperInfo) {
@@ -94,8 +95,8 @@ public class GenericDAO {
public GenericDAO(GenericHelperInfo helperInfo) {
this.helperInfo = helperInfo;
this.modelFieldTypeReader = ModelFieldTypeReader.getModelFieldTypeReader(helperInfo.getHelperBaseName());
- this.datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperInfo.getHelperBaseName());
- this.executor = ExecutionPool.getExecutor(GENERIC_DAO_THREAD_GROUP, "OFBiz-entity-datasource(" + helperInfo.getHelperFullName() + ")", datasourceInfo.maxWorkerPoolSize, false);
+ this.datasource = EntityConfigUtil.getDatasource(helperInfo.getHelperBaseName());
+ this.executor = ExecutionPool.getExecutor(GENERIC_DAO_THREAD_GROUP, "OFBiz-entity-datasource(" + helperInfo.getHelperFullName() + ")", datasource.getMaxWorkerPoolSize(), false);
}
public <T> Future<T> submitWork(Callable<T> callable) throws GenericEntityException {
@@ -170,7 +171,7 @@ public class GenericDAO {
}
}
- StringBuilder sqlB = new StringBuilder("INSERT INTO ").append(modelEntity.getTableName(datasourceInfo)).append(" (");
+ StringBuilder sqlB = new StringBuilder("INSERT INTO ").append(modelEntity.getTableName(datasource)).append(" (");
modelEntity.colNameString(fieldsToSave, sqlB, "");
sqlB.append(") VALUES (");
@@ -276,7 +277,7 @@ public class GenericDAO {
addFieldIfMissing(fieldsToSave, ModelEntity.STAMP_FIELD, modelEntity);
}
- StringBuilder sql = new StringBuilder().append("UPDATE ").append(modelEntity.getTableName(datasourceInfo)).append(" SET ");
+ StringBuilder sql = new StringBuilder().append("UPDATE ").append(modelEntity.getTableName(datasource)).append(" SET ");
modelEntity.colNameString(fieldsToSave, sql, "", "=?, ", "=?", false);
sql.append(" WHERE ");
SqlJdbcUtil.makeWhereStringFromFields(sql, modelEntity.getPkFieldsUnmodifiable(), entity, "AND");
@@ -321,7 +322,7 @@ public class GenericDAO {
throw new org.ofbiz.entity.GenericNotImplementedException("Operation updateByCondition not supported yet for view entities");
}
- StringBuilder sql = new StringBuilder("UPDATE ").append(modelEntity.getTableName(datasourceInfo));
+ StringBuilder sql = new StringBuilder("UPDATE ").append(modelEntity.getTableName(datasource));
sql.append(" SET ");
List<EntityConditionParam> params = new LinkedList<EntityConditionParam>();
for (Map.Entry<String, ? extends Object> entry: fieldsToSet.entrySet()) {
@@ -335,7 +336,7 @@ public class GenericDAO {
params.add(new EntityConditionParam(field, entry.getValue()));
}
}
- sql.append(" WHERE ").append(condition.makeWhereString(modelEntity, params, this.datasourceInfo));
+ sql.append(" WHERE ").append(condition.makeWhereString(modelEntity, params, this.datasource));
try {
sqlP.prepareStatement(sql.toString());
@@ -519,13 +520,13 @@ public class GenericDAO {
StringBuilder sqlBuffer = new StringBuilder("SELECT ");
if (modelEntity.getNopksSize() > 0) {
- modelEntity.colNameString(modelEntity.getNopksCopy(), sqlBuffer, "", ", ", "", datasourceInfo.aliasViews);
+ modelEntity.colNameString(modelEntity.getNopksCopy(), sqlBuffer, "", ", ", "", datasource.getAliasViewColumns());
} else {
sqlBuffer.append("*");
}
- sqlBuffer.append(SqlJdbcUtil.makeFromClause(modelEntity, modelFieldTypeReader, datasourceInfo));
- sqlBuffer.append(SqlJdbcUtil.makeWhereClause(modelEntity, modelEntity.getPkFieldsUnmodifiable(), entity, "AND", datasourceInfo.joinStyle));
+ sqlBuffer.append(SqlJdbcUtil.makeFromClause(modelEntity, modelFieldTypeReader, datasource));
+ sqlBuffer.append(SqlJdbcUtil.makeWhereClause(modelEntity, modelEntity.getPkFieldsUnmodifiable(), entity, "AND", datasource.getJoinStyle()));
try {
sqlP.prepareStatement(sqlBuffer.toString(), true, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
@@ -589,12 +590,12 @@ public class GenericDAO {
StringBuilder sqlBuffer = new StringBuilder("SELECT ");
if (partialFields.size() > 0) {
- modelEntity.colNameString(partialFields, sqlBuffer, "", ", ", "", datasourceInfo.aliasViews);
+ modelEntity.colNameString(partialFields, sqlBuffer, "", ", ", "", datasource.getAliasViewColumns());
} else {
sqlBuffer.append("*");
}
- sqlBuffer.append(SqlJdbcUtil.makeFromClause(modelEntity, modelFieldTypeReader, datasourceInfo));
- sqlBuffer.append(SqlJdbcUtil.makeWhereClause(modelEntity, modelEntity.getPkFieldsUnmodifiable(), entity, "AND", datasourceInfo.joinStyle));
+ sqlBuffer.append(SqlJdbcUtil.makeFromClause(modelEntity, modelFieldTypeReader, datasource));
+ sqlBuffer.append(SqlJdbcUtil.makeWhereClause(modelEntity, modelEntity.getPkFieldsUnmodifiable(), entity, "AND", datasource.getJoinStyle()));
SQLProcessor sqlP = new SQLProcessor(helperInfo);
@@ -718,15 +719,15 @@ public class GenericDAO {
if (modelEntity instanceof ModelViewEntity) {
// Views must have enumerated fields in SELECT.
if (selectFields.isEmpty()) {
- modelEntity.colNameString(modelEntity.getFieldsUnmodifiable(), sqlBuffer, "", ", ", "", datasourceInfo.aliasViews);
+ modelEntity.colNameString(modelEntity.getFieldsUnmodifiable(), sqlBuffer, "", ", ", "", datasource.getAliasViewColumns());
} else {
- modelEntity.colNameString(selectFields, sqlBuffer, "", ", ", "", datasourceInfo.aliasViews);
+ modelEntity.colNameString(selectFields, sqlBuffer, "", ", ", "", datasource.getAliasViewColumns());
}
} else {
if (selectFields.isEmpty()) {
sqlBuffer.append("*");
} else {
- modelEntity.colNameString(selectFields, sqlBuffer, "", ", ", "", datasourceInfo.aliasViews);
+ modelEntity.colNameString(selectFields, sqlBuffer, "", ", ", "", datasource.getAliasViewColumns());
}
}
if (selectFields.isEmpty()) {
@@ -746,7 +747,7 @@ public class GenericDAO {
}
// FROM clause and when necessary the JOIN or LEFT JOIN clause(s) as well
- sqlBuffer.append(SqlJdbcUtil.makeFromClause(modelEntity, modelFieldTypeReader, datasourceInfo));
+ sqlBuffer.append(SqlJdbcUtil.makeFromClause(modelEntity, modelFieldTypeReader, datasource));
// WHERE clause
List<EntityConditionParam> whereEntityConditionParams = new LinkedList<EntityConditionParam>();
@@ -771,7 +772,7 @@ public class GenericDAO {
// add to end of other order by so that those in method call will override those in view
orderByExpanded.addAll(viewOrderByList);
}
- sqlBuffer.append(SqlJdbcUtil.makeOrderByClause(modelEntity, orderByExpanded, datasourceInfo));
+ sqlBuffer.append(SqlJdbcUtil.makeOrderByClause(modelEntity, orderByExpanded, datasource));
// OFFSET clause
makeOffsetString(sqlBuffer, findOptions);
@@ -838,7 +839,7 @@ public class GenericDAO {
}
}
- String viewClause = SqlJdbcUtil.makeViewWhereClause(modelEntity, datasourceInfo.joinStyle);
+ String viewClause = SqlJdbcUtil.makeViewWhereClause(modelEntity, datasource.getJoinStyle());
if (viewClause.length() > 0) {
conditions.add(EntityCondition.makeConditionWhere(viewClause));
@@ -846,7 +847,7 @@ public class GenericDAO {
if (!conditions.isEmpty()) {
whereString.append(prefix);
- whereString.append(EntityCondition.makeCondition(conditions, EntityOperator.AND).makeWhereString(modelEntity, whereEntityConditionParams, this.datasourceInfo));
+ whereString.append(EntityCondition.makeCondition(conditions, EntityOperator.AND).makeWhereString(modelEntity, whereEntityConditionParams, this.datasource));
}
return whereString;
@@ -865,14 +866,14 @@ public class GenericDAO {
String entityCondHavingString = "";
if (havingEntityCondition != null) {
- entityCondHavingString = havingEntityCondition.makeWhereString(modelEntity, havingEntityConditionParams, this.datasourceInfo);
+ entityCondHavingString = havingEntityCondition.makeWhereString(modelEntity, havingEntityConditionParams, this.datasource);
}
String viewEntityCondHavingString = null;
if (modelViewEntity != null) {
EntityCondition viewHavingEntityCondition = EntityCondition.makeCondition(viewHavingConditions);
if (viewHavingEntityCondition != null) {
- viewEntityCondHavingString = viewHavingEntityCondition.makeWhereString(modelEntity, havingEntityConditionParams, this.datasourceInfo);
+ viewEntityCondHavingString = viewHavingEntityCondition.makeWhereString(modelEntity, havingEntityConditionParams, this.datasource);
}
}
@@ -898,8 +899,8 @@ public class GenericDAO {
}
protected StringBuilder makeOffsetString(StringBuilder offsetString, EntityFindOptions findOptions) {
- if (UtilValidate.isNotEmpty(datasourceInfo.offsetStyle)) {
- if (datasourceInfo.offsetStyle.equals("limit")) {
+ if (UtilValidate.isNotEmpty(datasource.getOffsetStyle())) {
+ if (datasource.getOffsetStyle().equals("limit")) {
// use the LIMIT/OFFSET style
if (findOptions.getLimit() > -1) {
offsetString.append(" LIMIT " + findOptions.getLimit());
@@ -907,7 +908,7 @@ public class GenericDAO {
offsetString.append(" OFFSET " + findOptions.getOffset());
}
}
- } else if (datasourceInfo.offsetStyle.equals("fetch")) {
+ } else if (datasource.getOffsetStyle().equals("fetch")) {
// use SQL2008 OFFSET/FETCH style by default
if (findOptions.getOffset() > -1) {
offsetString.append(" OFFSET ").append(findOptions.getOffset()).append(" ROWS");
@@ -925,8 +926,8 @@ public class GenericDAO {
SQLProcessor sqlP = new SQLProcessor(helperInfo);
// get the tables names
- String atable = modelEntityOne.getTableName(datasourceInfo);
- String ttable = modelEntityTwo.getTableName(datasourceInfo);
+ String atable = modelEntityOne.getTableName(datasource);
+ String ttable = modelEntityTwo.getTableName(datasource);
// get the column name string to select
StringBuilder selsb = new StringBuilder();
@@ -986,7 +987,7 @@ public class GenericDAO {
sqlsb.append(atable).append(", ").append(ttable);
sqlsb.append(" WHERE ");
sqlsb.append(wheresb.toString());
- sqlsb.append(SqlJdbcUtil.makeOrderByClause(modelEntityTwo, orderBy, true, datasourceInfo));
+ sqlsb.append(SqlJdbcUtil.makeOrderByClause(modelEntityTwo, orderBy, true, datasource));
// now execute the query
List<GenericValue> retlist = new LinkedList<GenericValue>();
@@ -1077,7 +1078,7 @@ public class GenericDAO {
sqlBuffer.append("COUNT(DISTINCT ");
// this only seems to support a single column, which is not desirable but seems a lot better than no columns or in certain cases all columns
sqlBuffer.append(firstSelectField.getColValue());
- // sqlBuffer.append(modelEntity.colNameString(selectFields, ", ", "", datasourceInfo.aliasViews));
+ // sqlBuffer.append(modelEntity.colNameString(selectFields, ", ", "", datasource.aliasViews));
sqlBuffer.append(")");
}
} else {
@@ -1100,7 +1101,7 @@ public class GenericDAO {
}
// FROM clause and when necessary the JOIN or LEFT JOIN clause(s) as well
- sqlBuffer.append(SqlJdbcUtil.makeFromClause(modelEntity, modelFieldTypeReader, datasourceInfo));
+ sqlBuffer.append(SqlJdbcUtil.makeFromClause(modelEntity, modelFieldTypeReader, datasource));
// WHERE clause
List<EntityConditionParam> whereEntityConditionParams = new LinkedList<EntityConditionParam>();
@@ -1185,7 +1186,7 @@ public class GenericDAO {
throw new org.ofbiz.entity.GenericNotImplementedException("Operation delete not supported yet for view entities");
}
- StringBuilder sql = new StringBuilder().append("DELETE FROM ").append(modelEntity.getTableName(datasourceInfo)).append(" WHERE ");
+ StringBuilder sql = new StringBuilder().append("DELETE FROM ").append(modelEntity.getTableName(datasource)).append(" WHERE ");
SqlJdbcUtil.makeWhereStringFromFields(sql, modelEntity.getPkFieldsUnmodifiable(), entity, "AND");
int retVal;
@@ -1221,9 +1222,9 @@ public class GenericDAO {
throw new org.ofbiz.entity.GenericNotImplementedException("Operation deleteByCondition not supported yet for view entities");
}
- StringBuilder sql = new StringBuilder("DELETE FROM ").append(modelEntity.getTableName(this.datasourceInfo));
+ StringBuilder sql = new StringBuilder("DELETE FROM ").append(modelEntity.getTableName(this.datasource));
- String whereCondition = condition.makeWhereString(modelEntity, null, this.datasourceInfo);
+ String whereCondition = condition.makeWhereString(modelEntity, null, this.datasource);
if (UtilValidate.isNotEmpty(whereCondition)) {
sql.append(" WHERE ").append(whereCondition);
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperFactory.java?rev=1490541&r1=1490540&r2=1490541&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperFactory.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperFactory.java Fri Jun 7 08:39:44 2013
@@ -23,7 +23,7 @@ import java.util.Map;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilValidate;
-import org.ofbiz.entity.config.DatasourceInfo;
+import org.ofbiz.entity.config.model.Datasource;
import org.ofbiz.entity.config.EntityConfigUtil;
/**
@@ -46,12 +46,12 @@ public class GenericHelperFactory {
helper = helperCache.get(helperInfo.getHelperFullName());
if (helper == null) {
try {
- DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperInfo.getHelperBaseName());
+ Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperInfo.getHelperBaseName());
if (datasourceInfo == null) {
throw new IllegalStateException("Could not find datasource definition with name " + helperInfo.getHelperBaseName());
}
- String helperClassName = datasourceInfo.helperClass;
+ String helperClassName = datasourceInfo.getHelperClass();
Class<?> helperClass = null;
if (UtilValidate.isNotEmpty(helperClassName)) {