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

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Oct 7 00:45:30 EDT 2010


Author: rebody
Date: 2010-10-07 00:45:29 -0400 (Thu, 07 Oct 2010)
New Revision: 6746

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/repository/RepositorySessionImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java
Log:
JBPM-2927 move hibernate package from RepositorySessionImpl to DbSession.

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-10-07 04:33:42 UTC (rev 6745)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java	2010-10-07 04:45:29 UTC (rev 6746)
@@ -568,4 +568,44 @@
       .list();
     return CollectionUtil.checkList(tasks, Task.class);
   }
+
+  // repository
+  public List<ExecutionImpl> findExecutionsForSupend(Set<String> processDefinitionIds) {
+    Query query = session.createQuery(
+      "select execution " +
+      "from " + ExecutionImpl.class.getName() + " as execution " +
+      "where execution.processDefinitionId in (:processDefinitionIds) " +
+      "  and execution.state != '" + ExecutionImpl.STATE_SUSPENDED + "'"
+    );
+    query.setParameterList("processDefinitionIds", processDefinitionIds);
+    return query.list();
+  }
+
+  public List<ExecutionImpl> findExecutionsForResume(Set<String> processDefinitionIds) {
+    Query query = session.createQuery(
+      "select execution " +
+      "from " + ExecutionImpl.class.getName() + " as execution " +
+      "where execution.processDefinitionId in (:processDefinitionIds) " +
+      "  and execution.state = '" + ExecutionImpl.STATE_SUSPENDED + "'"
+    );
+    query.setParameterList("processDefinitionIds", processDefinitionIds);
+    return query.list();
+  }
+
+  public DeploymentProperty findDeploymentPropertyByProcessDefinitionId(String processDefinitionId) {
+    DeploymentProperty deploymentProperty = (DeploymentProperty) session.createQuery(
+      "select deploymentProperty " +
+      "from " + DeploymentProperty.class.getName() + " as deploymentProperty " +
+      "where deploymentProperty.key = '" + DeploymentImpl.KEY_PROCESS_DEFINITION_ID + "' " +
+      "  and deploymentProperty.stringValue = '" + processDefinitionId + "' "
+    ).setMaxResults(1).uniqueResult();
+    return deploymentProperty;
+  }
+
+  public List<Long> findDeploymentDbids() {
+    return session.createQuery("select dbid from " +
+        DeploymentImpl.class.getName() + " as deployment ")
+        .setReadOnly(true)
+        .list();
+  }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java	2010-10-07 04:33:42 UTC (rev 6745)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java	2010-10-07 04:45:29 UTC (rev 6746)
@@ -25,9 +25,6 @@
 import java.util.List;
 import java.util.Set;
 
-import org.hibernate.Query;
-import org.hibernate.Session;
-
 import org.jbpm.api.JbpmException;
 import org.jbpm.api.NewDeployment;
 import org.jbpm.api.ProcessDefinition;
@@ -38,58 +35,53 @@
 import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
 import org.jbpm.pvm.internal.query.ProcessDefinitionQueryImpl;
 import org.jbpm.pvm.internal.session.RepositorySession;
