details:   https://code.openbravo.com/erp/devel/pi/rev/6323b569fcbb
changeset: 34954:6323b569fcbb
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Tue Nov 13 09:24:05 2018 +0100
summary:   fixed bug 39614: random unique constraint violation message

  Get name to generate error message from actual element associated to the 
column
  in the table we are looking for instead of getting it from any element with 
that
  same name assuming it is unique.

diffstat:

 src/org/openbravo/erpCommon/utility/ErrorTextParser.java       |  19 +++++----
 src/org/openbravo/erpCommon/utility/ErrorTextParserORACLE.java |   4 +-
 src/org/openbravo/erpCommon/utility/ErrorTextParser_data.xsql  |  19 +++++++--
 3 files changed, 27 insertions(+), 15 deletions(-)

diffs (129 lines):

diff -r 03d8fd2a8cca -r 6323b569fcbb 
src/org/openbravo/erpCommon/utility/ErrorTextParser.java
--- a/src/org/openbravo/erpCommon/utility/ErrorTextParser.java  Mon Nov 12 
13:00:12 2018 +0100
+++ b/src/org/openbravo/erpCommon/utility/ErrorTextParser.java  Tue Nov 13 
09:24:05 2018 +0100
@@ -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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2018 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -156,7 +156,7 @@
   protected String getTableName(String tableName) {
     try {
       String pkColumnName = tableName + "_ID";
-      return ErrorTextParserData.selectColumnName(conn, language, 
pkColumnName);
+      return ErrorTextParserData.selectColumnName(conn, language, tableName, 
pkColumnName);
     } catch (ServletException e) {
       log4j.error(
           "Error while trying to name for table via ad_element for tablename: 
" + tableName, e);
@@ -168,14 +168,17 @@
    * Helper method to get a (slightly better) human-readable name for a 
database column based on its
    * name. Method uses AD_ELEMENT.name and AD_ELEMENT_TRL.NAME for this purpose
    * 
+   * @param tableName
+   *          table where the column is in
+   * 
    * @param columnName
-   *          name of a database column
+   *          name of the column to get its human readable name
    * @return translated, human-readable name
    */
-  protected String getColumnName(String columnName) {
+  protected String getColumnName(String tableName, String columnName) {
     String res;
     try {
-      res = ErrorTextParserData.selectColumnName(conn, language, columnName);
+      res = ErrorTextParserData.selectColumnName(conn, language, tableName, 
columnName);
       return res;
     } catch (ServletException e) {
       log4j.error("Error while trying to get name for ad_element.columnname: " 
+ columnName, e);
@@ -236,7 +239,7 @@
           if (columns.length() > 0) {
             columns.append(", ");
           }
-          columns.append(getColumnName(column));
+          columns.append(getColumnName(constraintData[0].tableName, column));
         }
         String columnName;
         if (columnList.length > 1) {
@@ -300,7 +303,7 @@
           if (msgText != null) {
             String msgTemplate = msgText.getField("msgText");
             String tableName = getTableName(constraintData[0].tableName);
-            columnName = getColumnName(columnName);
+            columnName = getColumnName(constraintData[0].tableName, 
columnName);
             Map<String, String> replaceMap = new HashMap<String, String>();
             replaceMap.put("TABLE_NAME", tableName);
             replaceMap.put("COLUMN_NAME", columnName);
@@ -312,7 +315,7 @@
         } else if (searchCond.endsWith(" IN ('Y','N')") || 
searchCond.endsWith(" IN ('Y', 'N')")
             || searchCond.endsWith(" IN ('N','Y')") || searchCond.endsWith(" 
IN ('N', 'Y')")) {
           String columnName = searchCond.substring(0, searchCond.lastIndexOf(" 
IN (")).trim();
-          columnName = getColumnName(columnName);
+          columnName = getColumnName(constraintData[0].tableName, columnName);
 
           FieldProvider msgText = Utility.locateMessage(getConnection(), 
"NotYNError",
               getLanguage());
diff -r 03d8fd2a8cca -r 6323b569fcbb 
src/org/openbravo/erpCommon/utility/ErrorTextParserORACLE.java
--- a/src/org/openbravo/erpCommon/utility/ErrorTextParserORACLE.java    Mon Nov 
12 13:00:12 2018 +0100
+++ b/src/org/openbravo/erpCommon/utility/ErrorTextParserORACLE.java    Tue Nov 
13 09:24:05 2018 +0100
@@ -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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2018 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -184,8 +184,8 @@
               getLanguage());
           if (msgText != null) {
             String msgTemplate = msgText.getField("msgText");
+            columnName = getColumnName(tableName, columnName);
             tableName = getTableName(tableName);
-            columnName = getColumnName(columnName);
             Map<String, String> replaceMap = new HashMap<String, String>();
             replaceMap.put("TABLE_NAME", tableName);
             replaceMap.put("COLUMN_NAME", columnName);
diff -r 03d8fd2a8cca -r 6323b569fcbb 
src/org/openbravo/erpCommon/utility/ErrorTextParser_data.xsql
--- a/src/org/openbravo/erpCommon/utility/ErrorTextParser_data.xsql     Mon Nov 
12 13:00:12 2018 +0100
+++ b/src/org/openbravo/erpCommon/utility/ErrorTextParser_data.xsql     Tue Nov 
13 09:24:05 2018 +0100
@@ -12,7 +12,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) 2001-2010 Openbravo SLU
+ * All portions are Copyright (C) 2001-2018 Openbravo SLU
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -38,12 +38,21 @@
   <SqlMethod name="selectColumnName" type="preparedStatement" return="String">
     <SqlMethodComment></SqlMethodComment>
     <Sql>
-      select coalesce(ad_element_trl.name, ad_element.name) as column_name
-      from ad_element left join ad_element_trl on ad_element.ad_element_id = 
ad_element_trl.ad_element_id and ad_element_trl.ad_language = ?
-      where upper(ad_element.columnname) = upper(?)
+        select coalesce(et.name, e.name, c.name) as column_name
+          from ad_table t,
+               ad_column c
+                left join ad_element e
+                       on c.ad_element_id = e.ad_element_id
+                left join ad_element_trl et
+                       on e.ad_element_id = et.ad_element_id
+                      and et.ad_language = ?
+         where t.ad_table_id = c.ad_table_id
+           and upper(t.tableName) = upper(?)
+           and upper(c.columnName) = upper(?)
     </Sql>
     <Parameter name="language"/>
-    <Parameter name="columnname"/>
+    <Parameter name="tableName"/>
+    <Parameter name="columnName"/>
   </SqlMethod>
 
   <SqlMethod name="selectColumnNamesForConstraint" type="preparedStatement" 
return="multiple">


_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to