[jbpm-commits] JBoss JBPM SVN: r6607 - in jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal: hibernate and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Aug 18 05:40:27 EDT 2010


Author: rebody
Date: 2010-08-18 05:40:27 -0400 (Wed, 18 Aug 2010)
New Revision: 6607

Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/CheckDbCmd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java
   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/session/DbSession.java
Log:
JBPM-2927 move check table method to DbSession.


Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/CheckDbCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/CheckDbCmd.java	2010-08-18 08:12:55 UTC (rev 6606)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/CheckDbCmd.java	2010-08-18 09:40:27 UTC (rev 6607)
@@ -30,6 +30,7 @@
 import org.jbpm.pvm.internal.id.PropertyImpl;
 import org.jbpm.pvm.internal.model.ExecutionImpl;
 import org.jbpm.pvm.internal.processengine.ProcessEngineImpl;
+import org.jbpm.pvm.internal.session.DbSession;
 
 /**
  * @author Tom Baeyens
@@ -37,59 +38,48 @@
 public class CheckDbCmd implements Command<Object> {
 
   private static final long serialVersionUID = 1L;
-  
+
   private static Log log = Log.getLog(CheckDbCmd.class.getName());
 
   public Object execute(Environment environment) throws Exception {
+    DbSession dbSession = EnvironmentImpl.getFromCurrent(DbSession.class);
     Session session = EnvironmentImpl.getFromCurrent(Session.class);
 
-    // if table JBPM4_PROPERTIES doesn't exist, 
-    if (!PropertyImpl.propertiesTableExists(session)) {
-      if (!executionTableExists(session)) {
+    // if table JBPM4_PROPERTIES doesn't exist,
+    if (!dbSession.propertiesTableExists()) {
+      if (!dbSession.executionTableExists()) {
         // tell users to run create.schema
         throw new JbpmException("no jBPM DB schema: no JBPM4_EXECUTION table.   Run the create.jbpm.schema target first in the install tool.");
-        
+
       } else {
         // tell users to run upgrade
         throw new JbpmException("jBPM DB schema not in sync with library version: no JBPM4_PROPERTIES table.   Run the upgrade target first in the install tool.");
       }
-      
+
     } else {
       Long nextDbid = PropertyImpl.getNextDbid(session);
-      // if there is no next.dbid property specified 
-      if (nextDbid==null) {
+      // if there is no next.dbid property specified
+      if (nextDbid == null) {
         // (this only happens in the test suite)
-        // initialize the dbid property.  
+        // initialize the dbid property.
         PropertyImpl.setNextDbid(session, 1);
       }
     }
 
     // verify if DB version matches with library version,
     String dbVersion = PropertyImpl.getDbVersion(session);
-    log.info("jBPM version info: library["+ProcessEngineImpl.JBPM_LIBRARY_VERSION+"], schema["+dbVersion+"]");
+    if (log.isInfoEnabled()) {
+      log.info("jBPM version info: library[" + ProcessEngineImpl.JBPM_LIBRARY_VERSION + "], schema[" + dbVersion + "]");
+    }
 
-    if ( (dbVersion!=null) 
+    if ( (dbVersion != null)
          && (!dbVersion.equals(ProcessEngineImpl.JBPM_LIBRARY_VERSION))
        ) {
       // tell users to run upgrade
-      throw new JbpmException("jBPM DB schema version ("+dbVersion+") differs from jBPM library version ("+ProcessEngineImpl.JBPM_LIBRARY_VERSION+"): run the upgrade tool first.");
+      throw new JbpmException("jBPM DB schema version (" + dbVersion + ") differs from jBPM library version ("
+        + ProcessEngineImpl.JBPM_LIBRARY_VERSION + "): run the upgrade tool first.");
     }
 
     return null;
   }
-  
-  public static boolean executionTableExists(Session session) {
-    try {
-      session.createQuery("from "+ExecutionImpl.class.getName())
-        .setMaxResults(1)
-        .uniqueResult();
-      return true;
-      
-    } catch (Exception e) {
-      return false;
-    }
-  }
-
-
-
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java	2010-08-18 08:12:55 UTC (rev 6606)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java	2010-08-18 09:40:27 UTC (rev 6607)
@@ -42,6 +42,7 @@
 import org.jbpm.pvm.internal.history.model.HistoryCommentImpl;
 import org.jbpm.pvm.internal.history.model.HistoryProcessInstanceImpl;
 import org.jbpm.pvm.internal.id.DbidGenerator;
+import org.jbpm.pvm.internal.id.PropertyImpl;
 import org.jbpm.pvm.internal.job.JobImpl;
 import org.jbpm.pvm.internal.job.StartProcessTimer;
 import org.jbpm.pvm.internal.job.TimerImpl;
@@ -396,4 +397,29 @@
       .list();
     return CollectionUtil.checkList(timers, Timer.class);
   }
+
+  /** check table. */
+  public boolean executionTableExists() {
+    try {
+      session.createQuery("from " + ExecutionImpl.class.getName())
+        .setMaxResults(1)
+        .uniqueResult();
+      return true;
+
+    } catch (Exception e) {
+      return false;
+    }
+  }
+
+  public boolean propertiesTableExists() {
+    try {
+      session.createQuery("from " + PropertyImpl.class.getName())
+        .setMaxResults(1)
+        .uniqueResult();
+      return true;
+
+    } catch (Exception e) {
+      return false;
+    }
+  }
 }

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-08-18 08:12:55 UTC (rev 6606)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/PropertyImpl.java	2010-08-18 09:40:27 UTC (rev 6607)
@@ -46,24 +46,24 @@
 import org.jbpm.pvm.internal.type.Variable;
 
 /** jbpm installation properties.
- * 
+ *
  * currently there are 2 use cases for these properties:
  *  1) include the jbpm schema version into the DB
  *  2) have a record to maintain the next dbid for the id generator
- *   
+ *
  * @author Tom Baeyens
  */
 public class PropertyImpl {
-  
+
   private static Log log = Log.getLog(PropertyImpl.class.getName());
-  
+
   public static final String DB_VERSION_KEY = "db.version";
   public static final String NEXT_DBID_KEY = "next.dbid";
 
   protected int version;
   protected String key;
   protected String value;
-  
+
   protected PropertyImpl() {
   }
 
@@ -71,10 +71,10 @@
     this.key = key;
     this.value = value;
   }
