[jbpm-commits] JBoss JBPM SVN: r5232 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src: main/java/org/jbpm/graph/def and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Sun Jul 5 09:42:54 EDT 2009


Author: alex.guizar at jboss.com
Date: 2009-07-05 09:42:53 -0400 (Sun, 05 Jul 2009)
New Revision: 5232

Added:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/SybaseRowLockDialect.java
Removed:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/StringMax.java
Modified:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/Converters.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/JbpmNamingStrategy.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/hibernate.properties.mysql.xml
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/hibernate.properties.sybase.xml
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/SerializabilityTest.java
Log:
extend sybase dialect in order to specify datarows locking in create table statements


Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/Converters.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/Converters.java	2009-07-05 11:06:02 UTC (rev 5231)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/Converters.java	2009-07-05 13:42:53 UTC (rev 5232)
@@ -38,7 +38,7 @@
 /**
  * provides access to the list of converters and ensures that the converter objects are unique.
  */
-public abstract class Converters {
+public class Converters {
 
   static final int CONVERTERS_BY_CLASS_NAMES = 0;
   static final int CONVERTERS_BY_DATABASE_ID = 1;
@@ -46,14 +46,18 @@
 
   static Map converterMapsMap = new HashMap();
 
+  private Converters() {
+    // prevent instantiation
+  }
+
   // public methods
 
   public static Converter getConverterByClassName(String className) {
     Converter converter = (Converter) getConvertersByClassNames().get(className);
     if (converter == null) {
-      throw new JbpmException("converter '"
-          + className
-          + "' is not declared in jbpm.converter.properties");
+      throw new JbpmException("converter '" +
+          className +
+          "' is not declared in jbpm.converter.properties");
     }
     return converter;
   }
@@ -71,7 +75,7 @@
     return getConverterMaps()[CONVERTERS_BY_CLASS_NAMES];
   }
 
-  // maps converter database-id-strings to unique converter objects 
+  // maps converter database-id-strings to unique converter objects
   static Map getConvertersByDatabaseId() {
     return getConverterMaps()[CONVERTERS_BY_DATABASE_ID];
   }
@@ -130,7 +134,8 @@
         convertersIds.put(converter, converterDatabaseId);
       }
       catch (Exception e) {
-        // NOTE that Error's are not caught because that might halt the JVM and mask the original Error.
+        // NOTE that Error's are not caught because that might halt the JVM and mask the original
+        // Error.
         log.debug("couldn't instantiate converter '" + converterClassName + "': " + e);
       }
     }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/JbpmNamingStrategy.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/JbpmNamingStrategy.java	2009-07-05 11:06:02 UTC (rev 5231)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/JbpmNamingStrategy.java	2009-07-05 13:42:53 UTC (rev 5232)
@@ -21,7 +21,7 @@
  */
 package org.jbpm.db.hibernate;
 
