details:   https://code.openbravo.com/erp/devel/pi/rev/462eab118a3b
changeset: 34795:462eab118a3b
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Fri Sep 21 11:26:50 2018 +0200
summary:   fixed bug 39332: PG 11: ad_db_modified function fails

  AD_DB_MODIFIED was failing in PG 11 because it was using pg_proc.proisagg
  column which does no longer exist starting from 11.

  Using that column was unneeded in any case because it was in query to get
  paramaters and it was filtering out functions using them, as those functions
  where already obtained in outer query, it is not needed to filter them again.

details:   https://code.openbravo.com/erp/devel/pi/rev/45a672248561
changeset: 34796:45a672248561
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Fri Sep 21 11:34:01 2018 +0200
summary:   related to bug 39332: PG 11: ad_db_modified function fails

  Added test cases covering ad_db_modified

diffstat:

 src-db/database/model/prescript-PostgreSql.sql            |   3 +-
 src-test/src/org/openbravo/test/AllAntTaskTests.java      |   4 +-
 src-test/src/org/openbravo/test/model/DBModifiedTest.java |  97 +++++++++++++++
 3 files changed, 101 insertions(+), 3 deletions(-)

diffs (142 lines):

diff -r 8a73e458127f -r 45a672248561 
src-db/database/model/prescript-PostgreSql.sql
--- a/src-db/database/model/prescript-PostgreSql.sql    Tue Sep 25 09:59:27 
2018 +0200
+++ b/src-db/database/model/prescript-PostgreSql.sql    Fri Sep 21 11:34:01 
2018 +0200
@@ -1289,7 +1289,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) 2009 Openbravo SLU
+* All portions are Copyright (C) 2009-2018 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************/
@@ -1338,7 +1338,6 @@
           WHERE pg_proc.prorettype <> 'pg_catalog.cstring'::pg_catalog.regtype
             AND (pg_proc.proargtypes[0] IS NULL
              OR pg_proc.proargtypes[0] <> 
'pg_catalog.cstring'::pg_catalog.regtype)
-            AND NOT pg_proc.proisagg
             AND pg_catalog.pg_function_is_visible(pg_proc.oid)
             AND pg_proc.proname = i.realname
              and pg_proc.pronargs = i.pronargs
diff -r 8a73e458127f -r 45a672248561 
src-test/src/org/openbravo/test/AllAntTaskTests.java
--- a/src-test/src/org/openbravo/test/AllAntTaskTests.java      Tue Sep 25 
09:59:27 2018 +0200
+++ b/src-test/src/org/openbravo/test/AllAntTaskTests.java      Fri Sep 21 
11:34:01 2018 +0200
@@ -74,6 +74,7 @@
 import org.openbravo.test.inventoryStatus.InventoryStatusTest;
 import 
org.openbravo.test.materialMgmt.iscompletelyinvoicedshipment.IsCompletelyInvoicedShipment;
 import org.openbravo.test.model.ClassLoaderTest;
+import org.openbravo.test.model.DBModifiedTest;
 import org.openbravo.test.model.IndexesTest;
 import org.openbravo.test.model.OneToManyTest;
 import org.openbravo.test.model.RuntimeModelTest;
@@ -175,7 +176,8 @@
     ClassLoaderTest.class, //
     IndexesTest.class, //
     TrlColumnsOraTypeTest.class, //
-    ADCSInitialization.class,
+    ADCSInitialization.class, //
+    DBModifiedTest.class,
 
     // modularity
     DatasetServiceTest.class, //
diff -r 8a73e458127f -r 45a672248561 
src-test/src/org/openbravo/test/model/DBModifiedTest.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/test/model/DBModifiedTest.java Fri Sep 21 
11:34:01 2018 +0200
@@ -0,0 +1,97 @@
+/*
+ *************************************************************************
+ * 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) 2018 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.test.model;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.test.base.OBBaseTest;
+
+/** Test cases covering detection of DB model changes */
+public class DBModifiedTest extends OBBaseTest {
+
+  @Test
+  public void noChangesTest() {
+    assertFalse("DB changes detected without any change performed in DB", 
isDBModified(false));
+  }
+
+  @Test
+  public void dbChangesShouldBeDetected() {
+    try {
+      createDBObject();
+      assertTrue("DB changes were not detected", isDBModified(false));
+    } finally {
+      dropDBObject();
+    }
+  }
+
+  @Test
+  public void dbChecksumCanBePersisted() {
+    try {
+      createDBObject();
+      assertTrue("DB changes were not detected", isDBModified(true));
+
+      assertFalse("DB changes were detected just after upating check sum in 
DB",
+          isDBModified(false));
+    } finally {
+      dropDBObject();
+    }
+  }
+
+  @Test
+  public void canCheckChangesWithoutSavingChecksum() {
+    try {
+      createDBObject();
+      assertTrue("DB changes were not detected", isDBModified(false));
+
+      assertTrue("DB changes were not detected after calling AD_DB_MODIFIED 
persisting checksum ",
+          isDBModified(false));
+    } finally {
+      dropDBObject();
+    }
+  }
+
+  private boolean isDBModified(boolean saveChecksum) {
+    Object modified = OBDal.getInstance().getSession()
+        .createNativeQuery("SELECT AD_DB_MODIFIED(:saveChecksum) FROM DUAL", 
Object.class)
+        .setParameter("saveChecksum", saveChecksum ? "Y" : "N") //
+        .uniqueResult();
+
+    // PG returns Character and ORA String
+    return modified.equals('Y') || modified.equals("Y");
+  }
+
+  private void createDBObject() {
+    OBDal.getInstance().getSession()
+        .createNativeQuery("CREATE TABLE TEST_OBJ AS SELECT * FROM DUAL") //
+        .executeUpdate();
+  }
+
+  private void dropDBObject() {
+    OBDal.getInstance().getSession() //
+        .createNativeQuery("DROP TABLE TEST_OBJ") //
+        .executeUpdate();
+
+    // reset checksum after dropping object
+    isDBModified(true);
+  }
+}


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

Reply via email to