+import org.jbpm.pvm.internal.session.DbSession;
 import org.jbpm.pvm.internal.util.CollectionUtil;
 
 /**
  * @author Tom Baeyens
  */
 public class RepositorySessionImpl implements RepositorySession {
-  
+
   private static Log log = Log.getLog(RepositorySessionImpl.class.getName());
-  
-  protected Session session;
+
   protected RepositoryCache repositoryCache;
   protected DeployerManager deployerManager;
 
+  protected DbSession dbSession;
+
   public String deploy(NewDeployment deployment) {
     DeploymentImpl deploymentImpl = (DeploymentImpl) deployment;
-    
+
     long dbid = DbidGenerator.getDbidGenerator().getNextId();
     deploymentImpl.setDbid(dbid);
     deploymentImpl.initResourceLobDbids();
-    
-    session.save(deploymentImpl); // will also save the attached resources
+
+    dbSession.save(deploymentImpl); // will also save the attached resources
     deployerManager.deploy(deploymentImpl);
 
     return deploymentImpl.getId();
   }
-  
+
   public void updateDeploymentResource(String deploymentId, String resourceName, byte[] bytes) {
     DeploymentImpl deployment = getDeployment(deploymentId);
     deployerManager.updateResource(deployment, resourceName, bytes);
   }
-  
+
   public void cascadeDeploymentSuspend(DeploymentImpl deployment) {
     // cascade to all executions in this deployment
     Set<String> processDefinitionIds = deployment.getProcessDefinitionIds();
     if (!processDefinitionIds.isEmpty()) {
-      Query query = session.createQuery(
-        "select execution " +
-        "from "+ExecutionImpl.class.getName()+" as execution " +
-        "where execution.processDefinitionId in (:processDefinitionIds) " +
-        "  and execution.state != '"+ExecutionImpl.STATE_SUSPENDED+"'"   
-      );
-      query.setParameterList("processDefinitionIds", processDefinitionIds);
-      List<?> executions = query.list();
+      List<ExecutionImpl> executions = dbSession.findExecutionsForSupend(processDefinitionIds);
       for (ExecutionImpl execution: CollectionUtil.checkList(executions, ExecutionImpl.class)) {
         execution.suspend();
       }
     }
 
-    // TODO cleaning this cache should actually be done as a synchronization 
-    // after the transaction.  If a concurrent transaction for an execution 
-    // starts between clearing the cache and committing the transaction, then 
-    // that transaction could potentially re-initialize the process definition 
+    // TODO cleaning this cache should actually be done as a synchronization
+    // after the transaction.  If a concurrent transaction for an execution
+    // starts between clearing the cache and committing the transaction, then
+    // that transaction could potentially re-initialize the process definition
     // in the cache.
     repositoryCache.remove(deployment.getId());
   }
@@ -98,14 +90,7 @@
     // cascade to all executions in this deployment
     Set<String> processDefinitionIds = deployment.getProcessDefinitionIds();
     if (!processDefinitionIds.isEmpty()) {
-      Query query = session.createQuery(
-        "select execution " +
-        "from "+ExecutionImpl.class.getName()+" as execution " +
-        "where execution.processDefinitionId in (:processDefinitionIds) " +   
-        "  and execution.state = '"+ExecutionImpl.STATE_SUSPENDED+"'"   
-      );
-      query.setParameterList("processDefinitionIds", processDefinitionIds);
-      List<?> executions = query.list();
+      List<ExecutionImpl> executions = dbSession.findExecutionsForResume(processDefinitionIds);
       for (ExecutionImpl execution: CollectionUtil.checkList(executions, ExecutionImpl.class)) {
         execution.resume();
       }
@@ -113,39 +98,41 @@
   }
 
   public DeploymentImpl getDeployment(String deploymentId) {
-    return (DeploymentImpl) session.get(DeploymentImpl.class, Long.parseLong(deploymentId));
+    return (DeploymentImpl) dbSession.get(DeploymentImpl.class, Long.parseLong(deploymentId));
   }
 
   public Object getObject(String deploymentId, String objectName) {
     Object object = repositoryCache.get(deploymentId, objectName);
-    if (object!=null) {
+    if (object != null) {
       log.trace("repository cache hit");
 
-    } else if (deploymentId==null) {
+    } else if (deploymentId == null) {
       throw new JbpmException("deploymentId is null");
-      
+
     } else {
-      log.trace("loading deployment "+deploymentId+" from db");
-      DeploymentImpl deployment = (DeploymentImpl) session.load(DeploymentImpl.class, Long.parseLong(deploymentId));
+      if (log.isTraceEnabled()) {
+        log.trace("loading deployment " + deploymentId + " from db");
+      }
+      DeploymentImpl deployment = (DeploymentImpl) dbSession.get(DeploymentImpl.class, Long.parseLong(deploymentId));
       deployerManager.deploy(deployment);
       object = repositoryCache.get(deploymentId, objectName);
-      if (object==null) {
-        throw new JbpmException("deployment "+deploymentId+" doesn't contain object "+objectName);
+      if (object == null) {
+        throw new JbpmException("deployment " + deploymentId + " doesn't contain object " + objectName);
       }
     }
     return object;
   }
-  
+
   public byte[] getBytes(String deploymentId, String resourceName) {
     DeploymentImpl deployment = getDeployment(deploymentId);
-    if (deployment==null) {
+    if (deployment == null) {
       return null;
     }
     return deployment.getBytes(resourceName);
   }
 
   // queries //////////////////////////////////////////////////////////////////
-  
+
   public ProcessDefinitionQueryImpl createProcessDefinitionQuery() {
     return new ProcessDefinitionQueryImpl();
   }
@@ -168,11 +155,11 @@
 
   public ProcessDefinitionImpl findProcessDefinitionById(String processDefinitionId) {
     DeploymentProperty deploymentProperty = findDeploymentPropertyByProcessDefinitionId(processDefinitionId);
-    
-    if (deploymentProperty!=null) {
+
+    if (deploymentProperty != null) {
       String deploymentId = deploymentProperty.getDeployment().getId();
       String objectName = deploymentProperty.getObjectName();
-      
+
       return (ProcessDefinitionImpl) getObject(deploymentId, objectName);
     } else {
       validateRepositoryCache();
@@ -180,7 +167,7 @@
 
     return null;
   }
-  
+
   public ProcessDefinitionImpl findLatestProcessDefinitionByName(String processDefinitionName) {
     ProcessDefinition processDefinition = createProcessDefinitionQuery()
       .processDefinitionName(processDefinitionName)
@@ -188,46 +175,38 @@
       .page(0, 1)
       .uniqueResult();
 
-  if (processDefinition != null) {
-    return findProcessDefinitionById(processDefinition.getId());
-  } else {
-    validateRepositoryCache();
-  }
+    if (processDefinition != null) {
+      return findProcessDefinitionById(processDefinition.getId());
+    } else {
+      validateRepositoryCache();
+    }
 
-  return null;
+    return null;
   }
 
   public DeploymentProperty findDeploymentPropertyByProcessDefinitionId(String processDefinitionId) {
-    DeploymentProperty deploymentProperty = (DeploymentProperty) session.createQuery(
-      "select deploymentProperty " +
-      "from "+DeploymentProperty.class.getName()+" as deploymentProperty " +
-      "where deploymentProperty.key = '"+DeploymentImpl.KEY_PROCESS_DEFINITION_ID+"' " +
-      "  and deploymentProperty.stringValue = '"+processDefinitionId+"' "
-    ).setMaxResults(1).uniqueResult();
-    return deploymentProperty;
+    return dbSession.findDeploymentPropertyByProcessDefinitionId(processDefinitionId);
   }
-  
+
   /**
    * Checks if every entry in the repositoryCache is still valid.
    * If the entry is not found in the database, it is deleted from the cache.
    */
   @SuppressWarnings("unchecked")
   private void validateRepositoryCache() {
-
     log.trace("Validating repository cache ... ");
-    Set<Long> dbIds = new HashSet<Long>(session.createQuery("select dbid from " +
-            DeploymentImpl.class.getName() + " as deployment ")
-            .setReadOnly(true)
-            .list());
-    
+    Set<Long> dbIds = new HashSet<Long>(dbSession.findDeploymentDbids());
+
     Set<String> cachedIds = repositoryCache.getCachedDeploymentIds();
     for (String cachedId : cachedIds) {
       if (!dbIds.contains(Long.valueOf(cachedId))) {
-        log.trace("Invalid entry in repositorycache found, removing now deployment id " + cachedId);
+        if (log.isTraceEnabled()) {
+          log.trace("Invalid entry in repositorycache found, removing now deployment id " + cachedId);
+        }
         repositoryCache.remove(cachedId);
       }
     }
-    
+
   }
 
 }

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-10-07 04:33:42 UTC (rev 6745)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java	2010-10-07 04:45:29 UTC (rev 6746)
@@ -40,6 +40,7 @@
 import org.jbpm.pvm.internal.query.JobQueryImpl;
 import org.jbpm.pvm.internal.query.ProcessInstanceQueryImpl;
 import org.jbpm.pvm.internal.query.TaskQueryImpl;
+import org.jbpm.pvm.internal.repository.DeploymentProperty;
 import org.jbpm.pvm.internal.task.TaskImpl;
 
 /**
@@ -129,4 +130,10 @@
   Set<String> findHistoryVariableNames(String processInstanceId);
   List<Participation> findParticipants(String taskId, String swimlaneId);
   List<Task> findSubTasks(String parentTaskId);
+
+  // repository
+  List<ExecutionImpl> findExecutionsForSupend(Set<String> processDefinitionIds);
+  List<ExecutionImpl> findExecutionsForResume(Set<String> processDefinitionIds);
+  DeploymentProperty findDeploymentPropertyByProcessDefinitionId(String processDefinitionId);
+  List<Long> findDeploymentDbids();
 }



More information about the jbpm-commits mailing list