-import org.hibernate.cfg.*;
+import org.hibernate.cfg.NamingStrategy;
 
 public class JbpmNamingStrategy implements NamingStrategy {
 

Deleted: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/StringMax.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/StringMax.java	2009-07-05 11:06:02 UTC (rev 5231)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/StringMax.java	2009-07-05 13:42:53 UTC (rev 5232)
@@ -1,47 +0,0 @@
-package org.jbpm.db.hibernate;
-
-// $Id$
-
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.Properties;
-
-import org.hibernate.type.StringType;
-import org.hibernate.usertype.ParameterizedType;
-import org.jbpm.JbpmException;
-
-/**
- * A custom type that truncates string values
- */
-public class StringMax extends StringType implements ParameterizedType
-{
-  private static final long serialVersionUID = 1L;
-
-  int length = 4000;
-
-  public void set(PreparedStatement st, Object value, int index) throws SQLException
-  {
-    String string = (String)value;
-    if (string != null && string.length() > length)
-    {
-      string = string.substring(0, length);
-    }
-    super.set(st, string, index);
-  }
-
-  public void setParameterValues(Properties parameters)
-  {
-    if (parameters != null && parameters.containsKey("length"))
-    {
-      String propval = parameters.getProperty("length");
-      try
-      {
-        length = Integer.parseInt(propval);
-      }
-      catch (NumberFormatException e)
-      {
-        throw new JbpmException("hibernate column type 'string_max' can't parse value '" + propval + "' as a max length.  default is 4000.", e);
-      }
-    }
-  }
-}

Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/SybaseRowLockDialect.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/SybaseRowLockDialect.java	                        (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/SybaseRowLockDialect.java	2009-07-05 13:42:53 UTC (rev 5232)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.db.hibernate;
+
+import org.hibernate.dialect.SybaseDialect;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class SybaseRowLockDialect extends SybaseDialect {
+
+  public String getTableTypeString() {
+    return " lock datarows";
+  }
+
+}

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java	2009-07-05 11:06:02 UTC (rev 5231)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java	2009-07-05 13:42:53 UTC (rev 5232)
@@ -21,6 +21,9 @@
  */
 package org.jbpm.graph.def;
 
+import java.io.InvalidObjectException;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -49,10 +52,12 @@
 
   private static final long serialVersionUID = 1L;
 
-  public static class NodeType {
+  public static class NodeType implements Serializable {
 
     private final String name;
 
+    private static final long serialVersionUID = 1L;
+
     public static final NodeType Node = new NodeType("Node");
     public static final NodeType StartState = new NodeType("StartState");
     public static final NodeType EndState = new NodeType("EndState");
@@ -69,6 +74,20 @@
     public String toString() {
       return name;
     }
+
+    public static NodeType valueOf(String name) {
+      return Node.name.equals(name) ? Node : StartState.name.equals(name) ? StartState
+          : EndState.name.equals(name) ? EndState : State.name.equals(name) ? State
+              : Task.name.equals(name) ? Task : Fork.name.equals(name) ? Fork
+                  : Join.name.equals(name) ? Join : Decision.name.equals(name) ? Decision : null;
+    }
+
+    private Object readResolve() throws ObjectStreamException {
+      NodeType nodeType = valueOf(name);
+      if (nodeType == null) throw new InvalidObjectException("invalid node type: " + name);
+      return nodeType;
+    }
+
   };
 
   protected List leavingTransitions = null;
@@ -270,9 +289,9 @@
    * moves one leaving transition from the oldIndex and inserts it at the newIndex.
    */
   public void reorderLeavingTransition(int oldIndex, int newIndex) {
-    if (leavingTransitions != null
-        && Math.min(oldIndex, newIndex) >= 0
-        && Math.max(oldIndex, newIndex) < leavingTransitions.size()) {
+    if (leavingTransitions != null &&
+        Math.min(oldIndex, newIndex) >= 0 &&
+        Math.max(oldIndex, newIndex) < leavingTransitions.size()) {
       Object transition = leavingTransitions.remove(oldIndex);
       leavingTransitions.add(newIndex, transition);
     }
@@ -341,7 +360,8 @@
     // fire the leave-node event for this node
     fireEvent(Event.EVENTTYPE_NODE_ENTER, executionContext);
 
-    // keep track of node entrance in the token, so that a node-log can be generated at node leave time.
+    // keep track of node entrance in the token, so that a node-log can be generated at node leave
+    // time.
     token.setNodeEnter(Clock.getCurrentTime());
 
     // remove the transition references from the runtime context
@@ -380,7 +400,8 @@
 
       }
       catch (Exception exception) {
-        // NOTE that Error's are not caught because that might halt the JVM and mask the original Error.
+        // NOTE that Error's are not caught because that might halt the JVM and mask the original
+        // Error.
         // search for an exception handler or throw to the client
         raiseException(exception, executionContext);
       }
@@ -406,11 +427,11 @@
   public void leave(ExecutionContext executionContext, String transitionName) {
     Transition transition = getLeavingTransition(transitionName);
     if (transition == null) {
-      throw new JbpmException("transition '"
-          + transitionName
-          + "' is not a leaving transition of node '"
-          + this
-          + "'");
+      throw new JbpmException("transition '" +
+          transitionName +
+          "' is not a leaving transition of node '" +
+          this +
+          "'");
     }
     leave(executionContext, transition);
   }
@@ -464,12 +485,11 @@
       String oldName = this.name;
       if (superState != null) {
         if (superState.hasNode(name)) {
-          throw new IllegalArgumentException(
-              "couldn't set name '"
-                  + name
-                  + "' on node '"
-                  + this
-                  + "'cause the superState of this node has already another child node with the same name");
+          throw new IllegalArgumentException("couldn't set name '" +
+              name +
+              "' on node '" +
+              this +
+              "'cause the superState of this node has already another child node with the same name");
         }
         Map nodes = superState.getNodesMap();
         nodes.remove(oldName);
@@ -477,12 +497,11 @@
       }
       else if (processDefinition != null) {
         if (processDefinition.hasNode(name)) {
-          throw new IllegalArgumentException(
-              "couldn't set name '"
-                  + name
-                  + "' on node '"
-                  + this
-                  + "'cause the process definition of this node has already another node with the same name");
+          throw new IllegalArgumentException("couldn't set name '" +
+              name +
+              "' on node '" +
+              this +
+              "'cause the process definition of this node has already another node with the same name");
         }
         Map nodeMap = processDefinition.getNodesMap();
         nodeMap.remove(oldName);

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/hibernate.properties.mysql.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/hibernate.properties.mysql.xml	2009-07-05 11:06:02 UTC (rev 5231)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/hibernate.properties.mysql.xml	2009-07-05 13:42:53 UTC (rev 5232)
@@ -1,6 +1,6 @@
 
     <!-- hibernate dialect -->
-    <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
+    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
 
     <!-- JDBC connection properties (begin) -->
     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/hibernate.properties.sybase.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/hibernate.properties.sybase.xml	2009-07-05 11:06:02 UTC (rev 5231)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/hibernate.properties.sybase.xml	2009-07-05 13:42:53 UTC (rev 5232)
@@ -10,7 +10,7 @@
     -->
 
     <!-- hibernate dialect -->
-    <property name="hibernate.dialect">org.hibernate.dialect.SybaseDialect</property>
+    <property name="hibernate.dialect">org.jbpm.db.hibernate.SybaseRowLockDialect</property>
 
     <!-- JDBC connection properties (begin) -->
     <property name="hibernate.connection.driver_class">${jdbc.sybase.driver}</property>

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/SerializabilityTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/SerializabilityTest.java	2009-07-05 11:06:02 UTC (rev 5231)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/SerializabilityTest.java	2009-07-05 13:42:53 UTC (rev 5232)
@@ -23,6 +23,7 @@
 
 import java.io.File;
 import java.io.Serializable;
+import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
 import org.jbpm.file.def.FileDefinitionFileSystemConfigTest;
@@ -37,7 +38,7 @@
       .toString();
 
   static final String[] excusedClasses = { "org.jbpm.ant", "org.jbpm.context.exe.JbpmType",
-      "org.jbpm.db.hibernate.ConverterEnumType", "org.jbpm.db.hibernate.Converters",
+      "org.jbpm.db.hibernate.ConverterEnumType", "org.jbpm.db.hibernate.SybaseRowLockDialect",
       "org.jbpm.db.hibernate.JbpmNamingStrategy", "org.jbpm.db.AbstractDbTestCase",
       "org.jbpm.db.ContextSession", "org.jbpm.db.FileSession", "org.jbpm.db.GraphSession",
       "org.jbpm.db.JbpmSession", "org.jbpm.db.JbpmSchema", "org.jbpm.db.JobSession",
@@ -65,22 +66,21 @@
       "org.jbpm.security.filter.JbpmAuthenticationFilter",
       "org.jbpm.command.service.CommandServiceImpl", "org.jbpm.sim.", "org.jbpm.util.Clock",
       "org.jbpm.util.CustomLoaderObjectInputStream", "org.jbpm.web.JobExecutorLauncher",
-      "org.jbpm.web.JbpmConfigurationCloser", "org.jbpm.JbpmContextTestHelper",
-      "org.jbpm.EventCallback$1" };
+      "org.jbpm.web.JbpmConfigurationCloser", "org.jbpm.JbpmContextTestHelper", };
 
   public void testForNonSerializableClasses() {
     File jbpmRoot = new File(testRootDir + "../classes/");
     scanForClasses(jbpmRoot, "");
   }
 
-  private void scanForClasses(File rootClassDir, String packageDir) {
+  private static void scanForClasses(File rootClassDir, String packageDir) {
     File packageDirFile = new File(rootClassDir.getPath() + "/" + packageDir);
     File[] files = packageDirFile.listFiles();
     for (int i = 0; i < files.length; i++) {
       if (files[i].isDirectory()) {
-        String newPackageDir = ("".equals(packageDir) ? files[i].getName() : packageDir
-            + "/"
-            + files[i].getName());
+        String newPackageDir = ("".equals(packageDir) ? files[i].getName() : packageDir +
+            "/" +
+            files[i].getName());
         // log.debug("descending into directory "+newPackageDir);
         scanForClasses(rootClassDir, newPackageDir);
 
@@ -95,17 +95,36 @@
     }
   }
 
-  private void assertSerializabilityOfClass(String className) {
+  private static void assertSerializabilityOfClass(String className) {
     Class clazz = ClassLoaderUtil.classForName(className);
 
-    if (!(Serializable.class.isAssignableFrom(clazz)
-        || Modifier.isAbstract(clazz.getModifiers())
-        || isExcused(className) || clazz.getConstructors().length == 0)) {
+    if (!(Serializable.class.isAssignableFrom(clazz) ||
+        Modifier.isAbstract(clazz.getModifiers()) ||
+        isAnonymous(clazz) ||
+        isUtility(clazz) || isExcused(className))) {
       fail(className + " is NOT Serializable");
     }
   }
 
-  boolean isExcused(String className) {
+  private static boolean isAnonymous(Class clazz) {
+    return clazz.getName().matches(".*\\$\\d+");
+  }
+
+  /**
+   * Tells whether the given class consists exclusively of static methods and has no public
+   * constructors.
+   */
+  private static boolean isUtility(Class clazz) {
+    Method[] methods = clazz.getMethods();
+    for (int i = 0; i < methods.length; i++) {
+      Method method = methods[i];
+      if (!Modifier.isStatic(method.getModifiers()) && method.getDeclaringClass() != Object.class)
+        return false;
+    }
+    return clazz.getConstructors().length == 0;
+  }
+
+  private static boolean isExcused(String className) {
     for (int i = 0; i < excusedClasses.length; i++) {
       if (className.startsWith(excusedClasses[i])) return true;
     }




More information about the jbpm-commits mailing list