|
Author: doogie
Date: Wed May 26 14:22:34 2010 New Revision: 948442 URL: http://svn.apache.org/viewvc?rev=948442&view=rev Log: Fix view entities that have view entities as members, with complex aliases, or functions on the nested view. Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java 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=948442&r1=948441&r2=948442&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 Wed May 26 14:22:34 2010 @@ -391,17 +391,15 @@ public class SqlJdbcUtil { Iterator<ModelField> fieldsIter = modelEntity.getFieldsIterator(); if (fieldsIter.hasNext()) { ModelField curField = fieldsIter.next(); - String colname = curField.getColName(); - sql.append(colname); + sql.append(curField.getColValue()); sql.append(" AS "); - sql.append(filterColName(colname)); + sql.append(filterColName(curField.getColName())); while (fieldsIter.hasNext()) { curField = fieldsIter.next(); - colname = curField.getColName(); sql.append(", "); - sql.append(colname); + sql.append(curField.getColValue()); sql.append(" AS "); - sql.append(filterColName(colname)); + sql.append(filterColName(curField.getColName())); } } sql.append(makeFromClause(modelEntity, datasourceInfo)); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java?rev=948442&r1=948441&r2=948442&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java Wed May 26 14:22:34 2010 @@ -45,6 +45,8 @@ public class ModelField extends ModelChi /** The col-name of the Field */ protected String colName = ""; + protected String colValue; + /** boolean which specifies whether or not the Field is a Primary Key */ protected boolean isPk = false; protected boolean encrypt = false; @@ -133,6 +135,14 @@ public class ModelField extends ModelChi } } + public String getColValue() { + return UtilValidate.isEmpty(this.colValue) ? this.colName : this.colValue; + } + + public void setColValue(String colValue) { + this.colValue = colValue; + } + /** boolean which specifies whether or not the Field is a Primary Key */ public boolean getIsPk() { return this.isPk; 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=948442&r1=948441&r2=948442&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 Wed May 26 14:22:34 2010 @@ -343,7 +343,7 @@ public class ModelViewEntity extends Mod Iterator<ModelField> fldsIt = flds.iterator(); while (fldsIt.hasNext()) { ModelField field = fldsIt.next(); - returnString.append(field.colName); + returnString.append(field.getColValue()); if (alias) { ModelAlias modelAlias = this.getAlias(field.name); if (modelAlias != null) { @@ -449,7 +449,8 @@ public class ModelViewEntity extends Mod StringBuilder colNameBuffer = new StringBuilder(); StringBuilder fieldTypeBuffer = new StringBuilder(); alias.makeAliasColName(colNameBuffer, fieldTypeBuffer, this, modelReader); - field.colName = colNameBuffer.toString(); + field.colValue = colNameBuffer.toString(); + field.colName = ModelUtil.javaNameToDbName(alias.name); field.type = fieldTypeBuffer.toString(); field.isPk = false; } else { @@ -495,7 +496,7 @@ public class ModelViewEntity extends Mod if (prefix == null) { Debug.logWarning("Specified alias function [" + alias.function + "] not valid; must be: min, max, sum, avg, count or count-distinct; using a column name with no function function", module); } else { - field.colName = prefix + field.colName + ")"; + field.colValue = prefix + field.getColValue() + ")"; } } } |
| Free forum by Nabble | Edit this page |