-  
+
   public static Long getNextDbid(Session session) {
     String dbidPropertyValue = getPropertyValue(session, PropertyImpl.NEXT_DBID_KEY);
-    if (dbidPropertyValue!=null) {
+    if (dbidPropertyValue != null) {
       return Long.valueOf(dbidPropertyValue);
     }
     return null;
@@ -86,7 +86,7 @@
 
   public static String getDbVersion(Session session) {
     String dbVersionPropertyValue = getPropertyValue(session, PropertyImpl.DB_VERSION_KEY);
-    if (dbVersionPropertyValue!=null) {
+    if (dbVersionPropertyValue != null) {
       return dbVersionPropertyValue;
     }
     return null;
@@ -102,26 +102,16 @@
   }
 
   public static void initializeNextDbid(Session session) {
-    long nextDbid = getMaxDbid(session)+1;
+    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())
-        .setMaxResults(1)
-        .uniqueResult();
-      return true;
-      
-    } catch (Exception e) {
-      return false;
+    if (log.isInfoEnabled()) {
+      log.info("nextDbid is initialized to " + nextDbid);
     }
   }
 
   protected static long getMaxDbid(Session session) {
     long maxDbid = 0;
-    
+
     List<String> persistedTypes = new ArrayList<String>();
     persistedTypes.add(DeploymentImpl.class.getName());
     persistedTypes.add(DeploymentProperty.class.getName());
@@ -139,21 +129,21 @@
     persistedTypes.add(TaskImpl.class.getName());
     persistedTypes.add(UserImpl.class.getName());
     persistedTypes.add(Variable.class.getName());
-    
+
     for (String persistedType: persistedTypes) {
       try {
         Long typeMaxDbid = (Long) session.createQuery(
                 "select max(o.dbid) " +
-                "from "+persistedType+" as o"
+                "from " + persistedType + " as o"
             ).uniqueResult();
-        
+
         if ( (typeMaxDbid!=null)
-             && (typeMaxDbid.longValue()>maxDbid) 
+             && (typeMaxDbid.longValue()>maxDbid)
            ) {
           maxDbid = typeMaxDbid.longValue();
         }
       } catch (Exception e) {
-        log.info("couldn't get max dbid for "+persistedType, e);
+        log.info("couldn't get max dbid for " + persistedType, e);
         e.printStackTrace();
       }
     }
@@ -163,7 +153,7 @@
 
   protected static String getPropertyValue(Session session, String propertyKey) {
     PropertyImpl dbidProperty = getProperty(session, propertyKey);
-    if (dbidProperty==null) {
+    if (dbidProperty == null) {
       return null;
     }
     return dbidProperty.getValue();
@@ -171,7 +161,7 @@
 
   protected static void setPropertyValue(Session session, String propertyKey, String propertyValue) {
     PropertyImpl property = getProperty(session, propertyKey);
-    if (property==null) {
+    if (property == null) {
       property = new PropertyImpl(propertyKey, propertyValue);
       session.save(property);
     } else {

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java	2010-08-18 08:12:55 UTC (rev 6606)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java	2010-08-18 09:40:27 UTC (rev 6607)
@@ -112,4 +112,8 @@
 
   /** retrieve all the outstanding timers associated for the given execution */
   List<Timer> findTimersByExecution(Execution execution);
+
+  /** check table. */
+  boolean executionTableExists();
+  boolean propertiesTableExists();
 }



More information about the jbpm-commits mailing list