[jbpm-commits] JBoss JBPM SVN: r3193 - in jbpm4/trunk: modules/api/src/main/java/org/jbpm and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Dec 4 04:30:45 EST 2008


Author: tom.baeyens at jboss.com
Date: 2008-12-04 04:30:45 -0500 (Thu, 04 Dec 2008)
New Revision: 3193

Added:
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionQuery.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessDefinitionQuery.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/HqlQueryCmd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionQueryImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessDefinitionQueryImpl.java
Modified:
   jbpm4/trunk/eclipse/jbpm.code.templates.xml
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessService.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessDefinitionCmd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessServiceImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PvmDbSessionBinding.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/svc/ProcessServiceTest.java
   jbpm4/trunk/modules/userguide/.settings/attachedFile.properties
Log:
query capabilities and completed process service testing

Modified: jbpm4/trunk/eclipse/jbpm.code.templates.xml
===================================================================
--- jbpm4/trunk/eclipse/jbpm.code.templates.xml	2008-12-04 09:21:44 UTC (rev 3192)
+++ jbpm4/trunk/eclipse/jbpm.code.templates.xml	2008-12-04 09:30:45 UTC (rev 3193)
@@ -28,10 +28,7 @@
 </template><template autoinsert="true" context="interfacebody_context" deleted="false" description="Code in new interface type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name="interfacebody">
 </template><template autoinsert="true" context="enumbody_context" deleted="false" description="Code in new enum type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.enumbody" name="enumbody">
 </template><template autoinsert="true" context="annotationbody_context" deleted="false" description="Code in new annotation type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name="annotationbody">
-</template><template autoinsert="true" context="catchblock_context" deleted="false" description="Code in new catch blocks" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.catchblock" name="catchblock">// ${todo} Auto-generated catch block
-${exception_var}.printStackTrace();</template><template autoinsert="true" context="methodbody_context" deleted="false" description="Code in created method stubs" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodbody" name="methodbody">// ${todo} Auto-generated method stub
-${body_statement}</template><template autoinsert="true" context="constructorbody_context" deleted="false" description="Code in created constructor stubs" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name="constructorbody">${body_statement}
-// ${todo} Auto-generated constructor stub</template><template autoinsert="true" context="getterbody_context" deleted="false" description="Code in created getters" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.getterbody" name="getterbody">return ${field};</template><template autoinsert="true" context="setterbody_context" deleted="false" description="Code in created setters" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.setterbody" name="setterbody">${field} = ${param};</template><template autoinsert="true" context="gettercomment_context" deleted="false" description="Comment for getter function" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.gettercomment" name="gettercomment">/**
+</template><template autoinsert="false" context="catchblock_context" deleted="false" description="Code in new catch blocks" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.catchblock" name="catchblock">${exception_var}.printStackTrace();</template><template autoinsert="false" context="methodbody_context" deleted="false" description="Code in created method stubs" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodbody" name="methodbody">${body_statement}</template><template autoinsert="false" context="constructorbody_context" deleted="false" description="Code in created constructor stubs" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name="constructorbody">${body_statement}</template><template autoinsert="true" context="getterbody_context" deleted="false" description="Code in created getters" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.getterbody" name="getterbody">return ${field};</template><template autoinsert="!
 true" context="setterbody_context" deleted="false" description="Code in created setters" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.setterbody" name="setterbody">${field} = ${param};</template><template autoinsert="true" context="gettercomment_context" deleted="false" description="Comment for getter function" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.gettercomment" name="gettercomment">/**
  * @return the ${bare_field_name}
  */</template><template autoinsert="true" context="settercomment_context" deleted="false" description="Comment for setter function" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.settercomment" name="settercomment">/**
  * @param ${param} the ${bare_field_name} to set
@@ -57,7 +54,4 @@
 
 ${typecomment}
 ${type_declaration}</template><template autoinsert="true" context="classbody_context" deleted="false" description="Code in new class type bodies" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.classbody" name="classbody">
