Related with issue 29612: to_char needed in non-textual identifier properties
authorAugusto Mauch <augusto.mauch@openbravo.com>
Mon, 18 May 2015 10:49:53 +0200
changeset 27075 cf34375332d2
parent 27074 322841d09c06
child 27076 c8311f845ea4
Related with issue 29612: to_char needed in non-textual identifier properties

When filtering a foreign key whose identifier is a column that does not use a text/string reference, using the to_char function is still needed.
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
src/org/openbravo/base/model/Property.java
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java	Mon May 18 09:51:00 2015 +0200
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java	Mon May 18 10:49:53 2015 +0200
@@ -1582,17 +1582,15 @@
               + prefix.substring(0, prefix.lastIndexOf('.')) + " and t.language.language='"
               + OBContext.getOBContext().getLanguage().getLanguage() + "')), to_char("
               + replaceValueWithJoins(prefix + prop.getName()) + "), '')");
+        } else if (prop.isMandatory() && prop.isTextualType()) {
+          // if the property is mandatory there is no need to use coalesce to replace a possible
+          // null value with an empty string
+          // getting rid of the coalesce and to_char functions allow under certain circumstances
+          // to use indexes defined on that property
+          sb.append(replaceValueWithJoins(prefix + prop.getName()));
         } else {
-          if (prop.isMandatory()) {
-            // if the property is mandatory there is no need to use coalesce to replace a
-            // possible null value with an empty string
-            // getting rid of the coalesce and to_char functions allow under certain circumstances
-            // to use indexes defined on that property
-            sb.append(replaceValueWithJoins(prefix + prop.getName()));
-          } else {
-            sb.append("COALESCE(to_char(" + replaceValueWithJoins(prefix + prop.getName())
-                + "),'')");
-          }
+          sb.append("COALESCE(to_char(" + replaceValueWithJoins(prefix + prop.getName()) + "),'')");
+
         }
 
       } else {
--- a/src/org/openbravo/base/model/Property.java	Mon May 18 09:51:00 2015 +0200
+++ b/src/org/openbravo/base/model/Property.java	Mon May 18 10:49:53 2015 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -476,6 +476,18 @@
   }
 
   /**
+   * @return true if the class of the primitive type ({@link #getPrimitiveObjectType()}) is a
+   *         textual type (extends {@link Number}).
+   */
+  public boolean isTextualType() {
+    final Class<?> typeClass = getPrimitiveObjectType();
+    if (typeClass == null) {
+      return false;
+    }
+    return String.class.isAssignableFrom(typeClass);
+  }
+
+  /**
    * Returns the Object value of the default, for example a Date property with default value of
    * today will return a new Date() object.
    *