You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2010/05/26 16:22:34 UTC
svn commit: r948442 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity:
jdbc/SqlJdbcUtil.java model/ModelField.java model/ModelViewEntity.java
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() + ")";
}
}
}
Re: svn commit: r948442 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity:
jdbc/SqlJdbcUtil.java model/ModelField.java model/ModelViewEntity.java
Posted by Adam Heath <do...@brainfood.com>.
doogie@apache.org wrote:
> 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.
This bug would end up producing sql like the following:
SELECT .... FROM (( INNER JOIN (SELECT ...
(COALESCE(P.FIRST_NAME,' ') || COALESCE(P.MIDDLE_NAME,' ') ||
COALESCE(P.LAST_NAME,' ')) AS _COALESCE_P_FIRST_NAME,' '_ ||
COALESCE_P_MIDDLE_NAME,' '_ || COALESCE_P_LAST_NAME,' '__ ...
Yes, that's correct. It would take the column value, and then replace
certain punctuation with _. The above sql is very obviously extremely
broken.
<view-entity entity-name="PersonNameSearch">
<member-entity entity-alias="P" entity-name="Person"/>
<alias entity-alias="P" name="partyId"/>
<alias name="fullName">
<complex-alias operator="|| ' ' ||">
<complex-alias-field entity-alias="P" field="firstName"
default-value="''"/>
<complex-alias-field entity-alias="P" field="middleName"
default-value="''"/>
<complex-alias-field entity-alias="P" field="lastName"
default-value="''"/>
</complex-alias>
</alias>
</view-entity>
<view-entity entity-name="ProductAndPerson">
<member-entity entity-alias="PR" entity-name="Product"/>
<member-entity entity-alias="PRL" entity-name="ProductRole"/>
<member-entity entity-alias="PNS" entity-name="PersonNameSearch"/>
<alias entity-alias="PNS" name="fullName"/>
<!-- add appropriate view-link here, should be obvious -->
</view-entity>
>
> 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() + ")";
> }
> }
> }
>
>