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

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Mar 4 02:33:35 EST 2010


Author: alex.guizar at jboss.com
Date: 2010-03-04 02:33:35 -0500 (Thu, 04 Mar 2010)
New Revision: 6208

Added:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2637/
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2637/JBPM2637Test.java
Modified:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/GraphSession.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/TaskMgmtSession.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/JbpmPersistenceException.java
Log:
JBPM-2637: check for empty taskInstanceIds list in TaskMgmtSession.findTaskInstancesByIds

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/GraphSession.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/GraphSession.java	2010-03-03 19:06:53 UTC (rev 6207)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/GraphSession.java	2010-03-04 07:33:35 UTC (rev 6208)
@@ -27,10 +27,9 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.hibernate.HibernateException;
 import org.hibernate.LockMode;
+import org.hibernate.ObjectNotFoundException;
 import org.hibernate.Session;
 import org.hibernate.criterion.Restrictions;
 
@@ -42,7 +41,7 @@
 import org.jbpm.persistence.JbpmPersistenceException;
 
 /**
- * are the graph related database operations.
+ * graph-related database operations.
  */
 public class GraphSession {
 
@@ -63,32 +62,34 @@
 
   // process definitions //////////////////////////////////////////////////////
 
+  /**
+   * assigns a version number to the given process definition and then makes it
+   * persistent.
+   */
   public void deployProcessDefinition(ProcessDefinition processDefinition) {
-    String processDefinitionName = processDefinition.getName();
     // versioning applies to named process definitions only
-    if (processDefinitionName != null) {
-      // find the current latest process definition
-      ProcessDefinition previousLatestVersion = findLatestProcessDefinition(processDefinitionName);
-      // if there is a current latest process definition
-      if (previousLatestVersion != null) {
-        // take the next version number
-        processDefinition.setVersion(previousLatestVersion.getVersion() + 1);
-      }
-      else {
-        // start from 1
-        processDefinition.setVersion(1);
-      }
-      session.save(processDefinition);
+    String processName = processDefinition.getName();
+    if (processName == null) {
+      throw new JbpmException("process definition has no name");
     }
+    // find the current latest process definition
+    ProcessDefinition previousLatestVersion = findLatestProcessDefinition(processName);
+    // if there is a current latest process definition
+    if (previousLatestVersion != null) {
+      // take the next version number
+      processDefinition.setVersion(previousLatestVersion.getVersion() + 1);
+    }
     else {
-      throw new JbpmException("process definition does not have a name");
+      // start from 1
+      processDefinition.setVersion(1);
     }
+    saveProcessDefinition(processDefinition);
   }
 
   /**
-   * saves the process definitions. this method does not assign a version number. that is the
-   * responsibility of the {@link #deployProcessDefinition(ProcessDefinition)
-   * deployProcessDefinition} method.
+   * saves the process definition. this method does not assign a version
+   * number.
+   * @see {@link #deployProcessDefinition(ProcessDefinition)}
    */
   public void saveProcessDefinition(ProcessDefinition processDefinition) {
     try {
@@ -101,80 +102,85 @@
   }
 
   /**
-   * loads a process definition from the database by the identifier.
-   * 
-   * @throws JbpmPersistenceException in case the referenced process definition doesn't exist.
+   * returns the persistent process definition with the given identifier,
+   * assuming the definition exists. if the requested process definition does
+   * not exist in the database, {@link ObjectNotFoundException} is thrown when
+   * the definition state is first accessed.
    */
   public ProcessDefinition loadProcessDefinition(long processDefinitionId) {
     try {
-      return (ProcessDefinition) session.load(ProcessDefinition.class, new Long(
-          processDefinitionId));
+      return (ProcessDefinition) session.load(ProcessDefinition.class,
+        new Long(processDefinitionId));
     }
     catch (HibernateException e) {
       handle(e);
       throw new JbpmPersistenceException("could not load process definition "
-          + processDefinitionId, e);
+        + processDefinitionId, e);
     }
   }
 
   /**
-   * gets a process definition from the database by the identifier.
+   * returns the persistent process definition with the given identifier.
    * 
-   * @return the referenced process definition or null in case it doesn't exist.
+   * @return the referenced process definition, or <code>null</code> if there is
+   * no such definition.
    */
   public ProcessDefinition getProcessDefinition(long processDefinitionId) {
     try {
-      return (ProcessDefinition) session.get(ProcessDefinition.class, new Long(
-          processDefinitionId));
+      return (ProcessDefinition) session.get(ProcessDefinition.class,
+        new Long(processDefinitionId));
     }
     catch (HibernateException e) {
       handle(e);
       throw new JbpmPersistenceException("could not get process definition "
-          + processDefinitionId, e);
+        + processDefinitionId, e);
     }
   }
 
   /**
-   * queries the database for a process definition with the given name and version.
+   * finds the process definition with the given name and version.
    */
   public ProcessDefinition findProcessDefinition(String name, int version) {
     try {
       return (ProcessDefinition) session.getNamedQuery("GraphSession.findProcessDefinitionByNameAndVersion")
-          .setString("name", name)
-          .setInteger("version", version)
-          .uniqueResult();
+        .setString("name", name)
+        .setInteger("version", version)
+        .uniqueResult();
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("could not find process definition '" + name
-          + "' at version " + version, e);
+      throw new JbpmPersistenceException("could not find process definition by name '" + name
+        + "' and version " + version, e);
     }
   }
 
   /**
-   * queries the database for the latest version of a process definition with the given name.
+   * queries the database for the latest version of a process definition with
+   * the given name.
    */
   public ProcessDefinition findLatestProcessDefinition(String name) {
     try {
       return (ProcessDefinition) session.getNamedQuery("GraphSession.findLatestProcessDefinitionQuery")
-          .setString("name", name)
-          .setMaxResults(1)
-          .uniqueResult();
+        .setString("name", name)
+        .setMaxResults(1)
+        .uniqueResult();
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("could not find process definition '" + name + "'", e);
+      throw new JbpmPersistenceException("could not find process definition by name " + name, e);
     }
   }
 
   /**
-   * queries the database for the latest version of each process definition. Process definitions
-   * are distinct by name.
+   * queries the database for the latest version of each process definition.
+   * process definitions are distinct by name.
    */
   public List findLatestProcessDefinitions() {
     try {
       List tuples = session.getNamedQuery("GraphSession.findLatestProcessDefinitions").list();
-      List result = new ArrayList();
+      if (tuples.isEmpty()) return Collections.EMPTY_LIST;
+
+      List result = new ArrayList(tuples.size());
       for (Iterator i = tuples.iterator(); i.hasNext();) {
         Object[] tuple = (Object[]) i.next();
         String name = (String) tuple[0];
@@ -185,20 +191,26 @@
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException(
-          "could not find latest versions of process definitions", e);
+      throw new JbpmPersistenceException("could not find latest process definitions", e);
     }
   }
 
   public List findProcessDefinitions(Collection processDefinitionIds) {
-    return session.createCriteria(ProcessDefinition.class)
+    try {
+      return session.createCriteria(ProcessDefinition.class)
         .add(Restrictions.in("id", processDefinitionIds))
         .list();
+    }
+    catch (HibernateException e) {
+      handle(e);
+      throw new JbpmPersistenceException("could not find process definitions by identifiers "
+        + processDefinitionIds, e);
+    }
   }
 
   /**
-   * queries the database for all process definitions, ordered by name (ascending), then by
-   * version (descending).
+   * queries the database for all process definitions, ordered by name
+   * (ascending), then by version (descending).
    */
   public List findAllProcessDefinitions() {
     try {
@@ -211,19 +223,19 @@
   }
 
   /**
-   * queries the database for all versions of process definitions with the given name, ordered
-   * by version (descending).
+   * queries the database for all versions of process definitions with the given
+   * name, ordered by version (descending).
    */
   public List findAllProcessDefinitionVersions(String name) {
     try {
       return session.getNamedQuery("GraphSession.findAllProcessDefinitionVersions")
-          .setString("name", name)
-          .list();
+        .setString("name", name)
+        .list();
     }
     catch (HibernateException e) {
-      log.error(e);
-      throw new JbpmPersistenceException("could not find all versions of process definition '"
-          + name + "'", e);
+      handle(e);
+      throw new JbpmPersistenceException("could not find all process definitions by name "
+        + name, e);
     }
   }
 
@@ -235,17 +247,14 @@
     try {
       // delete all the process instances of this definition
       List processInstanceIds = session.getNamedQuery("GraphSession.findAllProcessInstanceIdsForDefinition")
-          .setLong("processDefinitionId", processDefinition.getId())
-          .list();
+        .setLong("processDefinitionId", processDefinition.getId())
+        .list();
       for (Iterator i = processInstanceIds.iterator(); i.hasNext();) {
         Long processInstanceId = (Long) i.next();
         ProcessInstance processInstance = getProcessInstance(processInstanceId.longValue());
         if (processInstance != null) {
           deleteProcessInstance(processInstance);
         }
-        else {
-          log.debug("process instance " + processInstanceId + " has been deleted already");
-        }
       }
 
       List referencingProcessStates = findReferencingProcessStates(processDefinition);
@@ -265,8 +274,8 @@
 
   List findReferencingProcessStates(ProcessDefinition subProcessDefinition) {
     return session.getNamedQuery("GraphSession.findReferencingProcessStates")
-        .setEntity("subProcessDefinition", subProcessDefinition)
-        .list();
+      .setEntity("subProcessDefinition", subProcessDefinition)
+      .list();
   }
 
   // process instances ////////////////////////////////////////////////////////
@@ -280,11 +289,10 @@
   }
 
   /**
-   * loads a process instance from the database by the identifier. This throws an exception in
-   * case the process instance does not exist.
-   * 
-   * @see #getProcessInstance(long)
-   * @throws JbpmPersistenceException in case the process instance doesn't exist.
+   * returns the persistent process instance with the given identifier, assuming
+   * the instance exists. if the requested process instance does not exist in
+   * the database, {@link ObjectNotFoundException} is thrown when the instance
+   * state is first accessed.
    */
   public ProcessInstance loadProcessInstance(long processInstanceId) {
     try {
@@ -292,14 +300,16 @@
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException(
-          "could not load process instance " + processInstanceId, e);
+      throw new JbpmPersistenceException("could not load process instance "
+        + processInstanceId, e);
     }
   }
 
   /**
-   * gets a process instance from the database by the identifier. This method returns null in
-   * case the given process instance does not exist.
+   * returns the persistent process instance with the given identifier.
+   * 
+   * @return the referenced process instance, or <code>null</code> if there is
+   * no such instance
    */
   public ProcessInstance getProcessInstance(long processInstanceId) {
     try {
@@ -307,16 +317,16 @@
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("could not get process instance " + processInstanceId,
-          e);
+      throw new JbpmPersistenceException("could not get process instance "
+        + processInstanceId, e);
     }
   }
 
   /**
-   * loads a token from the database by the identifier.
-   * 
-   * @return the token.
-   * @throws JbpmPersistenceException in case the referenced token doesn't exist.
+   * returns the persistent token with the given identifier, assuming the token
+   * exists. if the requested token does not exist in the database,
+   * {@link ObjectNotFoundException} is thrown when the token state is first
+   * accessed.
    */
   public Token loadToken(long tokenId) {
     try {
@@ -329,9 +339,10 @@
   }
 
   /**
-   * gets a token from the database by the identifier.
+   * returns the persistent token with the given identifier.
    * 
-   * @return the token or null in case the token doesn't exist.
+   * @return the referenced token, or <code>null</code> if there is no such
+   * token.
    */
   public Token getToken(long tokenId) {
     try {
@@ -344,7 +355,7 @@
   }
 
   /**
-   * locks a process instance in the database.
+   * obtains a pessimistic lock on the process instance with the given identifier.
    */
   public void lockProcessInstance(long processInstanceId) {
     try {
@@ -352,13 +363,13 @@
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException(
-          "could not lock process instance " + processInstanceId, e);
+      throw new JbpmPersistenceException("could not lock process instance "
+        + processInstanceId, e);
     }
   }
 
   /**
-   * locks a process instance in the database.
+   * obtains a pessimistic lock on the given process instance.
    */
   public void lockProcessInstance(ProcessInstance processInstance) {
     try {
@@ -371,19 +382,19 @@
   }
 
   /**
-   * fetches all processInstances for the given process definition from the database. The
-   * returned list of process instances is sorted start date, youngest first.
+   * finds all instances of the given process definition.
+   * @return a list of process instances ordered by start date, earliest first
    */
   public List findProcessInstances(long processDefinitionId) {
     try {
       return session.getNamedQuery("GraphSession.findAllProcessInstancesForDefinition")
-          .setLong("processDefinitionId", processDefinitionId)
-          .list();
+        .setLong("processDefinitionId", processDefinitionId)
+        .list();
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException(
-          "could not find process instances for process definition " + processDefinitionId, e);
+      throw new JbpmPersistenceException("could not find instances for process definition "
+        + processDefinitionId, e);
     }
   }
 
@@ -396,7 +407,7 @@
   }
 
   public void deleteProcessInstance(ProcessInstance processInstance, boolean includeTasks,
-      boolean includeJobs) {
+    boolean includeJobs) {
     if (processInstance == null) {
       throw new IllegalArgumentException("processInstance cannot be null");
     }
@@ -420,7 +431,6 @@
       if (includeTasks) deleteTasks(processInstance);
 
       // delete the process instance
-      log.debug("deleting " + processInstance);
       session.delete(processInstance);
     }
     catch (HibernateException e) {
@@ -430,52 +440,40 @@
   }
 
   void deleteJobs(ProcessInstance processInstance) {
-    log.debug("deleting jobs for " + processInstance);
-    int entityCount = session.getNamedQuery("GraphSession.deleteJobsForProcessInstance")
-        .setEntity("processInstance", processInstance)
-        .executeUpdate();
-    log.debug("deleted " + entityCount + " jobs for " + processInstance);
+    session.getNamedQuery("GraphSession.deleteJobsForProcessInstance")
+      .setEntity("processInstance", processInstance)
+      .executeUpdate();
   }
 
   void deleteLogs(ProcessInstance processInstance) {
-    log.debug("deleting logs for " + processInstance);
     List logs = session.getNamedQuery("GraphSession.findLogsForProcessInstance")
-        .setEntity("processInstance", processInstance)
-        .list();
+      .setEntity("processInstance", processInstance)
+      .list();
     for (Iterator i = logs.iterator(); i.hasNext();) {
       session.delete(i.next());
     }
   }
 
   void detachFromSuperProcess(ProcessInstance processInstance, Token superProcessToken) {
-    log.debug("detaching " + processInstance + " from " + superProcessToken);
     processInstance.setSuperProcessToken(null);
     superProcessToken.setSubProcessInstance(null);
   }
 
   void deleteSubProcesses(ProcessInstance processInstance) {
-    log.debug("deleting subprocesses for " + processInstance);
     List subProcessInstances = session.getNamedQuery("GraphSession.findSubProcessInstances")
-        .setEntity("processInstance", processInstance)
-        .list();
+      .setEntity("processInstance", processInstance)
+      .list();
 
-    if (subProcessInstances.isEmpty()) {
-      log.debug("no subprocesses to delete for " + processInstance);
-      return;
-    }
-
     for (Iterator i = subProcessInstances.iterator(); i.hasNext();) {
       ProcessInstance subProcessInstance = (ProcessInstance) i.next();
-      log.debug("preparing to delete Sub" + subProcessInstance);
       deleteProcessInstance(subProcessInstance);
     }
   }
 
   void deleteTasks(ProcessInstance processInstance) {
-    log.debug("deleting tasks for " + processInstance);
     List tasks = session.getNamedQuery("GraphSession.findTaskInstancesForProcessInstance")
-        .setEntity("processInstance", processInstance)
-        .list();
+      .setEntity("processInstance", processInstance)
+      .list();
     for (Iterator i = tasks.iterator(); i.hasNext();) {
       session.delete(i.next());
     }
@@ -542,79 +540,84 @@
   public List calculateAverageTimeByNode(long processDefinitionId, long minumumDurationMillis) {
     try {
       List tuples = session.getNamedQuery("GraphSession.calculateAverageTimeByNode")
-          .setLong("processDefinitionId", processDefinitionId)
-          .setDouble("minimumDuration", minumumDurationMillis)
-          .list();
+        .setLong("processDefinitionId", processDefinitionId)
+        .setDouble("minimumDuration", minumumDurationMillis)
+        .list();
+      if (tuples.isEmpty()) return Collections.EMPTY_LIST;
 
-      List results;
-      if (!tuples.isEmpty()) {
-        results = new ArrayList();
+      List results = new ArrayList();
+      for (Iterator i = tuples.iterator(); i.hasNext();) {
+        Object[] values = (Object[]) i.next();
 
-        for (Iterator i = tuples.iterator(); i.hasNext();) {
-          Object[] values = (Object[]) i.next();
-          AverageNodeTimeEntry averageNodeTimeEntry = new AverageNodeTimeEntry();
-          averageNodeTimeEntry.setNodeId(((Number) values[0]).longValue());
-          averageNodeTimeEntry.setNodeName((String) values[1]);
-          averageNodeTimeEntry.setCount(((Number) values[2]).intValue());
-          averageNodeTimeEntry.setAverageDuration(((Number) values[3]).longValue());
-          averageNodeTimeEntry.setMinDuration(((Number) values[4]).longValue());
-          averageNodeTimeEntry.setMaxDuration(((Number) values[5]).longValue());
+        AverageNodeTimeEntry entry = new AverageNodeTimeEntry();
+        entry.setNodeId(((Number) values[0]).longValue());
+        entry.setNodeName((String) values[1]);
+        entry.setCount(((Number) values[2]).intValue());
+        entry.setAverageDuration(((Number) values[3]).longValue());
+        entry.setMinDuration(((Number) values[4]).longValue());
+        entry.setMaxDuration(((Number) values[5]).longValue());
 
-          results.add(averageNodeTimeEntry);
-        }
+        results.add(entry);
       }
-      else {
-        results = Collections.EMPTY_LIST;
-      }
       return results;
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("could not calculate average time by node for "
-          + processDefinitionId, e);
+      throw new JbpmPersistenceException("could not calculate average time by node "
+        + "for process definition " + processDefinitionId, e);
     }
   }
 
   public List findActiveNodesByProcessInstance(ProcessInstance processInstance) {
     try {
       return session.getNamedQuery("GraphSession.findActiveNodesByProcessInstance")
-          .setEntity("processInstance", processInstance)
-          .list();
+        .setEntity("processInstance", processInstance)
+        .list();
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("could not find active nodes for " + processInstance,
-          e);
+      throw new JbpmPersistenceException("could not find active nodes for "
+        + processInstance, e);
     }
   }
 
+  /**
+   * returns the instance of the given process definition with the specified
+   * business key.
+   * 
+   * @return the referenced instance, or <code>null</code> if there is no such
+   * instance
+   */
   public ProcessInstance getProcessInstance(ProcessDefinition processDefinition, String key) {
     try {
       return (ProcessInstance) session.getNamedQuery("GraphSession.findProcessInstanceByKey")
-          .setEntity("processDefinition", processDefinition)
-          .setString("key", key)
-          .uniqueResult();
+        .setEntity("processDefinition", processDefinition)
+        .setString("key", key)
+        .uniqueResult();
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("could not get process instance with key '" + key
-          + "'", e);
+      throw new JbpmPersistenceException("could not get process instance by key " + key, e);
     }
   }
 
+  /**
+   * returns the instance of the given process definition with the specified
+   * business key, assuming the instance exists.
+   * 
+   * @throws JbpmPersistenceException if the referenced process instance does
+   * not exist
+   */
   public ProcessInstance loadProcessInstance(ProcessDefinition processDefinition, String key) {
     ProcessInstance processInstance = getProcessInstance(processDefinition, key);
     if (processInstance == null) {
-      throw new JbpmException("no process instance was found with key '" + key + "'");
+      throw new JbpmPersistenceException("could not load process instance by key " + key);
     }
     return processInstance;
   }
 
   private void handle(HibernateException exception) {
-    // exception will be rethrown, no need to log here at a verbose level
-    log.debug(exception);
+    // exception will be rethrown, no need to log here
     if (jbpmSession != null) jbpmSession.handleException();
   }
-
-  private static final Log log = LogFactory.getLog(GraphSession.class);
 }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/TaskMgmtSession.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/TaskMgmtSession.java	2010-03-03 19:06:53 UTC (rev 6207)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/TaskMgmtSession.java	2010-03-04 07:33:35 UTC (rev 6208)
@@ -22,10 +22,9 @@
 package org.jbpm.db;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.hibernate.HibernateException;
 import org.hibernate.Session;
 
@@ -51,39 +50,37 @@
   }
 
   /**
-   * get the tasklist for a given actor.
+   * get the task list for a given actor.
    */
   public List findTaskInstances(String actorId) {
     try {
       return session.getNamedQuery("TaskMgmtSession.findTaskInstancesByActorId")
-          .setString("actorId", actorId)
-          .list();
+        .setString("actorId", actorId)
+        .list();
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("couldn't get task instances list for actor '"
-          + actorId
-          + "'", e);
+      throw new JbpmPersistenceException("could not find task instances by actor " + actorId, e);
     }
   }
 
   /**
-   * get all the task instances for all the given actorIds.
+   * get all the task instances for all the given actor identifiers.
    * 
-   * @return a list of task instances. An empty list is returned in case no task instances are
-   *         found.
+   * @return a list of task instances. An empty list is returned in case no task
+   * instances are found.
    */
   public List findTaskInstances(List actorIds) {
+    if (actorIds.isEmpty()) return Collections.EMPTY_LIST;
     try {
       return session.getNamedQuery("TaskMgmtSession.findTaskInstancesByActorIds")
-          .setParameterList("actorIds", actorIds)
-          .list();
+        .setParameterList("actorIds", actorIds)
+        .list();
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("couldn't get task instances list for actors '"
-          + actorIds
-          + "'", e);
+      throw new JbpmPersistenceException("could not find task instances by actors " + actorIds,
+        e);
     }
   }
 
@@ -100,15 +97,14 @@
   public List findPooledTaskInstances(String actorId) {
     try {
       List taskInstanceIds = session.getNamedQuery("TaskMgmtSession.findPooledTaskInstancesByActorId")
-          .setString("actorId", actorId)
-          .list();
+        .setString("actorId", actorId)
+        .list();
       return findTaskInstancesByIds(taskInstanceIds);
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("couldn't get pooled task instances list for actor '"
-          + actorId
-          + "'", e);
+      throw new JbpmPersistenceException("could not find pooled task instances by actor "
+        + actorId, e);
     }
   }
 
@@ -116,17 +112,17 @@
    * get the task instances for which the given actor is in the pool.
    */
   public List findPooledTaskInstances(List actorIds) {
+    if (actorIds.isEmpty()) return Collections.EMPTY_LIST;
     try {
       List taskInstanceIds = session.getNamedQuery("TaskMgmtSession.findPooledTaskInstancesByActorIds")
-          .setParameterList("actorIds", actorIds)
-          .list();
+        .setParameterList("actorIds", actorIds)
+        .list();
       return findTaskInstancesByIds(taskInstanceIds);
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("couldn't get pooled task instances list for actors '"
-          + actorIds
-          + "'", e);
+      throw new JbpmPersistenceException("could not find pooled task instances by actors "
+        + actorIds, e);
     }
   }
 
@@ -136,13 +132,12 @@
   public List findTaskInstancesByToken(long tokenId) {
     try {
       return session.getNamedQuery("TaskMgmtSession.findTaskInstancesByTokenId")
-          .setLong("tokenId", tokenId)
-          .list();
+        .setLong("tokenId", tokenId)
+        .list();
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("couldn't get task instances by token '" + tokenId + "'",
-          e);
+      throw new JbpmPersistenceException("could not find task instances by token " + tokenId, e);
     }
   }
 
@@ -152,14 +147,13 @@
   public List findTaskInstancesByProcessInstance(ProcessInstance processInstance) {
     try {
       return session.getNamedQuery("TaskMgmtSession.findTaskInstancesByProcessInstance")
-          .setEntity("processInstance", processInstance)
-          .list();
+        .setEntity("processInstance", processInstance)
+        .list();
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("couldn't get task instances by process instance '"
-          + processInstance
-          + "'", e);
+      throw new JbpmPersistenceException("could not find task instances by " + processInstance,
+        e);
     }
   }
 
@@ -173,7 +167,7 @@
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("couldn't get task instance '" + taskInstanceId + "'", e);
+      throw new JbpmPersistenceException("could not load task instance " + taskInstanceId, e);
     }
     return taskInstance;
   }
@@ -188,30 +182,27 @@
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("couldn't get task instance '" + taskInstanceId + "'", e);
+      throw new JbpmPersistenceException("could not get task instance " + taskInstanceId, e);
     }
     return taskInstance;
   }
 
   public List findTaskInstancesByIds(List taskInstanceIds) {
+    if (taskInstanceIds.isEmpty()) return Collections.EMPTY_LIST;
     try {
       return session.getNamedQuery("TaskMgmtSession.findTaskInstancesByIds")
-          .setParameterList("taskInstanceIds", taskInstanceIds)
-          .list();
+        .setParameterList("taskInstanceIds", taskInstanceIds)
+        .list();
     }
     catch (HibernateException e) {
       handle(e);
-      throw new JbpmPersistenceException("couldn't get task instances by ids '"
-          + taskInstanceIds
-          + "'", e);
+      throw new JbpmPersistenceException("could not find task instances by identifiers "
+        + taskInstanceIds, e);
     }
   }
 
   private void handle(HibernateException exception) {
-    // exception will be rethrown, no need to log here at a verbose level
-    log.debug(exception);
+    // exception will be rethrown, no need to log here
     if (jbpmSession != null) jbpmSession.handleException();
   }
-
-  private static final Log log = LogFactory.getLog(TaskMgmtSession.class);
 }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/JbpmPersistenceException.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/JbpmPersistenceException.java	2010-03-03 19:06:53 UTC (rev 6207)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/JbpmPersistenceException.java	2010-03-04 07:33:35 UTC (rev 6208)