-</template><template autoinsert="true" context="catchblock_context" deleted="false" description="Code in new catch blocks" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.catchblock" name="catchblock">// ${todo} Auto-generated catch block
-${exception_var}.printStackTrace();</template><template autoinsert="true" context="methodbody_context" deleted="false" description="Code in created function stubs" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.methodbody" name="methodbody">// ${todo} Auto-generated function stub
-${body_statement}</template><template autoinsert="true" context="constructorbody_context" deleted="false" description="Code in created constructor stubs" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.constructorbody" name="constructorbody">${body_statement}
-// ${todo} Auto-generated constructor stub</template><template autoinsert="true" context="getterbody_context" deleted="false" description="Code in created getters" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.getterbody" name="getterbody">return ${field};</template><template autoinsert="true" context="setterbody_context" deleted="false" description="Code in created setters" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.setterbody" name="setterbody">${field} = ${param};</template></templates>
\ No newline at end of file
+</template><template autoinsert="false" context="catchblock_context" deleted="false" description="Code in new catch blocks" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.catchblock" name="catchblock">${exception_var}.printStackTrace();</template><template autoinsert="false" context="methodbody_context" deleted="false" description="Code in created function stubs" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.methodbody" name="methodbody">${body_statement}</template><template autoinsert="false" context="constructorbody_context" deleted="false" description="Code in created constructor stubs" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.constructorbody" name="constructorbody">${body_statement}</template><template autoinsert="true" context="getterbody_context" deleted="false" description="Code in created getters" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.getterbody" name="getterbody">return ${field};</template>!
 <template autoinsert="true" context="setterbody_context" deleted="false" description="Code in created setters" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.setterbody" name="setterbody">${field} = ${param};</template></templates>
\ No newline at end of file

Added: jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionQuery.java	                        (rev 0)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionQuery.java	2008-12-04 09:30:45 UTC (rev 3193)
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+import java.util.List;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public interface ExecutionQuery {
+  
+  ExecutionQuery onlyProcessInstances();
+
+  ExecutionQuery processDefinitionNameLike(String processDefinitionName);
+  ExecutionQuery processDefinitionKeyLike(String processDefinitionKey);
+  ExecutionQuery processDefinitionId(String processDefinitionId);
+
+  ExecutionQuery orderByKeyAsc();
+  ExecutionQuery orderByKeyDesc();
+
+  List<Execution> list();
+  List<Execution> list(int firstResult, int maxResults);
+}


Property changes on: jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionQuery.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java	2008-12-04 09:21:44 UTC (rev 3192)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java	2008-12-04 09:30:45 UTC (rev 3193)
@@ -112,7 +112,8 @@
   /** provides a named external trigger to an execution with parameters. */
   Execution signalExecutionByKey(String processDefinitionName, String executionKey, String signalName, Map<String, Object> parameters);
 
-  
+  /** search for executions with criteria */
+  ExecutionQuery createExecutionQuery();
 
   /** creates or overwrites a variable value on the referenced execution */ 
   Execution setVariable(String executionId, String name, Object value);

Added: jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessDefinitionQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessDefinitionQuery.java	                        (rev 0)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessDefinitionQuery.java	2008-12-04 09:30:45 UTC (rev 3193)
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import java.util.List;
+
+/**
+ * @author Tom Baeyens
+ */
+public interface ProcessDefinitionQuery {
+
+  ProcessDefinitionQuery nameLike(String name);
+  ProcessDefinitionQuery keyLike(String key);
+
+  ProcessDefinitionQuery orderByNameAsc();
+  ProcessDefinitionQuery orderByNameDesc();
+  
+  ProcessDefinitionQuery orderByKeyAsc();
+  ProcessDefinitionQuery orderByKeyDesc();
+
+  List<ProcessDefinition> list();
+  List<ProcessDefinition> list(int firstResult, int maxResults);
+}


