[jbpm-commits] JBoss JBPM SVN: r6096 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/id and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jan 19 12:14:52 EST 2010


Author: tom.baeyens at jboss.com
Date: 2010-01-19 12:14:51 -0500 (Tue, 19 Jan 2010)
New Revision: 6096

Modified:
   jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/DbHelper.java
   jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/JbpmVersion.java
   jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Upgrade.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/PropertyImpl.java
Log:
JBPM-2714 fixing upgrade

Modified: jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/DbHelper.java
===================================================================
--- jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/DbHelper.java	2010-01-19 15:47:58 UTC (rev 6095)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/DbHelper.java	2010-01-19 17:14:51 UTC (rev 6096)
@@ -25,7 +25,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.hibernate.classic.Session;
+import org.hibernate.Session;
 import org.jbpm.api.JbpmException;
 import org.jbpm.internal.log.Jdk14LogFactory;
 import org.jbpm.internal.log.Log;
@@ -47,7 +47,7 @@
     log.info("where database is one of {oracle, postgresql, mysql, hsqldb}"); 
     log.info("and delimiter is the db sql delimiter.  default delimiter is ;");
   }
-  
+
   public static void executeSqlResource(String resource, Session session) {
     InputStream stream = Upgrade.class.getClassLoader().getResourceAsStream(resource);
     if (stream == null) {

Modified: jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/JbpmVersion.java
===================================================================
--- jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/JbpmVersion.java	2010-01-19 15:47:58 UTC (rev 6095)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/JbpmVersion.java	2010-01-19 17:14:51 UTC (rev 6096)
@@ -26,7 +26,7 @@
  */
 public enum JbpmVersion {
 
-  V_4_0, V_4_1, V_4_2, V_4_3;
+  V_4_0, V_4_1, V_4_2, V_4_3, V_4_4;
 
   public String toString() {
     return "4." + ordinal();

Modified: jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Upgrade.java
===================================================================
--- jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Upgrade.java	2010-01-19 15:47:58 UTC (rev 6095)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Upgrade.java	2010-01-19 17:14:51 UTC (rev 6096)
@@ -24,7 +24,7 @@
 import java.util.List;
 
 import org.hibernate.HibernateException;
-import org.hibernate.classic.Session;
+import org.hibernate.Session;
 import org.hibernate.criterion.Restrictions;
 import org.jbpm.api.JbpmException;
 import org.jbpm.api.ProcessEngine;
@@ -47,6 +47,7 @@
   private static Log log = Log.getLog(Upgrade.class.getName());
   
   static String database;
+  static JbpmVersion jbpmVersion;
 
   public static void main(String[] args) {
     if ( (args==null)
@@ -63,72 +64,80 @@
       .buildProcessEngine();
   
     try {
-      JbpmVersion jbpmVersion = (JbpmVersion) processEngine.execute(new Command<Object>(){
+      processEngine.execute(new Command<Object>(){
         private static final long serialVersionUID = 1L;
         public Object execute(Environment environment) throws Exception {
           Session session = environment.get(Session.class);
           if (!PropertyImpl.propertiesTableExists(session)) {
             try {
               session.createSQLQuery("select CLASSNAME_ from JBPM4_VARIABLE").list();
-              return JbpmVersion.V_4_1;
+              jbpmVersion = JbpmVersion.V_4_1;
 
             } catch (HibernateException e) {
-              return JbpmVersion.V_4_0;
+              jbpmVersion = JbpmVersion.V_4_0;
             }
+          } else {
+            String dbVersion = PropertyImpl.getDbVersion(session);
+            if (dbVersion == null) {
+              throw new JbpmException("property table exists, but no db version property is present");
+            }
+
+            jbpmVersion = JbpmVersion.getJbpmVersion(dbVersion);
           }
-    
-          String dbVersion = PropertyImpl.getDbVersion(session);
-          if (dbVersion == null) {
-            throw new JbpmException("property table exists, but no db version property is present");
-          }
-    
-          return JbpmVersion.getJbpmVersion(dbVersion);
+          return null;
         }
       });
 
-      if (jbpmVersion == JbpmVersion.V_4_2) {
-        throw new JbpmException("jBPM schema is already up to date");
-      }
-
-      if (jbpmVersion.isEarlier(JbpmVersion.V_4_1)) {
+      if (jbpmVersion == JbpmVersion.V_4_4) {
+        log.info("jBPM schema is already up to date");
+        
+      } else {
         processEngine.execute(new Command<Object>(){
           private static final long serialVersionUID = 1L;
           public Object execute(Environment environment) throws Exception {
             Session session = environment.get(Session.class);
-            DbHelper.executeSqlResource("upgrade-4.0-to-4.1/jbpm." + database + ".upgrade.sql", session);
+            
+            log.info("upgrading from "+jbpmVersion+" to "+ProcessEngineImpl.JBPM_LIBRARY_VERSION);
+            
+            if (jbpmVersion.isEarlier(JbpmVersion.V_4_1)) {
+              DbHelper.executeSqlResource("upgrade-4.0-to-4.1/jbpm." + database + ".upgrade.sql", session);
+            }
+
+            if (jbpmVersion.isEarlier(JbpmVersion.V_4_2)) {
+              boolean isFfirstPartUpgrade42Completed = PropertyImpl.isFirstPartUpgrade42Completed(session);
+              if (!isFfirstPartUpgrade42Completed) {
+                DbHelper.executeSqlResource("upgrade-4.1-to-4.2/jbpm." + database + ".upgrade.sql", session);
+                PropertyImpl.initializeNextDbid(session);
+                PropertyImpl.setDbVersionTo41(session);
+              }
+            }
             return null;
           }
         });
-      }
 
-      if (jbpmVersion.isEarlier(JbpmVersion.V_4_2)) {
         processEngine.execute(new Command<Object>(){
           private static final long serialVersionUID = 1L;
           public Object execute(Environment environment) throws Exception {
             Session session = environment.get(Session.class);
-            DbHelper.executeSqlResource("upgrade-4.1-to-4.2/jbpm." + database + ".upgrade.sql", session);
-            PropertyImpl.upgradeProperties(session);
-            return null;
-          }
-        });
-        processEngine.execute(new Command<Object>(){
-          private static final long serialVersionUID = 1L;
-          public Object execute(Environment environment) throws Exception {
-            Session session = environment.get(Session.class);
-            // find deployments without a langid property
-            List<DeploymentProperty> deploymentProperties = session.createCriteria(DeploymentProperty.class)
-                .add(Restrictions.eq("key", DeploymentImpl.KEY_PROCESS_DEFINITION_ID))
-                .list();
-
-            for (DeploymentProperty deploymentProperty : deploymentProperties) {
-              String objectName = deploymentProperty.getObjectName();
-              DeploymentImpl deployment = deploymentProperty.getDeployment();
-              deployment.setProcessLanguageId(objectName, "jpdl-4.0");
+            
+            if (jbpmVersion.isEarlier(JbpmVersion.V_4_2)) {
+              // find deployments without a langid property
+              List<DeploymentProperty> deploymentProperties = session.createCriteria(DeploymentProperty.class)
+                  .add(Restrictions.eq("key", DeploymentImpl.KEY_PROCESS_DEFINITION_ID))
+                  .list();
+        
+              for (DeploymentProperty deploymentProperty : deploymentProperties) {
+                String objectName = deploymentProperty.getObjectName();
+                DeploymentImpl deployment = deploymentProperty.getDeployment();
+                deployment.setProcessLanguageId(objectName, "jpdl-4.0");
+              }
             }
+            
+            PropertyImpl.setDbVersionToLibraryVersion(session);
             return null;
           }
         });
-      }
+      }      
 
       log.info("jBPM DB upgrade completed successfully.");
 

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/PropertyImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/PropertyImpl.java	2010-01-19 15:47:58 UTC (rev 6095)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/PropertyImpl.java	2010-01-19 17:14:51 UTC (rev 6096)
@@ -102,13 +102,12 @@
     setNextDbid(session, 1);
   }
 
-  public static void upgradeProperties(Session session) {
-    setDbVersionToLibraryVersion(session);
+  public static void initializeNextDbid(Session session) {
     long nextDbid = getMaxDbid(session)+1;
     setNextDbid(session, nextDbid);
     log.info("nextDbid is initialized to "+nextDbid);
   }
-
+  
   public static boolean propertiesTableExists(Session session) {
     try {
       session.createQuery("from "+PropertyImpl.class.getName())
@@ -186,7 +185,21 @@
         .add(Restrictions.eq("key", key))
         .uniqueResult();
   }
-  
+
+  public static boolean isFirstPartUpgrade42Completed(Session session) {
+    try {
+      getProperty(session, DB_VERSION_KEY);
+      return true;
+    } catch (Exception e) {
+      // ok, this means the properties table exists
+    }
+    return false;
+  }
+
+  public static void setDbVersionTo41(Session session) {
+    setPropertyValue(session, DB_VERSION_KEY, "4.1");
+  }
+
   // getters and setters //////////////////////////////////////////////////////
 
   public String getKey() {



More information about the jbpm-commits mailing list