Author: doogie
Date: Sun May 30 22:07:04 2010
New Revision: 949608
URL: http://svn.apache.org/viewvc?rev=949608&view=rev
Log:
Allow fieldAlls, fieldDefs, and relations to be null; if they are empty,
then force them to null instead.
Modified:
ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Atom.java
ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLSelect.java
Modified: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Atom.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Atom.java?rev=949608&r1=949607&r2=949608&view=diff
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Atom.java (original)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Atom.java Sun May 30 22:07:04
2010
@@ -18,14 +18,26 @@
*/
package org.ofbiz.sql;
+import java.util.Collection;
+import java.util.Map;
+
import org.ofbiz.base.lang.Appender;
import org.ofbiz.base.util.UtilObject;
+import org.ofbiz.base.util.UtilValidate;
public abstract class Atom implements Appender<StringBuilder> {
public static boolean equalsHelper(Object l, Object r) {
return UtilObject.equalsHelper(l, r);
}
+ public static <T extends Collection<I>, I> T checkEmpty(T col) {
+ return UtilValidate.isEmpty(col) ? null : col;
+ }
+
+ public static <T extends Map<K, V>, K, V> T checkEmpty(T map) {
+ return UtilValidate.isEmpty(map) ? null : map;
+ }
+
public String toString() {
return appendTo(new StringBuilder()).toString();
}
Modified: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLSelect.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLSelect.java?rev=949608&r1=949607&r2=949608&view=diff
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLSelect.java (original)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLSelect.java Sun May 30
22:07:04 2010
@@ -41,10 +41,10 @@ public final class SQLSelect extends SQL
public SQLSelect(boolean isDistinct, List<FieldAll> fieldAlls, Map<String,
FieldDef> fieldDefs, Table table, Map<String, Relation> relations, Condition
whereCondition, Condition havingCondition, List<String> groupBy,
List<OrderByItem> orderBy, int offset, int limit) {
this.isDistinct = isDistinct;
- this.fieldAlls = fieldAlls;
- this.fieldDefs = fieldDefs;
+ this.fieldAlls = checkEmpty(fieldAlls);
+ this.fieldDefs = checkEmpty(fieldDefs);
this.table = table;
- this.relations = relations;
+ this.relations = checkEmpty(relations);
this.whereCondition = whereCondition;
this.havingCondition = havingCondition;
this.groupBy = groupBy;
@@ -108,10 +108,10 @@ public final class SQLSelect extends SQL
SQLSelect other = (SQLSelect) o;
return isDistinct == other.isDistinct
- && fieldAlls.equals(other.fieldAlls)
- && fieldDefs.equals(other.fieldDefs)
+ && equalsHelper(fieldAlls, other.fieldAlls)
+ && equalsHelper(fieldDefs, other.fieldDefs)
&& table.equals(other.table)
- && relations.equals(other.relations)
+ && equalsHelper(relations, other.relations)
&& equalsHelper(whereCondition, other.whereCondition)
&& equalsHelper(havingCondition, other.havingCondition)
&& offset == other.offset
@@ -126,14 +126,18 @@ public final class SQLSelect extends SQL
if (isDistinct) {
sb.append(" DISTINCT");
}
- StringUtil.appendTo(sb, fieldAlls, " ", null, ",");
- if (!fieldAlls.isEmpty() && !fieldDefs.isEmpty()) {
+ if (fieldAlls != null) {
+ StringUtil.appendTo(sb, fieldAlls, " ", null, ",");
+ }
+ if (fieldAlls != null && fieldDefs != null) {
sb.append(',');
}
- StringUtil.appendTo(sb, fieldDefs.values(), " ", null, ",");
+ if (fieldDefs != null) {
+ StringUtil.appendTo(sb, fieldDefs.values(), " ", null, ",");
+ }
sb.append(" FROM ");
table.appendTo(sb);
- if (!relations.isEmpty()) {
+ if (relations != null) {
StringUtil.appendTo(sb, relations.values(), " ", null, ",");
}
if (whereCondition != null) {