Property changes on: jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessDefinitionQuery.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessService.java	2008-12-04 09:21:44 UTC (rev 3192)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessService.java	2008-12-04 09:30:45 UTC (rev 3193)
@@ -36,7 +36,9 @@
   /** all deployed process definition keys. */
   List<String> findProcessDefinitionKeys();
 
-  /** all versions of the given process. */
+  /** all versions of the given process. 
+   * @return the process definitions in descending version order.  So you get the 
+   * highest version number as the first. */
   List<ProcessDefinition> findProcessDefinitionsByKey(String processDefinitionKey);
 
   /** latest version of the processDefinition with the given key. */
@@ -44,6 +46,9 @@
 
   /** specific version of a named processDefinition. */
   ProcessDefinition findProcessDefinitionById(String processDefinitionId);
+  
+  /** search for process definitions */
+  ProcessDefinitionQuery createProcessDefinitionQuery();
 
   /** deletes process definition if there are no existing executions. 
    * @throws JbpmException if there are existing executions. */

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessDefinitionCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessDefinitionCmd.java	2008-12-04 09:21:44 UTC (rev 3192)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessDefinitionCmd.java	2008-12-04 09:30:45 UTC (rev 3193)
@@ -24,6 +24,7 @@
 import org.jbpm.JbpmException;
 import org.jbpm.cmd.Command;
 import org.jbpm.env.Environment;
+import org.jbpm.pvm.internal.wire.binding.PvmDbSessionBinding;
 import org.jbpm.session.PvmDbSession;
 
 
