Author: jonesde
Date: Fri Jul 3 05:30:18 2009
New Revision: 790793
URL: http://svn.apache.org/viewvc?rev=790793&view=rev
Log:
Small refactoring, changed so select count uses new entity-condition stuff
under the view-entity
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
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=790793&r1=790792&r2=790793&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 Jul 3 05:30:18 2009
@@ -675,6 +675,88 @@
// WHERE clause
List<EntityConditionParam> whereEntityConditionParams =
FastList.newInstance();
+ StringBuilder whereString = makeConditionWhereString(modelEntity,
whereEntityCondition, whereEntityConditionParams);
+ if (whereString.length() > 0) {
+ sqlBuffer.append(" WHERE ");
+ sqlBuffer.append(whereString.toString());
+ }
+
+ // GROUP BY clause for view-entity
+ if (modelViewEntity != null) {
+ String groupByString =
modelViewEntity.colNameString(modelViewEntity.getGroupBysCopy(selectFields), ",
", "", false);
+
+ if (UtilValidate.isNotEmpty(groupByString)) {
+ sqlBuffer.append(" GROUP BY ");
+ sqlBuffer.append(groupByString);
+ }
+ }
+
+ // HAVING clause
+ List<EntityConditionParam> havingEntityConditionParams =
FastList.newInstance();
+ StringBuilder havingString = makeConditionHavingString(modelEntity,
havingEntityCondition, havingEntityConditionParams);
+ if (havingString.length() > 0) {
+ sqlBuffer.append(" HAVING ");
+ sqlBuffer.append(havingString);
+ }
+
+ // ORDER BY clause
+ List<String> orderByExpanded = FastList.<String>newInstance();
+ // add the manually specified ones, then the ones in the view entity's
entity-condition
+ if (orderBy != null) {
+ orderByExpanded.addAll(orderBy);
+ }
+ if (modelViewEntity != null && modelViewEntity.getByConditionFinder()
!= null) {
+ List<String> viewOrderBy =
modelViewEntity.getByConditionFinder().getOrderByFieldList(FastMap.<String,
Object>newInstance());
+ if (viewOrderBy != null && viewOrderBy.size() > 0) {
+ orderByExpanded.addAll(viewOrderBy);
+ }
+ }
+ sqlBuffer.append(SqlJdbcUtil.makeOrderByClause(modelEntity,
orderByExpanded, datasourceInfo));
+
+ // make the final SQL String
+ String sql = sqlBuffer.toString();
+
+ SQLProcessor sqlP = new SQLProcessor(helperName);
+ sqlP.prepareStatement(sql, findOptions.getSpecifyTypeAndConcur(),
findOptions.getResultSetType(),
+ findOptions.getResultSetConcurrency(),
findOptions.getFetchSize(), findOptions.getMaxRows());
+
+ if (verboseOn) {
+ // put this inside an if statement so that we don't have to
generate the string when not used...
+ Debug.logVerbose("Setting the whereEntityConditionParams: " +
whereEntityConditionParams, module);
+ }
+ // set all of the values from the Where EntityCondition
+ for (EntityConditionParam whereEntityConditionParam:
whereEntityConditionParams) {
+ SqlJdbcUtil.setValue(sqlP,
whereEntityConditionParam.getModelField(), modelEntity.getEntityName(),
whereEntityConditionParam.getFieldValue(), modelFieldTypeReader);
+ }
+ if (verboseOn) {
+ // put this inside an if statement so that we don't have to
generate the string when not used...
+ Debug.logVerbose("Setting the havingEntityConditionParams: " +
havingEntityConditionParams, module);
+ }
+ // set all of the values from the Having EntityCondition
+ for (EntityConditionParam havingEntityConditionParam:
havingEntityConditionParams) {
+ SqlJdbcUtil.setValue(sqlP,
havingEntityConditionParam.getModelField(), modelEntity.getEntityName(),
havingEntityConditionParam.getFieldValue(), modelFieldTypeReader);
+ }
+
+ long queryStartTime = 0;
+ if (Debug.timingOn()) {
+ queryStartTime = System.currentTimeMillis();
+ }
+ sqlP.executeQuery();
+ if (Debug.timingOn()) {
+ long queryEndTime = System.currentTimeMillis();
+ long queryTotalTime = queryEndTime - queryStartTime;
+ if (queryTotalTime > 150) {
+ Debug.logTiming("Ran query in " + queryTotalTime + "
milli-seconds: " + sql, module);
+ }
+ }
+ return new EntityListIterator(sqlP, modelEntity, selectFields,
modelFieldTypeReader);
+ }
+
+ protected StringBuilder makeConditionWhereString(ModelEntity modelEntity,
EntityCondition whereEntityCondition, List<EntityConditionParam>
whereEntityConditionParams) throws GenericEntityException {
+ ModelViewEntity modelViewEntity = null;
+ if (modelEntity instanceof ModelViewEntity) {
+ modelViewEntity = (ModelViewEntity) modelEntity;
+ }
String entityCondWhereString = "";
if (whereEntityCondition != null) {
@@ -717,25 +799,17 @@
whereString.append(viewClause);
if (addParens) whereString.append(")");
}
-
- if (whereString.length() > 0) {
- sqlBuffer.append(" WHERE ");
- sqlBuffer.append(whereString.toString());
- }
-
- // GROUP BY clause for view-entity
- if (modelViewEntity != null) {
- String groupByString =
modelViewEntity.colNameString(modelViewEntity.getGroupBysCopy(selectFields), ",
", "", false);
-
- if (UtilValidate.isNotEmpty(groupByString)) {
- sqlBuffer.append(" GROUP BY ");
- sqlBuffer.append(groupByString);
- }
+
+ return whereString;
+ }
+
+ protected StringBuilder makeConditionHavingString(ModelEntity modelEntity,
EntityCondition havingEntityCondition, List<EntityConditionParam>
havingEntityConditionParams) throws GenericEntityException {
+ ModelViewEntity modelViewEntity = null;
+ if (modelEntity instanceof ModelViewEntity) {
+ modelViewEntity = (ModelViewEntity) modelEntity;
}
-
- // HAVING clause
+
String entityCondHavingString = "";
- List<EntityConditionParam> havingEntityConditionParams =
FastList.newInstance();
if (havingEntityCondition != null) {
entityCondHavingString =
havingEntityCondition.makeWhereString(modelEntity, havingEntityConditionParams,
this.datasourceInfo);
}
@@ -765,62 +839,7 @@
if (addParens) havingString.append(")");
}
- if (havingString.length() > 0) {
- sqlBuffer.append(" HAVING ");
- sqlBuffer.append(havingString);
- }
-
- // ORDER BY clause
- List<String> orderByExpanded = FastList.<String>newInstance();
- // add the manually specified ones, then the ones in the view entity's
entity-condition
- if (orderBy != null) {
- orderByExpanded.addAll(orderBy);
- }
- if (modelViewEntity != null && modelViewEntity.getByConditionFinder()
!= null) {
- List<String> viewOrderBy =
modelViewEntity.getByConditionFinder().getOrderByFieldList(FastMap.<String,
Object>newInstance());
- if (viewOrderBy != null && viewOrderBy.size() > 0) {
- orderByExpanded.addAll(viewOrderBy);
- }
- }
- sqlBuffer.append(SqlJdbcUtil.makeOrderByClause(modelEntity,
orderByExpanded, datasourceInfo));
-
- // make the final SQL String
- String sql = sqlBuffer.toString();
-
- SQLProcessor sqlP = new SQLProcessor(helperName);
- sqlP.prepareStatement(sql, findOptions.getSpecifyTypeAndConcur(),
findOptions.getResultSetType(),
- findOptions.getResultSetConcurrency(),
findOptions.getFetchSize(), findOptions.getMaxRows());
-
- if (verboseOn) {
- // put this inside an if statement so that we don't have to
generate the string when not used...
- Debug.logVerbose("Setting the whereEntityConditionParams: " +
whereEntityConditionParams, module);
- }
- // set all of the values from the Where EntityCondition
- for (EntityConditionParam whereEntityConditionParam:
whereEntityConditionParams) {
- SqlJdbcUtil.setValue(sqlP,
whereEntityConditionParam.getModelField(), modelEntity.getEntityName(),
whereEntityConditionParam.getFieldValue(), modelFieldTypeReader);
- }
- if (verboseOn) {
- // put this inside an if statement so that we don't have to
generate the string when not used...
- Debug.logVerbose("Setting the havingEntityConditionParams: " +
havingEntityConditionParams, module);
- }
- // set all of the values from the Having EntityCondition
- for (EntityConditionParam havingEntityConditionParam:
havingEntityConditionParams) {
- SqlJdbcUtil.setValue(sqlP,
havingEntityConditionParam.getModelField(), modelEntity.getEntityName(),
havingEntityConditionParam.getFieldValue(), modelFieldTypeReader);
- }
-
- long queryStartTime = 0;
- if (Debug.timingOn()) {
- queryStartTime = System.currentTimeMillis();
- }
- sqlP.executeQuery();
- if (Debug.timingOn()) {
- long queryEndTime = System.currentTimeMillis();
- long queryTotalTime = queryEndTime - queryStartTime;
- //if (queryTotalTime > 150) {
- Debug.logTiming("Ran query in " + queryTotalTime + "
milli-seconds: " + sql, module);
- //}
- }
- return new EntityListIterator(sqlP, modelEntity, selectFields,
modelFieldTypeReader);
+ return havingString;
}
public List<GenericValue> selectByMultiRelation(GenericValue value,
ModelRelation modelRelationOne, ModelEntity modelEntityOne,
@@ -982,27 +1001,8 @@
sqlBuffer.append(SqlJdbcUtil.makeFromClause(modelEntity,
datasourceInfo));
// WHERE clause
- StringBuilder whereString = new StringBuilder();
- String entityCondWhereString = "";
List<EntityConditionParam> whereEntityConditionParams =
FastList.newInstance();
- if (whereEntityCondition != null) {
- entityCondWhereString =
whereEntityCondition.makeWhereString(modelEntity, whereEntityConditionParams,
this.datasourceInfo);
- }
-
- String viewClause = SqlJdbcUtil.makeViewWhereClause(modelEntity,
datasourceInfo.joinStyle);
-
- if (viewClause.length() > 0) {
- if (entityCondWhereString.length() > 0) {
- whereString.append("(");
- whereString.append(entityCondWhereString);
- whereString.append(") AND ");
- }
-
- whereString.append(viewClause);
- } else {
- whereString.append(entityCondWhereString);
- }
-
+ StringBuilder whereString = makeConditionWhereString(modelEntity,
whereEntityCondition, whereEntityConditionParams);
if (whereString.length() > 0) {
sqlBuffer.append(" WHERE ");
sqlBuffer.append(whereString.toString());
@@ -1017,14 +1017,11 @@
}
// HAVING clause
- String entityCondHavingString = "";
List<EntityConditionParam> havingEntityConditionParams =
FastList.newInstance();
- if (havingEntityCondition != null) {
- entityCondHavingString =
havingEntityCondition.makeWhereString(modelEntity, havingEntityConditionParams,
this.datasourceInfo);
- }
- if (entityCondHavingString.length() > 0) {
+ StringBuilder havingString = makeConditionHavingString(modelEntity,
havingEntityCondition, havingEntityConditionParams);
+ if (havingString.length() > 0) {
sqlBuffer.append(" HAVING ");
- sqlBuffer.append(entityCondHavingString);
+ sqlBuffer.append(havingString);
}
if (isGroupBy) {