Fixed issue 13613. Modulescripts will be executed during install.source.
authorAntonio Moreno <antonio.moreno@openbravo.com>
Mon, 24 Jan 2011 15:36:42 +0100
changeset 10098 b3960e2ed9de
parent 10097 413d4f41dde7
child 10099 5e020eacbbec
Fixed issue 13613. Modulescripts will be executed during install.source.
build.xml
src/org/openbravo/service/db/ImportReferenceDataTask.java
--- a/build.xml	Mon Jan 24 14:56:49 2011 +0100
+++ b/build.xml	Mon Jan 24 15:36:42 2011 +0100
@@ -225,7 +225,7 @@
     <dirset dir="${base.modules}">
       <include name="*/build/classes/" />
     </dirset>
-    <pathelement path="${basedir}/../../src-util/modulescript/build/classes/" />
+    <pathelement path="${basedir}/src-util/modulescript/build/classes/" />
     <pathelement path="${build}" />
     <pathelement path="${base.src}" />
     <fileset dir="${base.lib}">
--- a/src/org/openbravo/service/db/ImportReferenceDataTask.java	Mon Jan 24 14:56:49 2011 +0100
+++ b/src/org/openbravo/service/db/ImportReferenceDataTask.java	Mon Jan 24 15:36:42 2011 +0100
@@ -24,6 +24,7 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.sql.Connection;
 import java.util.Properties;
 import java.util.Vector;
 
@@ -37,6 +38,7 @@
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.ddlutils.task.DatabaseUtils;
 import org.openbravo.ddlutils.util.DBSMOBUtil;
+import org.openbravo.modulescript.ModuleScriptHandler;
 
 /**
  * Imports client data for the clients defined in the clients parameter from the
@@ -56,9 +58,20 @@
       log.info("Error disabling check constraint");
     }
     super.execute();
+    executeModuleScripts();
     enableConstraints();
   }
 
+  private void executeModuleScripts() {
+    try {
+      ModuleScriptHandler hd = new ModuleScriptHandler();
+      hd.setBasedir(new File(getProject().getBaseDir() + "/../"));
+      hd.execute();
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+
   @Override
   protected void doExecute() {
     final File importDir = getReferenceDataDir();
@@ -96,6 +109,7 @@
   }
 
   private void disableConstraints() throws FileNotFoundException, IOException {
+    log.info("Disabling constraints...");
     String obDir = getProject().getBaseDir().toString() + "/../";
     Properties obProp = new Properties();
     obProp.load(new FileInputStream(new File(obDir, "config/Openbravo.properties")));
@@ -125,12 +139,38 @@
       fileArray[i] = dirs.get(i);
     }
     xmlModel = DatabaseUtils.readDatabase(fileArray);
-
-    platform.disableCheckConstraints(xmlModel);
+    Connection con = null;
+    try {
+      con = platform.borrowConnection();
+      log.info("   Disabling foreign keys");
+      platform.disableAllFK(con, xmlModel, false);
+      log.info("   Disabling triggers");
+      platform.disableAllTriggers(con, xmlModel, false);
+      log.info("   Disabling check constraints");
+      platform.disableCheckConstraints(xmlModel);
+    } finally {
+      if (con != null) {
+        platform.returnConnection(con);
+      }
+    }
   }
 
   private void enableConstraints() {
-    platform.enableCheckConstraints(xmlModel);
+    log.info("Enabling constraints...");
+    Connection con = null;
+    try {
+      con = platform.borrowConnection();
+      log.info("   Enabling check constraints");
+      platform.enableCheckConstraints(xmlModel);
+      log.info("   Enabling triggers");
+      platform.enableAllTriggers(con, xmlModel, false);
+      log.info("   Enabling foreign keys");
+      platform.enableAllFK(con, xmlModel, false);
+    } finally {
+      if (con != null) {
+        platform.returnConnection(con);
+      }
+    }
   }
 
   public void setDisableCheckReferencedOrganizations(boolean disableCheckReferencedOrganizations) {