@@ -49,7 +50,7 @@
   public Void execute(Environment environment) {
     PvmDbSession pvmDbSession = Environment.getFromCurrent(PvmDbSession.class);
     if (pvmDbSession==null) {
-      throw new JbpmException("no PvmDbSession configured");
+      throw new JbpmException("no "+PvmDbSessionBinding.TAG+" configured");
     }
     pvmDbSession.deleteProcessDefinition(processDefinitionId, deleteProcessInstances);
     return null;

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/HqlQueryCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/HqlQueryCmd.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/HqlQueryCmd.java	2008-12-04 09:30:45 UTC (rev 3193)
@@ -0,0 +1,74 @@
+/*
+ * 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.cmd;
+
+import java.util.List;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.jbpm.JbpmException;
+import org.jbpm.cmd.Command;
+import org.jbpm.env.Environment;
+import org.jbpm.log.Log;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class HqlQueryCmd implements Command<List<Object>> {
+
+  private static final long serialVersionUID = 1L;
+  
+  private static Log log = Log.getLog(HqlQueryCmd.class.getName());
+  
+  String hql;
+  Integer firstResult;
+  Integer maxResults;
+
+  public HqlQueryCmd(String hql, Integer firstResult, Integer maxResults) {
+    this.hql = hql;
+    this.firstResult = firstResult;
+    this.maxResults = maxResults;
+  }
+
+  public List<Object> execute(Environment environment) throws Exception {
+    Session session = environment.get(Session.class);
+    if (session==null) {
+      throw new JbpmException("no hibernate-session defined in configuration");
+    }
+    
+    Query query = session.createQuery(hql);
+    if (firstResult!=null) {
+      query.setFirstResult(firstResult);
+    }
+    if (maxResults!=null) {
+      query.setMaxResults(maxResults);
+    }
+    
+    if (log.isDebugEnabled()) {
+      log.debug("executing hql: ");
+      log.debug(hql);
+    }
+
+    return query.list();
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/HqlQueryCmd.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionQueryImpl.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionQueryImpl.java	2008-12-04 09:30:45 UTC (rev 3193)
@@ -0,0 +1,142 @@
+/*
+ * 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.svc;
+
+import java.util.List;
+
+import org.jbpm.Execution;
+import org.jbpm.ExecutionQuery;
+import org.jbpm.cmd.CommandService;
+import org.jbpm.pvm.internal.cmd.HqlQueryCmd;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ExecutionQueryImpl implements ExecutionQuery {
+  
+  private static final String NEWLINE = System.getProperty("line.separator");
+
+  protected boolean onlyProcessInstances; 
+  protected String processDefinitionNameLike;
+  protected String processDefinitionKeyLike;
+  protected String processDefinitionId;
+  protected String order;
+  protected Integer firstResult;
+  protected Integer maxResults;
+  
+  protected CommandService commandService;
+  
+  public ExecutionQueryImpl(CommandService commandService) {
+    this.commandService = commandService;
+  }
+
+  protected String buildHql() {
+    StringBuffer hql = new StringBuffer();
+    hql.append("select e ");
+    hql.append(NEWLINE);
+    hql.append("from "+ExecutionImpl.class.getName()+" as e ");
+    hql.append(NEWLINE);
+    
+    boolean where = false;
+
+    if (processDefinitionId!=null) {
+      where = true;
+      hql.append("where e.processDefinition.id = '"+processDefinitionId+"'");
+      hql.append(NEWLINE);
+    }
+
+    if (processDefinitionNameLike!=null) {
+      where = true;
+      addWhereOrAnd(hql, where);
+      hql.append("e.processDefinition.name like '"+processDefinitionNameLike+"'");
+      hql.append(NEWLINE);
+    }
+
+    if (processDefinitionKeyLike!=null) {
+      where = true;
+      addWhereOrAnd(hql, where);
+      hql.append("e.processDefinition.key like '"+processDefinitionKeyLike+"'");
+      hql.append(NEWLINE);
+    }
+    
+    if (order!=null) {
+      hql.append("order by "+order);
+    }
+
+    return hql.toString();
+  }
+
+  private void addWhereOrAnd(StringBuffer hql, boolean where) {
+    if (where) {
+      hql.append("  and ");
+    } else {
+      hql.append("where ");
+    }
+  }
+
+  protected List<Execution> execute() {
+    String hql = buildHql();
+    return (List) commandService.execute(new HqlQueryCmd(hql, firstResult, maxResults));
+  }
+
+  public ExecutionQuery onlyProcessInstances() {
+    this.onlyProcessInstances = true;
+    return this;
+  }
+
+  public ExecutionQuery orderByKeyAsc() {
+    order = "e.key asc";
+    return this;
+  }
+
+  public ExecutionQuery orderByKeyDesc() {
+    order = "e.key desc";
+    return this;
+  }
+
+  public ExecutionQuery processDefinitionId(String processDefinitionId) {
+    this.processDefinitionId = processDefinitionId;
+    return this;
+  }
+
+  public ExecutionQuery processDefinitionKeyLike(String processDefinitionKey) {
+    this.processDefinitionKeyLike = processDefinitionKey;
+    return this;
+  }
+
+  public ExecutionQuery processDefinitionNameLike(String processDefinitionName) {
+    this.processDefinitionNameLike = processDefinitionName;
+    return this;
+  }
+
+  public List<Execution> list() {
+    return execute();
+  }
+
+  public List<Execution> list(int firstResult, int maxResults) {
+    this.firstResult = firstResult;
+    this.maxResults = maxResults;
+    return execute();
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionQueryImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java	2008-12-04 09:21:44 UTC (rev 3192)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java	2008-12-04 09:30:45 UTC (rev 3193)
@@ -26,6 +26,7 @@
 import java.util.Set;
 
 import org.jbpm.Execution;
+import org.jbpm.ExecutionQuery;
 import org.jbpm.ExecutionService;
 import org.jbpm.cmd.CommandService;
 import org.jbpm.pvm.internal.cmd.DeleteProcessInstance;
@@ -135,6 +136,10 @@
   public Execution findExecution(String executionId) {
     return commandService.execute(new FindExecutionCmd(executionId));
   }
+  
+  public ExecutionQuery createExecutionQuery() {
+    return new ExecutionQueryImpl(commandService);
+  }
 
   public void deleteProcessInstance(String processInstanceId) {
     commandService.execute(new DeleteProcessInstance(processInstanceId));

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessDefinitionQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessDefinitionQueryImpl.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessDefinitionQueryImpl.java	2008-12-04 09:30:45 UTC (rev 3193)
@@ -0,0 +1,127 @@
+/*
+ * 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.svc;
+
+import java.util.List;
+
+import org.jbpm.ProcessDefinition;
+import org.jbpm.ProcessDefinitionQuery;
+import org.jbpm.cmd.CommandService;
+import org.jbpm.pvm.internal.cmd.HqlQueryCmd;
+import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ProcessDefinitionQueryImpl implements ProcessDefinitionQuery {
+  
+  private static final String NEWLINE = System.getProperty("line.separator");
+  
+  protected String nameLike;
+  protected String keyLike;
+  protected String order;
+  protected Integer firstResult;
+  protected Integer maxResults;
+  
+  protected CommandService commandService;
+  
+  public ProcessDefinitionQueryImpl(CommandService commandService) {
+    this.commandService = commandService;
+  }
+
+  protected String buildHql() {
+    StringBuffer hql = new StringBuffer();
+    hql.append("select pd ");
+    hql.append(NEWLINE);
+    hql.append("from "+ProcessDefinitionImpl.class.getName()+" as pd ");
+    hql.append(NEWLINE);
+
+    if (nameLike!=null) {
+      hql.append("where pd.name like '"+nameLike+"'");
+      hql.append(NEWLINE);
+    }
+
+    if (keyLike!=null) {
+      if (nameLike==null) {
+         hql.append("where ");
+      } else {
+        hql.append("  and ");
+        hql.append(NEWLINE);
+      }
+      hql.append("pd.key like '"+keyLike+"'");
+      hql.append(NEWLINE);
+    }
+    
+    if (order!=null) {
+      hql.append("order by "+order);
+    }
+
+    return hql.toString();
+  }
+
+  protected List<ProcessDefinition> execute() {
+    String hql = buildHql();
+    return (List) commandService.execute(new HqlQueryCmd(hql, firstResult, maxResults));
+  }
+
+
+  public ProcessDefinitionQuery nameLike(String name) {
+    nameLike = name;
+    return this;
+  }
+
+  public ProcessDefinitionQuery keyLike(String key) {
+    keyLike = key;
+    return this;
+  }
+
+  public ProcessDefinitionQuery orderByKeyAsc() {
+    order = "pd.key asc";
+    return this;
+  }
+
+  public ProcessDefinitionQuery orderByKeyDesc() {
+    order = "pd.key desc";
+    return this;
+  }
+
+  public ProcessDefinitionQuery orderByNameAsc() {
+    order = "pd.name asc";
+    return this;
+  }
+
+  public ProcessDefinitionQuery orderByNameDesc() {
+    order = "pd.name desc";
+    return this;
+  }
+
+  public List<ProcessDefinition> list() {
+    return execute();
+  }
+
+  public List<ProcessDefinition> list(int firstResult, int maxResults) {
+    this.firstResult = firstResult;
+    this.maxResults = maxResults;
+    return execute();
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessDefinitionQueryImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessServiceImpl.java	2008-12-04 09:21:44 UTC (rev 3192)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessServiceImpl.java	2008-12-04 09:30:45 UTC (rev 3193)
@@ -25,6 +25,7 @@
 
 import org.jbpm.Deployment;
 import org.jbpm.ProcessDefinition;
+import org.jbpm.ProcessDefinitionQuery;
 import org.jbpm.ProcessService;
 import org.jbpm.cmd.CommandService;
 import org.jbpm.model.OpenProcessDefinition;
@@ -72,7 +73,11 @@
     commandService.execute(new DeleteProcessDefinitionCmd(processDefinitionId, true));
   }
 
+  public ProcessDefinitionQuery createProcessDefinitionQuery() {
+    return new ProcessDefinitionQueryImpl(commandService);
+  }
 
+  
 
   public List<ProcessDefinition> deploy(Deployment deployment) {
     return commandService.execute(new DeployCmd((DeploymentImpl)deployment));
@@ -82,7 +87,6 @@
     DeploymentImpl deploymentImpl = new DeploymentImpl(processDefinition);
     return commandService.execute(new DeployCmd(deploymentImpl));
   }
-
   
   public CommandService getCommandService() {
     return commandService;

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PvmDbSessionBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PvmDbSessionBinding.java	2008-12-04 09:21:44 UTC (rev 3192)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PvmDbSessionBinding.java	2008-12-04 09:30:45 UTC (rev 3193)
@@ -34,9 +34,11 @@
  * @author Tom Baeyens
  */
 public class PvmDbSessionBinding extends WireDescriptorBinding {
+  
+  public static final String TAG = "pvm-db-session";
 
   public PvmDbSessionBinding() {
-    super("pvm-db-session");
+    super(TAG);
   }
 
   public Object parse(Element element, Parse parse, Parser parser) {

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/svc/ProcessServiceTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/svc/ProcessServiceTest.java	2008-12-04 09:21:44 UTC (rev 3192)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/svc/ProcessServiceTest.java	2008-12-04 09:30:45 UTC (rev 3193)
@@ -35,40 +35,6 @@
  */
 public class ProcessServiceTest extends DbTestCase {
 
-  public void testMinimalProcess() {
-    deployJpdlXmlString(
-      "<process name='minimal'>" +
-      "  <start>" +
-      "    <flow to='end' />" +
-      "  </start>" +
-      "  <end name='end' />" +
-      "</process>"
-    );
-    
-    Execution execution = executionService.startExecutionByKey("minimal");
-    
-    assertEquals("end", execution.getNodeName());
-    assertTrue(execution.isEnded());
-    assertTrue(execution.isFinished());
-    assertFalse(execution.isActive());
-  }
-
-  public void testMostMinimalProcess() {
-    deployJpdlXmlString(
-      "<process name='minimal'>" +
-      "  <start />" +
-      "</process>"
-    );
-
-    Execution execution = executionService.startExecutionByKey("minimal");
-    
-    assertTrue(execution.isEnded());
-    assertTrue(execution.isFinished());
-    assertFalse(execution.isActive());
-  }
-  
-  // user guide tests /////////////////////////////////////////////////////////
-
   public void testProcessWithNameOnly() {
     ProcessDefinition processDefinition = deployJpdlXmlString(
       "<process name='Insurance claim'>" +
@@ -84,12 +50,14 @@
   }
 
   public void testProcessWithNameAndKey() {
-    ProcessDefinition processDefinition = deployJpdlXmlString(
+    deployJpdlXmlString(
       "<process name='Insurance claim' key='ICL'>" +
       "  <start />" +
       "</process>"
     );
 
+    ProcessDefinition processDefinition = processService.findLatestProcessDefinitionByKey("ICL");
+
     assertNotNull(processDefinition);
     assertEquals("Insurance claim", processDefinition.getName());
     assertEquals("ICL", processDefinition.getKey());
@@ -97,7 +65,22 @@
     assertEquals("ICL:1", processDefinition.getId());
   }
 
+  // interface methods ////////////////////////////////////////////////////////
 
+  public void testFindProcessDefinitionKeys() {
+    deployMultipleVersionsOfProcesses();
+
+    List<String> processKeys = processService.findProcessDefinitionKeys();
+
+    List<String> expected = new ArrayList<String>();
+    expected.add("nuclear_fusion");
+    expected.add("publish_book");
+    expected.add("ultimate_seduction");
+
+    assertEquals(expected, processKeys);
+  }
+
+
   public void testFindProcessByKey() {
     deployJpdlXmlString(
       "<process name='Name with spaces'>" +
@@ -113,23 +96,115 @@
     assertEquals("Name_with_spaces:1", processDefinition.getId());
   }
 
-  public void testGivenKey() {
+  public void testFindProcessDefinitions() {
+    deployMultipleVersionsOfProcesses();
+
+    List<ProcessDefinition> processDefinitions = processService.findProcessDefinitionsByKey("nuclear_fusion");
+    assertNotNull(processDefinitions);
+
+    assertEquals("expected 3 but was " + processDefinitions.size() + ": " + processDefinitions, 3, processDefinitions.size());
+    assertEquals("nuclear fusion", processDefinitions.get(0).getName());
+    assertEquals(3, processDefinitions.get(0).getVersion());
+
+    assertEquals("nuclear fusion", processDefinitions.get(1).getName());
+    assertEquals(2, processDefinitions.get(1).getVersion());
+
+    assertEquals("nuclear fusion", processDefinitions.get(2).getName());
+    assertEquals(1, processDefinitions.get(2).getVersion());
+  }
+
+  public void testFindLatestProcessDefinition() {
+    deployMultipleVersionsOfProcesses();
+
+    ProcessDefinition retrieved = processService.findLatestProcessDefinitionByKey("nuclear_fusion");
+    assertNotNull(retrieved);
+
+    assertEquals(3, retrieved.getVersion());
+    assertEquals("nuclear fusion", retrieved.getName());
+    assertEquals("nuclear_fusion", retrieved.getKey());
+  }
+
+  public void testFindProcessDefinitionById() {
     deployJpdlXmlString(
-      "<process name='minimal' key='M'>" +
+      "<process name='given' version='33'>" +
       "  <start />" +
       "</process>"
     );
 
-    ProcessDefinition processDefinition = processService.findLatestProcessDefinitionByKey("M");
+    // load it
+    ProcessDefinition processDefinition = processService.findProcessDefinitionById("given:33");
+    assertNotNull(processDefinition);
+    assertEquals("given", processDefinition.getName());
+    assertEquals(33, processDefinition.getVersion());
+  }
+
+  public void testDeleteProcessDefinition() {
+    processService.createDeployment()
+        .addString("xmlstring.jpdl.xml", 
+            "<process name='deleteme' version='33'>" +
+            "  <start />" +
+            "</process>")
+        .deploy();
+
+    // load it
+    processService.deleteProcessDefinition("deleteme:33");
+
+    // check if the db is empty
+    assertEquals(0, processService.createProcessDefinitionQuery().list().size());
+  }
+
+  public void testDeleteProcessDefinitionAndInstances() {
+    processService.createDeployment()
+        .addString("xmlstring.jpdl.xml", 
+          "<process name='deleteme' version='33'>" +
+          "  <start>" +
+          "    <flow to='w' />" +
+          "  </start>" +
+          "  <state name='w' />" +
+          "</process>")
+        .deploy();
     
-    assertEquals("M", processDefinition.getKey());
-    assertEquals("M:1", processDefinition.getId());
-    assertEquals(1, processDefinition.getVersion());
+    executionService.startExecutionByKey("deleteme");
+    executionService.startExecutionByKey("deleteme");
+    executionService.startExecutionByKey("deleteme");
+    executionService.startExecutionByKey("deleteme");
+    
+    // delete it all
+    processService.deleteProcessDefinitionAndInstances("deleteme:33");
+
+    // check if the db is empty
+    assertEquals(0, processService.createProcessDefinitionQuery().list().size());
+    assertEquals(0, executionService.createExecutionQuery().list().size());
   }
-
-  public void testAutomaticVersioning()
-  {
+  
+  public void testDeleteProcessDefinitionButNotInstances() {
     deployJpdlXmlString(
+      "<process name='deleteme' version='33'>" +
+      "  <start>" +
+      "    <flow to='w' />" +
+      "  </start>" +
+      "  <state name='w' />" +
+      "</process>"
+    );
+    
+    executionService.startExecutionByKey("deleteme");
+    executionService.startExecutionByKey("deleteme");
+    executionService.startExecutionByKey("deleteme");
+    executionService.startExecutionByKey("deleteme");
+    
+    // delete it all
+    try {
+      processService.deleteProcessDefinition("deleteme:33");
+      fail("expected exception");
+    } catch (JbpmException e) {
+      assertTextPresent("still 4 process instances for process definition deleteme:33", e.getMessage());
+    }
+  }
+  
+  // various other aspects ////////////////////////////////////////////////////
+  
+  public void testAutomaticVersioning() {
+    deployJpdlXmlString(
       "<process name='versionme'>" +
       "  <start />" +
       "</process>"
@@ -150,7 +225,7 @@
       "</process>"
     );
 
-    // look it up again
+    // look them up again
     processDefinitions = processService.findProcessDefinitionsByKey("versionme");
     // verify that there is only one
     assertEquals(processDefinitions.toString(), 2, processDefinitions.size());
@@ -195,48 +270,6 @@
     }
   }
 
-  public void testFindProcessDefinitionNames() {
-    deployMultipleVersionsOfProcesses();
-
-    List<String> processKeys = processService.findProcessDefinitionKeys();
-
-    List<String> expected = new ArrayList<String>();
-    expected.add("nuclear_fusion");
-    expected.add("publish_book");
-    expected.add("ultimate_seduction");
-
-    assertEquals(expected, processKeys);
-  }
-
-  public void testFindProcessDefinitions()
-  {
-    deployMultipleVersionsOfProcesses();
-
-    List<ProcessDefinition> processDefinitions = processService.findProcessDefinitionsByKey("nuclear_fusion");
-    assertNotNull(processDefinitions);
-
-    assertEquals("expected 3 but was " + processDefinitions.size() + ": " + processDefinitions, 3, processDefinitions.size());
-    assertEquals("nuclear fusion", processDefinitions.get(0).getName());
-    assertEquals(3, processDefinitions.get(0).getVersion());
-
-    assertEquals("nuclear fusion", processDefinitions.get(1).getName());
-    assertEquals(2, processDefinitions.get(1).getVersion());
-
-    assertEquals("nuclear fusion", processDefinitions.get(2).getName());
-    assertEquals(1, processDefinitions.get(2).getVersion());
-  }
-
-  public void testFindLatestProcessDefinition() {
-    deployMultipleVersionsOfProcesses();
-
-    ProcessDefinition retrieved = processService.findLatestProcessDefinitionByKey("nuclear_fusion");
-    assertNotNull(retrieved);
-
-    assertEquals(3, retrieved.getVersion());
-    assertEquals("nuclear fusion", retrieved.getName());
-    assertEquals("nuclear_fusion", retrieved.getKey());
-  }
-
   /**
    * deploys 3 versions of process with name 'nuclear fusion', 2 versions of the processes 'ultimate seduction' and
    * 'publish book'
@@ -292,6 +325,35 @@
     );
   }
 
-  
-  
+  public void testMinimalProcess() {
+    deployJpdlXmlString(
+      "<process name='minimal'>" +
+      "  <start>" +
+      "    <flow to='end' />" +
+      "  </start>" +
+      "  <end name='end' />" +
+      "</process>"
+    );
+    
+    Execution execution = executionService.startExecutionByKey("minimal");
+    
+    assertEquals("end", execution.getNodeName());
+    assertTrue(execution.isEnded());
+    assertTrue(execution.isFinished());
+    assertFalse(execution.isActive());
+  }
+
+  public void testMostMinimalProcess() {
+    deployJpdlXmlString(
+      "<process name='minimal'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    Execution execution = executionService.startExecutionByKey("minimal");
+    
+    assertTrue(execution.isEnded());
+    assertTrue(execution.isFinished());
+    assertFalse(execution.isActive());
+  }
 }

Modified: jbpm4/trunk/modules/userguide/.settings/attachedFile.properties
===================================================================
--- jbpm4/trunk/modules/userguide/.settings/attachedFile.properties	2008-12-04 09:21:44 UTC (rev 3192)
+++ jbpm4/trunk/modules/userguide/.settings/attachedFile.properties	2008-12-04 09:30:45 UTC (rev 3193)
@@ -1,2 +1,2 @@
 ## index of importer -> set(imports)
-#Wed Dec 03 17:57:37 CET 2008
+#Thu Dec 04 08:28:47 CET 2008




More information about the jbpm-commits mailing list