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

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Sep 11 11:42:09 EDT 2009


Author: tom.baeyens at jboss.com
Date: 2009-09-11 11:42:08 -0400 (Fri, 11 Sep 2009)
New Revision: 5632

Added:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/AcquireIdBlockCmd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/DatabaseIdGenerator.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/IdGenerator.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/InitializePropertiesCmd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/MemoryIdGenerator.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/PropertyImpl.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/id/
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/id/IdGeneratorTest.java
Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/RefBinding.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ReferenceDescriptor.java
   jbpm4/trunk/modules/pvm/src/main/resources/jbpm.default.cfg.xml
   jbpm4/trunk/modules/pvm/src/main/resources/jbpm.repository.hbm.xml
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java
Log:
JBPM-2526 first cut at id generator

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/AcquireIdBlockCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/AcquireIdBlockCmd.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/AcquireIdBlockCmd.java	2009-09-11 15:42:08 UTC (rev 5632)
@@ -0,0 +1,39 @@
+package org.jbpm.pvm.internal.id;
+
+import org.hibernate.Session;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.cmd.Environment;
+
+/**
+ * @author Tom Baeyens
+ */
+public class AcquireIdBlockCmd implements Command<Long> {
+
+  private static final long serialVersionUID = 1L;
+  
+  long blocksize;
+  
+  public AcquireIdBlockCmd(long blocksize) {
+    this.blocksize = blocksize;
+  }
+
+  public Long execute(Environment environment) throws Exception {
+    Session session = environment.get(Session.class);
+    
+    PropertyImpl property = (PropertyImpl) session.createQuery(
+        "select property " +
+        "from "+PropertyImpl.class.getName()+" as property " +
+        "where property.key = '"+PropertyImpl.NEXT_ID_KEY+"'"
+    ).uniqueResult();
+    
+    String nextIdText = property.getValue();
+    Long nextId = new Long(nextIdText);
+    
+    property.setValue(Long.toString(nextId.longValue()+blocksize));
+    
+    session.update(property);
+    session.flush();
+
+    return nextId;
+  }
+}
\ No newline at end of file


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/AcquireIdBlockCmd.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/DatabaseIdGenerator.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/DatabaseIdGenerator.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/DatabaseIdGenerator.java	2009-09-11 15:42:08 UTC (rev 5632)
@@ -0,0 +1,103 @@
+/*
+ * 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.pvm.internal.id;
+
+import java.util.Random;
+
+import org.hibernate.StaleStateException;
+import org.jbpm.api.JbpmException;
+import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.cmd.CommandService;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class DatabaseIdGenerator extends IdGenerator {
+  
+  private static Log log = Log.getLog(DatabaseIdGenerator.class.getName());
+  
+  static Random random = new Random();
+
+  // configuration
+  CommandService commandService;
+  long blocksize = 10000;
+  int maxAttempts = 3;
+
+  // runtime state  
+  long lastId = -2;
+  long nextId = -1;
+  
+  public synchronized long getNextId() {
+    // if no more ids available
+    if (lastId<nextId) {
+      // acquire a next block of ids
+
+      // reset the id block
+      lastId = -2;
+      nextId = -1;
+      
+      // try couple of times 
+      try {
+        for ( int attempts = maxAttempts; (attempts>0) && (nextId==-1) ; attempts-- ) {
+          try {
+            // acquire block 
+            nextId = commandService.execute(new AcquireIdBlockCmd(blocksize));
+            lastId = nextId + blocksize - 1;
+            
+            log.debug("acquired new id block ["+nextId+"-"+lastId+"]");
+            
+          } catch (StaleStateException e) {
+            // optimistic locking exception indicating another thread tried to 
+            // acquire a block of ids concurrently  
+            attempts--;
+            
+            // if no attempts left
+            if (attempts==0) {
+              // fail the surrounding transaction
+              throw new JbpmException("couldn't acquire block of ids, tried "+maxAttempts+" times");
+            }
+            
+            // if there are still attempts left, first wait a bit
+            int millis = 20 + random.nextInt(200);
+            log.debug("optimistic locking failure while trying to acquire id block.  retrying in "+millis+" millis");
+            try {
+              Thread.sleep(millis);
+            } catch (InterruptedException e1) {
+              log.debug("waiting after id block locking failure got interrupted");
+            }
+          }
+        }
+      } catch (Exception e) {
+        throw new JbpmException("couldn't acquire block of ids", e);
+      }
+    }
+
+    return nextId++;
+  }
+  
+  public void initialize() {
+    nextId = commandService.execute(new InitializePropertiesCmd(blocksize));
+    lastId = nextId + blocksize - 1;
+    log.debug("initial id block ["+nextId+"-"+lastId+"]");
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/DatabaseIdGenerator.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/IdGenerator.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/IdGenerator.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/IdGenerator.java	2009-09-11 15:42:08 UTC (rev 5632)
@@ -0,0 +1,47 @@
+/*
+ * 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.pvm.internal.id;
+
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public abstract class IdGenerator {
+  
+  static IdGenerator defaultIdGenerator = new MemoryIdGenerator();
+
+  public static IdGenerator getIdGenerator() {
+    IdGenerator idGenerator = EnvironmentImpl.getFromCurrent(IdGenerator.class, false);
+    if (idGenerator!=null) {
+      return idGenerator;
+    }
+    return getDefaultIdGenerator();
+  }
+  
+  public static IdGenerator getDefaultIdGenerator() {
+    return defaultIdGenerator;
+  }
+
+  public abstract long getNextId(); 
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/IdGenerator.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/InitializePropertiesCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/InitializePropertiesCmd.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/InitializePropertiesCmd.java	2009-09-11 15:42:08 UTC (rev 5632)
@@ -0,0 +1,103 @@
+/*
+ * 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.pvm.internal.id;
+
+import org.hibernate.Session;
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.cmd.Environment;
+import org.jbpm.internal.log.Log;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class InitializePropertiesCmd implements Command<Long> {
+
+  private static final long serialVersionUID = 1L;
+
+  private static Log log = Log.getLog(InitializePropertiesCmd.class.getName());
+  
+  long blocksize;
+  
+  public InitializePropertiesCmd(long blocksize) {
+    this.blocksize = blocksize;
+  }
+
+  public Long execute(Environment environment) throws Exception {
+    Session session = environment.get(Session.class);
+    
+    Long nextId = initializeNextId(session);
+    initializeSchemaVersion(session);
+    
+    session.flush();
+
+    return nextId;
+  }
+
+  void initializeSchemaVersion(Session session) {
+    PropertyImpl property = (PropertyImpl) session.createQuery(
+        "select property " +
+        "from "+PropertyImpl.class.getName()+" as property " +
+        "where property.key = '"+PropertyImpl.SCHEMA_VERSION_KEY+"'"
+    ).uniqueResult();
+
+    String jbpmVersion = "4.1-SNAPSHOT";
+    
+    if (property==null) {
+      log.debug("initializing db schema version to "+jbpmVersion);
+      property = new PropertyImpl(PropertyImpl.SCHEMA_VERSION_KEY, jbpmVersion);
+      session.save(property);
+      
+    } else {
+      String dbSchemaVersion = property.getValue();
+      if (!jbpmVersion.equals(dbSchemaVersion)) {
+        throw new JbpmException("jBPM runtime version "+jbpmVersion+" doesn't match with DB schema, which is version ");
+      } else {
+        log.debug("runtime and db schema version both "+jbpmVersion);
+      }
+    }
+  }
+
+  Long initializeNextId(Session session) {
+    PropertyImpl property = (PropertyImpl) session.createQuery(
+        "select property " +
+        "from "+PropertyImpl.class.getName()+" as property " +
+        "where property.key = '"+PropertyImpl.NEXT_ID_KEY+"'"
+    ).uniqueResult();
+    
+    Long nextId;
+    if (property==null) {
+      nextId = 1L;
+      property = new PropertyImpl(PropertyImpl.NEXT_ID_KEY, Long.toString(blocksize+1));
+      session.save(property);
+      
+    } else {
+      String nextIdText = property.getValue();
+      nextId = new Long(nextIdText);
+      property.setValue(Long.toString(nextId.longValue()+blocksize));
+      session.update(property);
+    }
+    
+    return nextId;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/InitializePropertiesCmd.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/MemoryIdGenerator.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/MemoryIdGenerator.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/MemoryIdGenerator.java	2009-09-11 15:42:08 UTC (rev 5632)
@@ -0,0 +1,36 @@
+/*
+ * 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.pvm.internal.id;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class MemoryIdGenerator extends IdGenerator {
+
+  static long nextId = 1;
+  
+  public synchronized long getNextId() {
+    return nextId++;
+  }
+
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/MemoryIdGenerator.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: 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	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/PropertyImpl.java	2009-09-11 15:42:08 UTC (rev 5632)
@@ -0,0 +1,59 @@
+/*
+ * 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.pvm.internal.id;
+
+
+/** 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 {
+  
+  public static final String SCHEMA_VERSION_KEY = "schema.version";
+  public static final String NEXT_ID_KEY = "next.id";
+
+  protected int version;
+  protected String key;
+  protected String value;
+  
+  protected PropertyImpl() {
+  }
+
+  public PropertyImpl(String key, String value) {
+    this.key = key;
+    this.value = value;
+  }
+
+  public String getKey() {
+    return key;
+  }
+  public String getValue() {
+    return value;
+  }
+  public void setValue(String value) {
+    this.value = value;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/PropertyImpl.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/RefBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/RefBinding.java	2009-09-11 15:11:04 UTC (rev 5631)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/RefBinding.java	2009-09-11 15:42:08 UTC (rev 5632)
@@ -44,6 +44,9 @@
     ReferenceDescriptor descriptor = new ReferenceDescriptor();
     if (element.hasAttribute("object")) {
       descriptor.setValue(element.getAttribute("object"));
+    } else if (element.hasAttribute("type")) {
+      descriptor.setType(element.getAttribute("type"));
+      
     } else {
       parse.addProblem("ref must have object attribute: "+XmlUtil.toString(element), element);
     }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ReferenceDescriptor.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ReferenceDescriptor.java	2009-09-11 15:11:04 UTC (rev 5631)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ReferenceDescriptor.java	2009-09-11 15:42:08 UTC (rev 5632)
@@ -1,5 +1,6 @@
 package org.jbpm.pvm.internal.wire.descriptor;
 
+import org.jbpm.api.JbpmException;
 import org.jbpm.pvm.internal.wire.Descriptor;
 import org.jbpm.pvm.internal.wire.WireContext;
 
@@ -19,6 +20,7 @@
   private static final long serialVersionUID = 1L;
 
   String text = null;
+  String type = null;
 
   // TODO add a refExpression that is evaluated with el
   // the base referenced descriptor always should have delayedInitialization = false;
@@ -31,14 +33,26 @@
   }
 
   public Object construct(WireContext wireContext) {
-    return wireContext.get(text, isDelayedInitializationAllowed());
+    if (text!=null) {
+      return wireContext.get(text, isDelayedInitializationAllowed());
+    } else if (type!=null) {
+      try {
+        Class<?> clazz = wireContext.getClassLoader().loadClass(type);
+        return wireContext.get(clazz);
+      } catch (Exception e) {
+        throw new JbpmException("couldn't load "+type, e);
+      }
+    }
+    return null;
   }
 
   public boolean isDelayedInitializationAllowed() {
     return (init == INIT_EAGER || init == INIT_LAZY);
   }
-
   public void setValue(String objectName) {
     this.text = objectName;
   }
+  public void setType(String type) {
+    this.type = type;
+  }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.default.cfg.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.default.cfg.xml	2009-09-11 15:11:04 UTC (rev 5631)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.default.cfg.xml	2009-09-11 15:42:08 UTC (rev 5632)
@@ -17,6 +17,11 @@
     </hibernate-configuration>
 
     <hibernate-session-factory />
+    
+    <object class="org.jbpm.pvm.internal.id.DatabaseIdGenerator" init="eager">
+      <field name="commandService"><ref type="org.jbpm.pvm.internal.cmd.CommandService" /></field>
+      <invoke method="initialize" />
+    </object>
 
     <script-manager default-expression-language="juel"
                     default-script-language="juel">

Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.repository.hbm.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.repository.hbm.xml	2009-09-11 15:11:04 UTC (rev 5631)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.repository.hbm.xml	2009-09-11 15:42:08 UTC (rev 5632)
@@ -48,4 +48,12 @@
     <property name="longValue" column="LONGVAL_" />
   </class> 
 
+  <class name="org.jbpm.pvm.internal.id.PropertyImpl" table="JBPM4_PROPERTY">
+    <id name="key" column="KEY_">
+      <generator class="assigned" />
+    </id>
+    <version name="version" column="VERSION_" />
+    <property name="value" column="VALUE_" />
+  </class> 
+
 </hibernate-mapping>

Added: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/id/IdGeneratorTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/id/IdGeneratorTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/id/IdGeneratorTest.java	2009-09-11 15:42:08 UTC (rev 5632)
@@ -0,0 +1,61 @@
+/*
+ * 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.pvm.internal.id;
+
+import junit.framework.TestCase;
+
+import org.hibernate.Session;
+import org.jbpm.api.Configuration;
+import org.jbpm.api.ProcessEngine;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.cmd.Environment;
+import org.jbpm.pvm.internal.cmd.CommandService;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class IdGeneratorTest extends TestCase {
+  
+  public void testIdGenerator() {
+    ProcessEngine processEngine = new Configuration().buildProcessEngine();
+    
+    CommandService commandService = processEngine.get(CommandService.class);
+    commandService.execute(new Command<Void>() {
+      private static final long serialVersionUID = 1L;
+      public Void execute(Environment environment) throws Exception {
+        Session session = environment.get(Session.class);
+        assertEquals(2, session.createQuery("select property from "+PropertyImpl.class.getName()+" as property").list().size());
+        return null;
+      }
+    });
+    
+    IdGenerator idGenerator = processEngine.get(IdGenerator.class);
+    
+    for (int i=1; i<10020; i++) {
+      assertEquals(i, idGenerator.getNextId());
+      if ((i%100) == 0) {
+        System.err.println(i);
+      }
+    }
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/id/IdGeneratorTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java	2009-09-11 15:11:04 UTC (rev 5631)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java	2009-09-11 15:42:08 UTC (rev 5632)
@@ -171,12 +171,14 @@
     Session session = sessionFactory.openSession();
     try {
       for (String tableName : tableNames) {
-        String countSql = "select count(*) as RECORD_COUNT_ from "+tableName;
-        SQLQuery sqlQuery = session.createSQLQuery(countSql);
-        sqlQuery.addScalar("RECORD_COUNT_", Hibernate.LONG);
-        Long recordCount = (Long) sqlQuery.uniqueResult();
-        if (recordCount>0L) {
-          recordsLeftMsg += tableName+":"+recordCount+", ";
+        if (!"JBPM4_PROPERTY".equals(tableName)) {
+          String countSql = "select count(*) as RECORD_COUNT_ from "+tableName;
+          SQLQuery sqlQuery = session.createSQLQuery(countSql);
+          sqlQuery.addScalar("RECORD_COUNT_", Hibernate.LONG);
+          Long recordCount = (Long) sqlQuery.uniqueResult();
+          if (recordCount>0L) {
+            recordsLeftMsg += tableName+":"+recordCount+", ";
+          }
         }
       }
     } finally {



More information about the jbpm-commits mailing list