fixed bug 35492: error checking pl consistency
authorAsier Lostalé <asier.lostale@openbravo.com>
Mon, 13 Mar 2017 09:26:00 +0100
changeset 928 8c2f9c7b3ec8
parent 927 cb8b35695efb
child 929 2c18bf970368
fixed bug 35492: error checking pl consistency

There were two problems in PG PL concistency checking for triggers:
* They were incorrectly casted to Function
* They were not translated with the specific trigger translator
src/org/apache/ddlutils/platform/postgresql/PostgrePLSQLConsistencyChecker.java
--- a/src/org/apache/ddlutils/platform/postgresql/PostgrePLSQLConsistencyChecker.java	Thu Mar 09 12:59:50 2017 +0100
+++ b/src/org/apache/ddlutils/platform/postgresql/PostgrePLSQLConsistencyChecker.java	Mon Mar 13 09:26:00 2017 +0100
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2016 Openbravo S.L.U.
+ * Copyright (C) 2016-2017 Openbravo S.L.U.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to  in writing,  software  distributed
@@ -48,15 +48,17 @@
   /** Checks PL consistency returning {@code null} if it is consistent or the object if it is not */
   @Override
   public StructureObject call() throws Exception {
-    PostgrePLSQLFunctionTranslation funcTrans = new PostgrePLSQLFunctionTranslation(fullDatabase);
+    PostgrePLSQLTranslation translator;
     String originalBody;
     String body;
     if (plObject instanceof Function) {
       originalBody = ((Function) plObject).getOriginalBody();
       body = ((Function) plObject).getBody();
+      translator = new PostgrePLSQLFunctionTranslation(fullDatabase);
     } else if (plObject instanceof Trigger) {
       originalBody = ((Trigger) plObject).getOriginalBody();
-      body = ((Function) plObject).getBody();
+      body = ((Trigger) plObject).getBody();
+      translator = new PostgrePLSQLTriggerTranslation(fullDatabase);
     } else {
       throw new IllegalArgumentException("Expected a Function or a Trigger got a "
           + plObject.getClass().getName());
@@ -69,7 +71,7 @@
     CommentFilter comFilter1 = new CommentFilter();
     String s1 = litFilter1.removeLiterals(body);
     s1 = comFilter1.removeComments(s1);
-    s1 = funcTrans.exec(s1);
+    s1 = translator.exec(s1);
     s1 = comFilter1.restoreComments(s1);
     s1 = litFilter1.restoreLiterals(s1);
     String s1r = s1.replaceAll("\\s", "");