@@ -27,6 +27,10 @@
 
   private static final long serialVersionUID = 1L;
 
+  public JbpmPersistenceException(String message) {
+    super(message);
+  }
+
   public JbpmPersistenceException(String message, Throwable cause) {
     super(message, cause);
   }

Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2637/JBPM2637Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2637/JBPM2637Test.java	                        (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2637/JBPM2637Test.java	2010-03-04 07:33:35 UTC (rev 6208)
@@ -0,0 +1,77 @@
+/*
+ * 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.jbpm2637;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.jbpm.db.AbstractDbTestCase;
+import org.jbpm.db.TaskMgmtSession;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+
+/**
+ * {@link TaskMgmtSession#findTaskInstancesByIds(List)} fails if taskInstanceIds
+ * is an empty list.
+ * 
+ * @see <a href="https://jira.jboss.org/jira/browse/JBPM-2637">JBPM-2637</a>
+ * @author Alejandro Guizar
+ */
+public class JBPM2637Test extends AbstractDbTestCase {
+
+  private long processDefinitionId;
+
+  protected void setUp() throws Exception {
+    super.setUp();
+
+    ProcessDefinition processDefinition = ProcessDefinition.createNewProcessDefinition();
+    processDefinition.setName("jbpm2637");
+    jbpmContext.deployProcessDefinition(processDefinition);
+    processDefinitionId = processDefinition.getId();
+    newTransaction();
+
+    ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate("jbpm2637");
+    processInstance.getTaskMgmtInstance().createTaskInstance(processInstance.getRootToken());
+    newTransaction();
+  }
+
+  protected void tearDown() throws Exception {
+    graphSession.deleteProcessDefinition(processDefinitionId);
+    super.tearDown();
+  }
+
+  public void testFindTaskInstancesEmptyActorList() {
+    assertEquals(0, taskMgmtSession.findTaskInstances(Collections.EMPTY_LIST).size());
+  }
+
+  public void testFindTaskInstancesEmptyActorArray() {
+    assertEquals(0, taskMgmtSession.findTaskInstances(new String[0]).size());
+  }
+
+  public void testFindPooledTaskInstancesEmptyActorList() {
+    assertEquals(0, taskMgmtSession.findPooledTaskInstances(Collections.EMPTY_LIST).size());
+  }
+
+  public void testFindTaskInstancesEmptyIdList() {
+    assertEquals(0, taskMgmtSession.findTaskInstancesByIds(Collections.EMPTY_LIST).size());
+  }
+}


Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2637/JBPM2637Test.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native



More information about the jbpm-commits mailing list