[jbpm-commits] JBoss JBPM SVN: r6442 - in jbpm4/trunk/modules: db/src/main/java/org/jbpm/db and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jun 29 13:57:12 EDT 2010


Author: alex.guizar at jboss.com
Date: 2010-06-29 13:57:11 -0400 (Tue, 29 Jun 2010)
New Revision: 6442

Modified:
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/cmd/VoidCommand.java
   jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Create.java
   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/distro/scripts/assembly-distro.xml
   jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/async/ExclusiveMessagesTest.java
Log:
JBPM-2893: remove unused exclusion patterns from distro assembly
clean up create/update database schema programs

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/cmd/VoidCommand.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/cmd/VoidCommand.java	2010-06-29 06:57:29 UTC (rev 6441)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/cmd/VoidCommand.java	2010-06-29 17:57:11 UTC (rev 6442)
@@ -21,7 +21,6 @@
  */
 package org.jbpm.api.cmd;
 
-
 /** convenience for commands without return value.
  * 
  * @author Tom Baeyens
@@ -35,6 +34,6 @@
     return null;
   }
 
-  public abstract void executeVoid(Environment environment) throws Exception;
+  protected abstract void executeVoid(Environment environment) throws Exception;
 
 }

Modified: jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Create.java
===================================================================
--- jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Create.java	2010-06-29 06:57:29 UTC (rev 6441)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Create.java	2010-06-29 17:57:11 UTC (rev 6442)
@@ -36,41 +36,34 @@
 
   private static final long serialVersionUID = 1L;
 
-  private static Log log = Log.getLog(Upgrade.class.getName());
-  
-  static String database;
+  private static final Log log = Log.getLog(Create.class.getName());
 
   public static void main(String[] args) {
-    if ( (args==null)
-         || (args.length!=1)
-       ) {
+    if (args.length != 1) {
       DbHelper.printSyntax(Upgrade.class);
       return;
     }
-    
-    database = args[0];
-    
-    ProcessEngine processEngine = new ConfigurationImpl()
-        .skipDbCheck()
-        .buildProcessEngine();
-    
+
+    final String database = args[0];
+    ProcessEngine processEngine = new ConfigurationImpl().skipDbCheck().buildProcessEngine();
+
     try {
-      processEngine.execute(new Command<Void>(){
+      processEngine.execute(new Command<Void>() {
         private static final long serialVersionUID = 1L;
+
         public Void execute(Environment environment) throws Exception {
           Session session = environment.get(Session.class);
-          DbHelper.executeSqlResource("create/jbpm."+database+".create.sql", session);
+          DbHelper.executeSqlResource("create/jbpm." + database + ".create.sql", session);
           PropertyImpl.createProperties(session);
           return null;
         }
       });
-
-      log.info("jBPM DB create completed successfully.");
-
-    } catch (Exception e) {
-      log.error("ERROR: jBPM DB create FAILED", e);
-
-    } finally {
+      log.info("database schema created successfully");
+    }
+    catch (Exception e) {
+      log.error("database schema creation failed", e);
+    }
+    finally {
       processEngine.close();
     }
   }

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-06-29 06:57:29 UTC (rev 6441)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/DbHelper.java	2010-06-29 17:57:11 UTC (rev 6442)
@@ -35,22 +35,26 @@
 /**
  * @author Tom Baeyens
  */
