svn commit: r949614 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: datasource/GenericDAO.java jdbc/DatabaseUtil.java jdbc/SqlJdbcUtil.java model/ModelEntity.java model/ModelViewEntity.java

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

svn commit: r949614 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: datasource/GenericDAO.java jdbc/DatabaseUtil.java jdbc/SqlJdbcUtil.java model/ModelEntity.java model/ModelViewEntity.java

doogie-3
Author: doogie
Date: Sun May 30 22:07:36 2010
New Revision: 949614

URL: http://svn.apache.org/viewvc?rev=949614&view=rev
Log:
Add new variants of colNameString 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/DatabaseUtil.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/ModelViewEntity.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=949614&r1=949613&r2=949614&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:36 2010
@@ -159,8 +159,12 @@ public class GenericDAO {
             }
         }
 
-        String sql = "INSERT INTO " + modelEntity.getTableName(datasourceInfo) + " (" + modelEntity.colNameString(fieldsToSave) + ") VALUES (" +
-            modelEntity.fieldsStringList(fieldsToSave, "?", ", ") + ")";
+        StringBuilder sqlB = new StringBuilder("INSERT INTO ").append(modelEntity.getTableName(datasourceInfo)).append(" (");
+
+        modelEntity.colNameString(fieldsToSave, sqlB, "");
+        sqlB.append(") VALUES (");
+        sqlB.append(modelEntity.fieldsStringList(fieldsToSave, "?", ", "));
+        String sql = sqlB.append(")").toString();
 
         try {
             sqlP.prepareStatement(sql);
@@ -261,13 +265,15 @@ public class GenericDAO {
             addFieldIfMissing(fieldsToSave, ModelEntity.STAMP_FIELD, modelEntity);
         }
 
-        String sql = "UPDATE " + modelEntity.getTableName(datasourceInfo) + " SET " + modelEntity.colNameString(fieldsToSave, "=?, ", "=?", false) + " WHERE " +
-            SqlJdbcUtil.makeWhereStringFromFields(modelEntity.getPkFieldsUnmodifiable(), entity, "AND");
+        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"));
 
         int retVal = 0;
 
         try {
-            sqlP.prepareStatement(sql);
+            sqlP.prepareStatement(sql.toString());
             SqlJdbcUtil.setValues(sqlP, fieldsToSave, entity, modelFieldTypeReader);
             SqlJdbcUtil.setPkValues(sqlP, modelEntity, entity, modelFieldTypeReader);
             retVal = sqlP.executeUpdate();
@@ -505,7 +511,7 @@ public class GenericDAO {
         StringBuilder sqlBuffer = new StringBuilder("SELECT ");
 
         if (modelEntity.getNopksSize() > 0) {
-            sqlBuffer.append(modelEntity.colNameString(modelEntity.getNopksCopy(), ", ", "", datasourceInfo.aliasViews));
+            modelEntity.colNameString(modelEntity.getNopksCopy(), sqlBuffer, "", ", ", "", datasourceInfo.aliasViews);
         } else {
             sqlBuffer.append("*");
         }
@@ -575,7 +581,7 @@ public class GenericDAO {
         StringBuilder sqlBuffer = new StringBuilder("SELECT ");
 
         if (partialFields.size() > 0) {
-            sqlBuffer.append(modelEntity.colNameString(partialFields, ", ", "", datasourceInfo.aliasViews));
+            modelEntity.colNameString(partialFields, sqlBuffer, "", ", ", "", datasourceInfo.aliasViews);
         } else {
             sqlBuffer.append("*");
         }
@@ -668,7 +674,7 @@ public class GenericDAO {
         }
 
         if (selectFields.size() > 0) {
-            sqlBuffer.append(modelEntity.colNameString(selectFields, ", ", "", datasourceInfo.aliasViews));
+            modelEntity.colNameString(selectFields, sqlBuffer, "", ", ", "", datasourceInfo.aliasViews);
         } else {
             sqlBuffer.append("*");
         }
@@ -697,12 +703,7 @@ public class GenericDAO {
 
         // 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);
-            }
+            modelViewEntity.colNameString(modelViewEntity.getGroupBysCopy(selectFields), sqlBuffer, " GROUP BY ", ", ", "", false);
         }
 
         // HAVING clause
@@ -1047,8 +1048,7 @@ public class GenericDAO {
 
         // GROUP BY clause for view-entity
         if (isGroupBy) {
-            sqlBuffer.append(" GROUP BY ");
-            sqlBuffer.append(modelViewEntity.colNameString(modelViewEntity.getGroupBysCopy(), ", ", "", false));
+            modelViewEntity.colNameString(modelViewEntity.getGroupBysCopy(), sqlBuffer, " GROUP BY ", ", ", "", false);
         }
 
         // HAVING clause

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java?rev=949614&r1=949613&r2=949614&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java Sun May 30 22:07:36 2010
@@ -1764,7 +1764,7 @@ public class DatabaseUtil {
             sqlBuf.append(pkName);
         }
         sqlBuf.append(" PRIMARY KEY (");
-        sqlBuf.append(entity.colNameString(entity.getPkFieldsUnmodifiable()));
+        entity.colNameString(entity.getPkFieldsUnmodifiable(), sqlBuf, "");
         sqlBuf.append(")");
 
         if (addFks) {
@@ -2596,7 +2596,7 @@ public class DatabaseUtil {
                 sqlBuf.append(pkName);
             }
             sqlBuf.append(" PRIMARY KEY (");
-            sqlBuf.append(entity.colNameString(entity.getPkFieldsUnmodifiable()));
+            entity.colNameString(entity.getPkFieldsUnmodifiable(), sqlBuf, "");
             sqlBuf.append(")");
 
             if (Debug.verboseOn()) Debug.logVerbose("[createPrimaryKey] sql=" + sqlBuf.toString(), module);

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java?rev=949614&r1=949613&r2=949614&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:36 2010
@@ -409,11 +409,7 @@ public class SqlJdbcUtil {
                 sql.append(viewWhereClause);
             }
             ModelViewEntity modelViewEntity = (ModelViewEntity)modelEntity;
-            String groupByString = modelViewEntity.colNameString(modelViewEntity.getGroupBysCopy(), ", ", "", false);
-            if (UtilValidate.isNotEmpty(groupByString)) {
-                sql.append(" GROUP BY ");
-                sql.append(groupByString);
-            }
+            modelViewEntity.colNameString(modelViewEntity.getGroupBysCopy(), sql, " GROUP BY ", ", ", "", false);
 
             sql.append(")");
             return sql.toString();

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java?rev=949614&r1=949613&r2=949614&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java Sun May 30 22:07:36 2010
@@ -885,36 +885,55 @@ public class ModelEntity extends ModelIn
         return returnString.toString();
     }
 
+    @Deprecated
     public String colNameString(ModelField... flds) {
-        return colNameString(Arrays.asList(flds));
+        return colNameString(new StringBuilder(), "", flds).toString();
     }
 
+    public StringBuilder colNameString(StringBuilder sb, String prefix,  ModelField... flds) {
+        return colNameString(Arrays.asList(flds), sb, prefix);
+    }
+
+    @Deprecated
     public String colNameString(List<ModelField> flds) {
-        return colNameString(flds, ", ", "", false);
+        return colNameString(flds, new StringBuilder(), "", ", ", "", false).toString();
+    }
+
+    public StringBuilder colNameString(List<ModelField> flds, StringBuilder sb, String prefix) {
+        return colNameString(flds, sb, prefix, ", ", "", false);
     }
 
+    @Deprecated
     public String colNameString(String separator, String afterLast, boolean alias, ModelField... flds) {
-        return colNameString(Arrays.asList(flds), separator, afterLast, alias);
+        return colNameString(Arrays.asList(flds), new StringBuilder(), "", separator, afterLast, alias).toString();
+    }
+
+    public StringBuilder colNameString(StringBuilder sb, String prefix, String separator, String afterLast, boolean alias, ModelField... flds) {
+        return colNameString(Arrays.asList(flds), sb, prefix, separator, afterLast, alias);
     }
 
+    @Deprecated
     public String colNameString(List<ModelField> flds, String separator, String afterLast, boolean alias) {
-        StringBuilder returnString = new StringBuilder();
+        return colNameString(flds, new StringBuilder(), "", separator, afterLast, alias).toString();
+    }
 
+    public StringBuilder colNameString(List<ModelField> flds, StringBuilder sb, String prefix, String separator, String afterLast, boolean alias) {
         if (flds.size() < 1) {
-            return "";
+            return sb;
         }
 
+        sb.append(prefix);
         Iterator<ModelField> fldsIt = flds.iterator();
         while (fldsIt.hasNext()) {
             ModelField field = fldsIt.next();
-            returnString.append(field.colName);
+            sb.append(field.colName);
             if (fldsIt.hasNext()) {
-                returnString.append(separator);
+                sb.append(separator);
             }
         }
 
-        returnString.append(afterLast);
-        return returnString.toString();
+        sb.append(afterLast);
+        return sb;
     }
 
     public String classNameString(ModelField... flds) {

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java?rev=949614&r1=949613&r2=949614&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java Sun May 30 22:07:36 2010
@@ -327,36 +327,45 @@ public class ModelViewEntity extends Mod
         }
     }
 
-    @Override
+    @Deprecated @Override
     public String colNameString(String separator, String afterLast, boolean alias, ModelField... flds) {
         return colNameString(Arrays.asList(flds), separator, afterLast, alias);
     }
 
     @Override
+    public StringBuilder colNameString(StringBuilder sb, String prefix, String separator, String afterLast, boolean alias, ModelField... flds) {
+        return colNameString(Arrays.asList(flds), sb, prefix, separator, afterLast, alias);
+    }
+
+    @Deprecated @Override
     public String colNameString(List<ModelField> flds, String separator, String afterLast, boolean alias) {
-        StringBuilder returnString = new StringBuilder();
+        return colNameString(flds, new StringBuilder(), "", separator, afterLast, alias).toString();
+    }
 
+    @Override
+    public StringBuilder colNameString(List<ModelField> flds, StringBuilder sb, String prefix, String separator, String afterLast, boolean alias) {
         if (flds.size() < 1) {
-            return "";
+            return sb;
         }
 
+        sb.append(prefix);
         Iterator<ModelField> fldsIt = flds.iterator();
         while (fldsIt.hasNext()) {
             ModelField field = fldsIt.next();
-            returnString.append(field.getColValue());
+            sb.append(field.getColValue());
             if (alias) {
                 ModelAlias modelAlias = this.getAlias(field.name);
                 if (modelAlias != null) {
-                    returnString.append(" AS ").append(modelAlias.getColAlias());
+                    sb.append(" AS ").append(modelAlias.getColAlias());
                 }
             }
             if (fldsIt.hasNext()) {
-                returnString.append(separator);
+                sb.append(separator);
             }
         }
 
-        returnString.append(afterLast);
-        return returnString.toString();
+        sb.append(afterLast);
+        return sb;
     }
 
     protected ModelEntity aliasedModelEntity = new ModelEntity();