svn commit: r949616 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: datasource/GenericDAO.java jdbc/SqlJdbcUtil.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r949616 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: datasource/GenericDAO.java jdbc/SqlJdbcUtil.java

doogie-3
Author: doogie
Date: Sun May 30 22:07:50 2010
New Revision: 949616

URL: http://svn.apache.org/viewvc?rev=949616&view=rev
Log:
Add new variants of makeWhereStringFromFields that take a StringBuilder, and deprecate the old versions that don't.

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.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=949616&r1=949615&r2=949616&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 Sun May 30 22:07:50 2010
@@ -268,7 +268,7 @@ public class GenericDAO {
         StringBuilder sql = new StringBuilder().append("UPDATE ").append(modelEntity.getTableName(datasourceInfo)).append(" SET ");
         modelEntity.colNameString(fieldsToSave, sql, "", "=?, ", "=?", false);
         sql.append(" WHERE ");
-        sql.append(SqlJdbcUtil.makeWhereStringFromFields(modelEntity.getPkFieldsUnmodifiable(), entity, "AND"));
+        SqlJdbcUtil.makeWhereStringFromFields(sql, modelEntity.getPkFieldsUnmodifiable(), entity, "AND");
 
         int retVal = 0;
 
@@ -1129,12 +1129,13 @@ public class GenericDAO {
             throw new org.ofbiz.entity.GenericNotImplementedException("Operation delete not supported yet for view entities");
         }
 
-        String sql = "DELETE FROM " + modelEntity.getTableName(datasourceInfo) + " WHERE " + SqlJdbcUtil.makeWhereStringFromFields(modelEntity.getPkFieldsUnmodifiable(), entity, "AND");
+        StringBuilder sql = new StringBuilder().append("DELETE FROM ").append(modelEntity.getTableName(datasourceInfo)).append(" WHERE ");
+        SqlJdbcUtil.makeWhereStringFromFields(sql, modelEntity.getPkFieldsUnmodifiable(), entity, "AND");
 
         int retVal;
 
         try {
-            sqlP.prepareStatement(sql);
+            sqlP.prepareStatement(sql.toString());
             SqlJdbcUtil.setPkValues(sqlP, modelEntity, entity, modelFieldTypeReader);
             retVal = sqlP.executeUpdate();
             entity.removedFromDatasource();

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=949616&r1=949615&r2=949616&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 Sun May 30 22:07:50 2010
@@ -231,17 +231,27 @@ public class SqlJdbcUtil {
     }
 
     /** Makes a WHERE clause String with "<col name>=?" if not null or "<col name> IS null" if null, all AND separated */
+    @Deprecated
     public static String makeWhereStringFromFields(List<ModelField> modelFields, Map<String, Object> fields, String operator) {
-        return makeWhereStringFromFields(modelFields, fields, operator, null);
+        return makeWhereStringFromFields(new StringBuilder(), modelFields, fields, operator, null).toString();
+    }
+
+    public static StringBuilder makeWhereStringFromFields(StringBuilder sb, List<ModelField> modelFields, Map<String, Object> fields, String operator) {
+        return makeWhereStringFromFields(sb, modelFields, fields, operator, null);
     }
 
     /** Makes a WHERE clause String with "<col name>=?" if not null or "<col name> IS null" if null, all AND separated */
+    @Deprecated
     public static String makeWhereStringFromFields(List<ModelField> modelFields, Map<String, Object> fields, String operator, List<EntityConditionParam> entityConditionParams) {
+        return makeWhereStringFromFields(new StringBuilder(), modelFields, fields, operator, entityConditionParams).toString();
+    }
+
+    /** Makes a WHERE clause String with "<col name>=?" if not null or "<col name> IS null" if null, all AND separated */
+    public static StringBuilder makeWhereStringFromFields(StringBuilder sb, List<ModelField> modelFields, Map<String, Object> fields, String operator, List<EntityConditionParam> entityConditionParams) {
         if (modelFields.size() < 1) {
-            return "";
+            return sb;
         }
 
-        StringBuilder returnString = new StringBuilder();
         Iterator<ModelField> iter = modelFields.iterator();
         while (iter.hasNext()) {
             Object item = iter.next();
@@ -249,29 +259,29 @@ public class SqlJdbcUtil {
             ModelField modelField = null;
             if (item instanceof ModelField) {
                 modelField = (ModelField) item;
-                returnString.append(modelField.getColName());
+                sb.append(modelField.getColName());
                 name = modelField.getName();
             } else {
-                returnString.append(item);
+                sb.append(item);
                 name = item;
             }
 
             Object fieldValue = fields.get(name);
             if (fieldValue != null && fieldValue != GenericEntity.NULL_FIELD) {
-                returnString.append('=');
-                addValue(returnString, modelField, fieldValue, entityConditionParams);
+                sb.append('=');
+                addValue(sb, modelField, fieldValue, entityConditionParams);
             } else {
-                returnString.append(" IS NULL");
+                sb.append(" IS NULL");
             }
 
             if (iter.hasNext()) {
-                returnString.append(' ');
-                returnString.append(operator);
-                returnString.append(' ');
+                sb.append(' ');
+                sb.append(operator);
+                sb.append(' ');
             }
         }
 
-        return returnString.toString();
+        return sb;
     }
 
     public static String makeWhereClause(ModelEntity modelEntity, List<ModelField> modelFields, Map<String, Object> fields, String operator, String joinStyle) throws GenericEntityException {