-public abstract class DbHelper {
-  
-  private static Log log = Log.getLog(DbHelper.class.getName());
+public class DbHelper {
 
+  private static final Log log = Log.getLog(DbHelper.class.getName());
+
+  private DbHelper() {
+    // hide default constructor to prevent instantiation
+  }
+
   public static void initializeLogging() {
-    Jdk14LogFactory.initializeJdk14Logging(); 
+    Jdk14LogFactory.initializeJdk14Logging();
   }
 
   public static void printSyntax(Class<?> clazz) {
-    log.info("Syntax: java -cp ... "+clazz.getName()+" database [delimiter]"); 
-    log.info("where database is one of {oracle, postgresql, mysql, hsqldb}"); 
+    log.info("Syntax: java -cp ... " + clazz.getName() + " database [delimiter]");
+    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);
+    InputStream stream = DbHelper.class.getClassLoader().getResourceAsStream(resource);
     if (stream == null) {
       throw new JbpmException("resource not found: " + resource);
     }
@@ -59,14 +63,15 @@
       byte[] bytes = IoUtil.readBytes(stream);
       String fileContents = new String(bytes);
       List<String> commands = extractCommands(fileContents);
-      
+
       log.info("--- Executing DB Commands -------------------------");
-      for (String command: commands) {
+      for (String command : commands) {
         log.info(command);
         try {
           int result = session.createSQLQuery(command).executeUpdate();
-          log.info("--- Result: "+result+" --------------------------");
-        } catch (Exception e) {
+          log.info("--- Result: " + result + " --------------------------");
+        }
+        catch (Exception e) {
           e.printStackTrace();
           log.info("-----------------------------------------------");
         }
@@ -83,16 +88,16 @@
   public static List<String> extractCommands(String fileContents) {
     List<String> commands = new ArrayList<String>();
     int i = 0;
-    while (i<fileContents.length()) {
+    while (i < fileContents.length()) {
       int j = fileContents.indexOf(";", i);
-      if (j==-1) {
+      if (j == -1) {
         j = fileContents.length();
       }
       String command = fileContents.substring(i, j).trim();
-      if (command.length()>0) {
+      if (command.length() > 0) {
         commands.add(command);
       }
-      i = j+1;
+      i = j + 1;
     }
     return commands;
   }

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-06-29 06:57:29 UTC (rev 6441)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/JbpmVersion.java	2010-06-29 17:57:11 UTC (rev 6442)
@@ -37,10 +37,6 @@
       dbVersion = dbVersion.substring(0, dbVersion.length() - 9);
     }
     return dbVersion.startsWith("4.") && dbVersion.length() > 2 ? valueOf("V_4_"
-        + dbVersion.substring(2)) : null;
+      + dbVersion.substring(2)) : null;
   }
-  
-  public boolean isEarlier(JbpmVersion other) {
-    return ordinal() < other.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-06-29 06:57:29 UTC (rev 6441)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Upgrade.java	2010-06-29 17:57:11 UTC (rev 6442)
@@ -30,12 +30,14 @@
 import org.jbpm.api.ProcessEngine;
 import org.jbpm.api.cmd.Command;
 import org.jbpm.api.cmd.Environment;
+import org.jbpm.api.cmd.VoidCommand;
 import org.jbpm.internal.log.Log;
 import org.jbpm.pvm.internal.cfg.ConfigurationImpl;
 import org.jbpm.pvm.internal.id.PropertyImpl;
 import org.jbpm.pvm.internal.processengine.ProcessEngineImpl;
 import org.jbpm.pvm.internal.repository.DeploymentImpl;
 import org.jbpm.pvm.internal.repository.DeploymentProperty;
+import org.jbpm.pvm.internal.util.CollectionUtil;
 
 /**
  * @author Tom Baeyens
@@ -44,122 +46,156 @@
 public class Upgrade {
 
   private static final long serialVersionUID = 1L;
-  
-  private static Log log = Log.getLog(Upgrade.class.getName());
-  
-  static String database;
-  static JbpmVersion jbpmVersion;
-  static boolean propertiesTableExists;
 
+  static final Log log = Log.getLog(Upgrade.class.getName());
+
+  private Upgrade() {
+    // hide default constructor to prevent instantiation
+  }
+
   public static void main(String[] args) {
-    if ( (args==null)
-         || (args.length!=1)
-       ) {
+    if (args.length != 1) {
       DbHelper.printSyntax(Upgrade.class);
       return;
     }
-    
-    database = args[0];
-    
-    ProcessEngine processEngine = new ConfigurationImpl()
-      .skipDbCheck()
-      .buildProcessEngine();
-  
+
+    String database = args[0];
+    ProcessEngine processEngine = new ConfigurationImpl().skipDbCheck().buildProcessEngine();
+
     try {
-      processEngine.execute(new Command<Object>(){
-        private static final long serialVersionUID = 1L;
-        public Object execute(Environment environment) throws Exception {
-          Session session = environment.get(Session.class);
-          propertiesTableExists = PropertyImpl.propertiesTableExists(session);
-          return null;
+      boolean propertiesTableExists = processEngine.execute(PropertiesTableExists.INSTANCE);
+      final JbpmVersion databaseVersion = processEngine.execute(new FindDatabaseVersion(propertiesTableExists));
+      JbpmVersion libraryVersion = JbpmVersion.getJbpmVersion(ProcessEngineImpl.JBPM_LIBRARY_VERSION);
+
+      if (databaseVersion == libraryVersion) {
+        log.info("database schema is already up to date");
+      }
+      else {
+        processEngine.execute(new RunUpgradeScripts(database, databaseVersion, propertiesTableExists));
+        processEngine.execute(new UpdateDatabaseVersion(databaseVersion));
+      }
+
+      log.info("database schema upgraded successfully");
+    }
+    catch (Exception e) {
+      log.error("database schema upgrade failed", e);
+    }
+    finally {
+      processEngine.close();
+    }
+  }
+
+  private static class PropertiesTableExists implements Command<Boolean> {
+
+    private static final long serialVersionUID = 1L;
+
+    static final PropertiesTableExists INSTANCE = new PropertiesTableExists();
+
+    public Boolean execute(Environment environment) throws Exception {
+      Session session = environment.get(Session.class);
+      return PropertyImpl.propertiesTableExists(session);
+    }
+  }
+
+  private static class FindDatabaseVersion implements Command<JbpmVersion> {
+
+    private final boolean propertiesTableExists;
+
+    private static final long serialVersionUID = 1L;
+
+    FindDatabaseVersion(boolean propertiesTableExists) {
+      this.propertiesTableExists = propertiesTableExists;
+    }
+
+    public JbpmVersion execute(Environment environment) throws Exception {
+      Session session = environment.get(Session.class);
+      if (!propertiesTableExists) {
+        try {
+          session.createSQLQuery("select CLASSNAME_ from JBPM4_VARIABLE").list();
+          return JbpmVersion.V_4_1;
         }
-      });
-      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 (!propertiesTableExists) {
-            try {
-              session.createSQLQuery("select CLASSNAME_ from JBPM4_VARIABLE").list();
-              jbpmVersion = JbpmVersion.V_4_1;
+        catch (HibernateException e) {
+          return 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");
+        }
+        return JbpmVersion.getJbpmVersion(dbVersion);
+      }
+    }
+  }
 
-            } catch (HibernateException e) {
-              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");
-            }
+  private static class RunUpgradeScripts extends VoidCommand {
 
-            jbpmVersion = JbpmVersion.getJbpmVersion(dbVersion);
-          }
-          return null;
+    private final JbpmVersion databaseVersion;
+    private final String database;
+    private final boolean propertiesTableExists;
+
+    private static final long serialVersionUID = 1L;
+
+    RunUpgradeScripts(String database, JbpmVersion databaseVersion,
+      boolean propertiesTableExists) {
+      this.database = database;
+      this.databaseVersion = databaseVersion;
+      this.propertiesTableExists = propertiesTableExists;
+    }
+
+    protected void executeVoid(Environment environment) throws Exception {
+      Session session = environment.get(Session.class);
+
+      log.info("upgrading from " + databaseVersion + " to "
+        + ProcessEngineImpl.JBPM_LIBRARY_VERSION);
+
+      if (databaseVersion.compareTo(JbpmVersion.V_4_1) < 0) {
+        DbHelper.executeSqlResource("upgrade-4.0-to-4.1/jbpm." + database + ".upgrade.sql", session);
+      }
+
+      if (databaseVersion.compareTo(JbpmVersion.V_4_2) < 0) {
+        // the first part of the upgrade to 4.2 might already be done before as that
+        // happens in the next transaction (and that next transaction might have failed in
+        // a previous run of upgrade)
+        // in that case, the next part is skipped
+        if (!propertiesTableExists) {
+          DbHelper.executeSqlResource("upgrade-4.1-to-4.2/jbpm." + database + ".upgrade.sql", session);
+          PropertyImpl.initializeNextDbid(session);
+          // we set the version to 4.1 as the next transaction might fail
+          PropertyImpl.setDbVersionTo41(session);
         }
-      });
+      }
+      // transaction is now committed as the next transaction requires the NextDbid
+      // property to be initialized and committed.
+    }
+  }
 
-      JbpmVersion currentJbpmVersion = JbpmVersion.getJbpmVersion(ProcessEngineImpl.JBPM_LIBRARY_VERSION);
-      if (jbpmVersion == currentJbpmVersion) {
-        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);
-            
-            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);
-            }
+  private static final class UpdateDatabaseVersion extends VoidCommand {
 
-            if (jbpmVersion.isEarlier(JbpmVersion.V_4_2)) {
-              // the first part of the upgrade to 4.2 might already be done before as that happens in the next transaction (and that next transaction might have failed in a previous run of upgrade)
-              // in that case, the next part is skipped
-              if (!propertiesTableExists) {
-                DbHelper.executeSqlResource("upgrade-4.1-to-4.2/jbpm." + database + ".upgrade.sql", session);
-                PropertyImpl.initializeNextDbid(session);
-                // we set the version to 4.1 as the next transaction might fail
-                PropertyImpl.setDbVersionTo41(session);
-              }
-            }
-            // transaction is now committed as the next transaction requires the NextDbid property to be initialized and committed.
-            return null;
-          }
-        });
+    private final JbpmVersion databaseVersion;
 
-        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 (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;
-          }
-        });
-      }      
+    private static final long serialVersionUID = 1L;
 
-      log.info("jBPM DB upgrade completed successfully.");
+    UpdateDatabaseVersion(JbpmVersion databaseVersion) {
+      this.databaseVersion = databaseVersion;
+    }
 
-    } catch (Exception e) {
-      log.error("ERROR: jBPM DB upgrade FAILED", e);
+    protected void executeVoid(Environment environment) throws Exception {
+      Session session = environment.get(Session.class);
 
-    } finally {
-      processEngine.close();
+      if (databaseVersion.compareTo(JbpmVersion.V_4_2) < 0) {
+        // find deployments without a langid property
+        List<?> deploymentProperties = session.createCriteria(DeploymentProperty.class)
+          .add(Restrictions.eq("key", DeploymentImpl.KEY_PROCESS_DEFINITION_ID))
+          .list();
+
+        for (DeploymentProperty deploymentProperty : CollectionUtil.checkList(deploymentProperties, DeploymentProperty.class)) {
+          DeploymentImpl deployment = deploymentProperty.getDeployment();
+          deployment.setProcessLanguageId(deploymentProperty.getObjectName(), "jpdl-4.0");
+        }
+      }
+
+      PropertyImpl.setDbVersionToLibraryVersion(session);
     }
   }
 }

Modified: jbpm4/trunk/modules/distro/scripts/assembly-distro.xml
===================================================================
--- jbpm4/trunk/modules/distro/scripts/assembly-distro.xml	2010-06-29 06:57:29 UTC (rev 6441)
+++ jbpm4/trunk/modules/distro/scripts/assembly-distro.xml	2010-06-29 17:57:11 UTC (rev 6442)
@@ -22,10 +22,11 @@
       <unpack>false</unpack>
     </dependencySet -->
     <dependencySet>
+      <outputDirectory>lib</outputDirectory>
       <outputFileNameMapping>${artifact.artifactId}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
       <!-- useStrictFiltering>true</useStrictFiltering -->
-      <unpack>false</unpack>
       <scope>test</scope>
+      <unpack>false</unpack>
       <excludes>
         <exclude>org.jbpm.jbpm4:jbpm-api:jar</exclude>
         <exclude>org.jbpm.jbpm4:jbpm-log:jar</exclude>
@@ -34,26 +35,23 @@
         <exclude>org.jbpm.jbpm4:jbpm-jpdl:jar</exclude>
         <exclude>org.jbpm.jbpm4:jbpm-enterprise:jar</exclude>
         <exclude>org.jbpm.jbpm4:jbpm-distro:jar</exclude>
-        <exclude>org.jbpm.jbpm4:jbpm-examples:jar</exclude>
         <exclude>org.jbpm.jbpm4:jbpm-gpd:zip</exclude>
         <exclude>org.jbpm.jbpm4.dependencies.signavio:jbpmeditor:war</exclude>
-        <exclude>org.jbpm.jbpm4:jbpm-test-db:jar</exclude>
       </excludes>
-      <outputDirectory>lib</outputDirectory>
     </dependencySet>
     <dependencySet>
+      <outputDirectory>install/src/gpd</outputDirectory>
+      <outputFileNameMapping>jbpm-gpd-site.zip</outputFileNameMapping>
       <includes>
         <include>org.jbpm.jbpm4:jbpm-gpd:zip</include>
       </includes>
-      <outputFileNameMapping>jbpm-gpd-site.zip</outputFileNameMapping>
-      <outputDirectory>install/src/gpd</outputDirectory>
     </dependencySet>
     <dependencySet>
+      <outputDirectory>install/src/signavio</outputDirectory>
+      <outputFileNameMapping>jbpmeditor.war</outputFileNameMapping>
       <includes>
         <include>org.jbpm.jbpm4.dependencies.signavio:jbpmeditor:war</include>
       </includes>
-      <outputFileNameMapping>jbpmeditor.war</outputFileNameMapping>
-      <outputDirectory>install/src/signavio</outputDirectory>
     </dependencySet>
   </dependencySets>
 

Modified: jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/async/ExclusiveMessagesTest.java
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/async/ExclusiveMessagesTest.java	2010-06-29 06:57:29 UTC (rev 6441)
+++ jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/async/ExclusiveMessagesTest.java	2010-06-29 17:57:11 UTC (rev 6442)
@@ -70,7 +70,7 @@
     commandService.execute(new VoidCommand() {
       private static final long serialVersionUID = 1L;
 
-      public void executeVoid(Environment environment) {
+      protected void executeVoid(Environment environment) {
         // exclusiveMessageIds maps execution keys to a set of thread ids.
         // the idea is that for each execution, all the exclusive jobs will
         // be executed by 1 thread sequentially.
@@ -101,7 +101,7 @@
     commandService.execute(new VoidCommand() {
       private static final long serialVersionUID = 1L;
 
-      public void executeVoid(Environment environment) {
+      protected void executeVoid(Environment environment) {
         ProcessDefinitionImpl processDefinition = ProcessDefinitionBuilder
         .startProcess("excl")
           .startActivity("wait", WaitState.class)
@@ -118,7 +118,7 @@
     commandService.execute(new VoidCommand() {
       private static final long serialVersionUID = 1L;
 
-      public void executeVoid(Environment environment) throws Exception {
+      protected void executeVoid(Environment environment) throws Exception {
         MessageSession messageSession = environment.get(MessageSession.class);
         for (int i = 0; i < nbrOfTestExecutions; i++) {
           Execution execution = new StartProcessInstanceCmd("excl:1", null, "execution-" + i).execute(environment);



More information about the jbpm-commits mailing list