# HG changeset patch
# Parent 3c4dbd96fad44f5aafff72ebb8efee26da49efec
fixes issues 16623: Add logic in CustomQuerySelectorDatasource to generate more efficient filter for foreign key domain types

diff --git a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
--- a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
+++ b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
@@ -41,7 +41,9 @@
 import org.openbravo.base.model.domaintype.BooleanDomainType;
 import org.openbravo.base.model.domaintype.DateDomainType;
 import org.openbravo.base.model.domaintype.DomainType;
+import org.openbravo.base.model.domaintype.ForeignKeyDomainType;
 import org.openbravo.base.model.domaintype.LongDomainType;
+import org.openbravo.base.model.domaintype.UniqueIdDomainType;
 import org.openbravo.client.application.ParameterUtils;
 import org.openbravo.client.kernel.RequestContext;
 import org.openbravo.dal.core.OBContext;
@@ -283,8 +285,10 @@
    * <li>Date Domain Type: Returns a multiple clause comparing separately value's day, month and
    * year.</li>
    * <li>Boolean Domain Type: Returns an equals clause <i>field.clauseLeftPart = value</i></li>
-   * <li>String Domain Type: Compares the clause left part with the value using the C_IGNORE_ACCENT
-   * database function which ignores accents and is case insensitive.
+   * <li>Foreign Key Domain Type: Returns an equals clause <i>field.clauseLeftPart.id = value</i></li>
+   * <li>Unique Id Domain Type: Returns an equals clause <i>field.clauseLeftPart = value</i></li>
+   * <li>String Domain Type: Compares the clause left part with the value using the lower
+   * database function which to make comparison case insensitive.
    * </ul>
    * 
    * @param value
@@ -318,10 +322,15 @@
       }
     } else if (domainType instanceof BooleanDomainType) {
       whereClause = field.getClauseLeftPart() + " = " + value;
+    } else if (domainType instanceof UniqueIdDomainType) {
+      whereClause = field.getClauseLeftPart() + " = '" + value + "'";
+    } else if (domainType instanceof ForeignKeyDomainType) {
+      // Assume left part definition is full object reference from HQL select
+      whereClause = field.getClauseLeftPart() + ".id = '" + value + "'";
     } else {
-      whereClause = "C_IGNORE_ACCENT(" + field.getClauseLeftPart() + ")";
-      whereClause += " LIKE C_IGNORE_ACCENT(";
-      whereClause += "'%" + value.toUpperCase().replaceAll(" ", "%") + "%')";
+      whereClause = "lower(" + field.getClauseLeftPart() + ")";
+      whereClause += " LIKE ";
+      whereClause += "'%" + value.toLowerCase().replaceAll(" ", "%") + "%'";
     }
     return whereClause;
   }
diff --git a/src-db/database/sourcedata/AD_REFERENCE.xml b/src-db/database/sourcedata/AD_REFERENCE.xml
--- a/src-db/database/sourcedata/AD_REFERENCE.xml
+++ b/src-db/database/sourcedata/AD_REFERENCE.xml
@@ -132,7 +132,7 @@
 <!--13-->  <VALIDATIONTYPE><![CDATA[D]]></VALIDATIONTYPE>
 <!--13-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--13-->  <ISBASEREFERENCE><![CDATA[Y]]></ISBASEREFERENCE>
-<!--13-->  <MODEL_IMPL><![CDATA[org.openbravo.base.model.domaintype.StringDomainType]]></MODEL_IMPL>
+<!--13-->  <MODEL_IMPL><![CDATA[org.openbravo.base.model.domaintype.UniqueIdDomainType]]></MODEL_IMPL>
 <!--13-->  <WAD_IMPL><![CDATA[org.openbravo.wad.controls.WADID]]></WAD_IMPL>
 <!--13-->  <UI_IMPL><![CDATA[org.openbravo.reference.ui.UIID]]></UI_IMPL>
 <!--13-->  <ISVALUEDISPLAYED><![CDATA[N]]></ISVALUEDISPLAYED>
diff --git a/src/org/openbravo/base/model/domaintype/UniqueIdDomainType.java b/src/org/openbravo/base/model/domaintype/UniqueIdDomainType.java
new file mode 100644
--- /dev/null
+++ b/src/org/openbravo/base/model/domaintype/UniqueIdDomainType.java
@@ -0,0 +1,30 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  Enterprise Intelligence Systems
+ ************************************************************************
+ */
+
+package org.openbravo.base.model.domaintype;
+
+/**
+ * The type for a ID column.
+ *
+ * @author eintelau (ben.sommerville@eintel.com.au)
+ */
+public class UniqueIdDomainType extends StringDomainType {
+}
+
+
