Author: alex.guizar(a)jboss.com
Date: 2010-06-13 16:33:36 -0400 (Sun, 13 Jun 2010)
New Revision: 6411
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/custom/CustomHistoryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryCandidatesTest.java
jbpm4/trunk/pom.xml
Log:
JBPM-2872: fix hudson db job - oracle chapter
avoid select distinct task as oracle does not support distinct with clob columns
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java 2010-06-13
05:17:29 UTC (rev 6410)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java 2010-06-13
20:33:36 UTC (rev 6411)
@@ -46,10 +46,11 @@
private static final long serialVersionUID = 1L;
protected CommandService commandService;
- protected String orderByClause = null;
- protected Page page = null;
- protected boolean isWhereAdded = false;
- protected boolean count = false;
+ protected String orderByClause;
+ protected Page page;
+ protected boolean isWhereAdded;
+ protected boolean count;
+ protected boolean uniqueResult;
protected abstract void applyParameters(Query query);
@@ -63,54 +64,39 @@
}
*/
- public List untypedList() {
+ public List<?> untypedList() {
if (commandService!=null) {
- return (List) commandService.execute(this);
+ return (List<?>) commandService.execute(this);
}
Session session = EnvironmentImpl.getFromCurrent(Session.class);
- return (List) execute(session);
+ return (List<?>) execute(session);
}
protected Object untypedUniqueResult() {
- List list = untypedList();
- if (list.isEmpty()) {
- return null;
+ uniqueResult = true;
+
+ if (commandService!=null) {
+ return commandService.execute(this);
}
- if (list.size()>1) {
- throw new JbpmException("result not unique: "+list.size());
- }
- return list.get(0);
+ Session session = EnvironmentImpl.getFromCurrent(Session.class);
+ return execute(session);
}
public Object execute(Environment environment) throws Exception {
Session session = environment.get(Session.class);
- return execute(session);
- }
-
- public Object execute(Session session) {
- String hql = hql();
try {
- Query query = session.createQuery(hql);
- applyParameters(query);
- applyPage(query);
- return query.list();
- } catch (HibernateException e) {
- Throwable t = e;
- while (t!=null) {
- if (t instanceof SQLException) {
- SQLException sqlException = (SQLException) t;
- SQLException nextException = sqlException.getNextException();
- if (nextException!=null) {
- log.error("cause of "+nextException+": ", e);
- }
- }
- t = t.getCause();
- }
- throw e;
+ return execute(session);
} finally {
resetQuery(); // reset the query member fields so the query can be reused.
}
}
+
+ public Object execute(Session session) {
+ Query query = session.createQuery(hql());
+ applyParameters(query);
+ applyPage(query);
+ return uniqueResult ? query.uniqueResult() : query.list();
+ }
/**
* Returns the count of the query.
@@ -135,6 +121,7 @@
private void resetQuery() {
isWhereAdded = false;
count = false;
+ uniqueResult = false;
}
protected void appendWhereClause(String whereClause, StringBuilder hql) {
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.java 2010-06-13
05:17:29 UTC (rev 6410)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.java 2010-06-13
20:33:36 UTC (rev 6411)
@@ -102,7 +102,7 @@
}
public List<Deployment> list() {
- return untypedList();
+ return (List<Deployment>) untypedList();
}
public Deployment uniqueResult() {
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java 2010-06-13
05:17:29 UTC (rev 6410)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java 2010-06-13
20:33:36 UTC (rev 6411)
@@ -22,6 +22,7 @@
package org.jbpm.pvm.internal.query;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -62,20 +63,34 @@
protected String deploymentId;
public Object execute(Session session) {
- List<Map<String, Object>> propertyMaps = (List<Map<String,
Object>>) super.execute(session);
-
- List<ProcessDefinition> processDefinitions = new
ArrayList<ProcessDefinition>();
- for (Map<String, Object> properties: propertyMaps) {
- String deploymentId = properties.get("deploymentDbid").toString();
- String objectName = (String)properties.get("objectName");
- RepositorySession repositorySession =
EnvironmentImpl.getFromCurrent(RepositorySession.class);
- ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl)
repositorySession.getObject(deploymentId, objectName);
- processDefinitions.add(processDefinition);
+ Object result = super.execute(session);
+ RepositorySession repositorySession =
EnvironmentImpl.getFromCurrent(RepositorySession.class);
+
+ if (uniqueResult) {
+ if (result == null) return null;
+ return getProcessDefinition(repositorySession, result);
}
-
- return processDefinitions;
+ else {
+ List<?> propertyMaps = (List<?>) result;
+ if (propertyMaps.isEmpty()) return Collections.EMPTY_LIST;
+
+ List<ProcessDefinition> processDefinitions = new
ArrayList<ProcessDefinition>();
+ for (Object propertyObject: propertyMaps) {
+ ProcessDefinitionImpl processDefinition = getProcessDefinition(repositorySession,
propertyObject);
+ processDefinitions.add(processDefinition);
+ }
+ return processDefinitions;
+ }
}
+ private static ProcessDefinitionImpl getProcessDefinition(RepositorySession
repositorySession,
+ Object propertyObject) {
+ Map<?, ?> propertyMap = (Map<?, ?>) propertyObject;
+ String deploymentId = propertyMap.get("deploymentDbid").toString();
+ String objectName = (String)propertyMap.get("objectName");
+ return (ProcessDefinitionImpl) repositorySession.getObject(deploymentId,
objectName);
+ }
+
public String hql() {
StringBuilder hql = new StringBuilder();
hql.append("select new map( idProperty.objectName as objectName, " +
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java 2010-06-13
05:17:29 UTC (rev 6410)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java 2010-06-13
20:33:36 UTC (rev 6411)
@@ -21,10 +21,14 @@
*/
package org.jbpm.pvm.internal.query;
+import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.hibernate.Query;
+import org.hibernate.Session;
+
import org.jbpm.api.JbpmException;
import org.jbpm.api.TaskQuery;
import org.jbpm.api.identity.Group;
@@ -43,16 +47,15 @@
public class TaskQueryImpl extends AbstractQuery implements TaskQuery {
private static final long serialVersionUID = 1L;
-
- private static Log log = Log.getLog(TaskQueryImpl.class.getName());
+ private static final Log log = Log.getLog(TaskQueryImpl.class.getName());
- protected boolean unassigned = false;
- protected String assignee = null;
- protected String candidate = null;
- protected Boolean suspended = null;
- protected String processInstanceId = null;
- protected String processDefinitionId = null;
- protected String activityName = null;
+ protected boolean unassigned;
+ protected String assignee;
+ protected String candidate;
+ protected Boolean suspended;
+ protected String processInstanceId;
+ protected String processDefinitionId;
+ protected String activityName;
/* groupIds transports the groupIds from the hql to the applyParameters */
protected List<String> groupIds;
@@ -136,25 +139,20 @@
public String hql() {
StringBuilder hql = new StringBuilder();
- hql.append("select ");
+ hql.append("select ");
- if (count) {
- hql.append("count(distinct task) ");
- } else {
- hql.append("distinct task ");
- }
-
- hql.append("from ");
- hql.append(TaskImpl.class.getName());
- hql.append(" as task ");
-
// participations
if (candidate!=null) {
- hql.append(", ");
+ if (count) {
+ hql.append("count(distinct task.id) ");
+ } else {
+ hql.append("distinct task.id ");
+ }
+
+ hql.append("from ");
hql.append(ParticipationImpl.class.getName());
- hql.append(" as participant ");
+ hql.append(" as participant join participant.task as task ");
- appendWhereClause("participant.task = task ", hql);
appendWhereClause("participant.type = 'candidate' ", hql);
IdentitySession identitySession =
EnvironmentImpl.getFromCurrent(IdentitySession.class);
@@ -162,15 +160,26 @@
if (groups.isEmpty()) {
groupIds = null;
appendWhereClause("participant.userId = :candidateUserId ", hql);
-
- } else {
+ }
+ else {
groupIds = new ArrayList<String>();
for (Group group: groups) {
groupIds.add(group.getId());
}
- appendWhereClause("((participant.userId = :candidateUserId) or
(participant.groupId in (:candidateGroupIds)))", hql);
+ appendWhereClause("(participant.userId = :candidateUserId or
participant.groupId in (:candidateGroupIds))", hql);
}
}
+ else {
+ if (count) {
+ hql.append("count(task) ");
+ } else {
+ hql.append("task ");
+ }
+
+ hql.append("from ");
+ hql.append(TaskImpl.class.getName());
+ hql.append(" as task ");
+ }
if (suspended!=null) {
if (suspended) {
@@ -198,20 +207,44 @@
appendWhereClause("task.assignee is null ", hql);
}
- appendOrderByClause(hql);
+ if (candidate == null && !count)
+ appendOrderByClause(hql);
String hqlQuery = hql.toString();
-
log.debug(hqlQuery);
-
return hqlQuery;
}
+ @Override
+ public Object execute(Session session) {
+ Object result = super.execute(session);
+ if (candidate == null || count) return result;
+
+ if (uniqueResult) {
+ if (result == null) return null;
+ return session.get(TaskImpl.class, (Serializable) result);
+ }
+ else {
+ List<?> list = (List<?>) result;
+ if (list.isEmpty()) return Collections.EMPTY_LIST;
+
+ StringBuilder hql = new StringBuilder();
+ hql.append("from ").append(TaskImpl.class.getName()).append(" as
task ");
+ isWhereAdded = false;
+ appendWhereClause("task.id in (:identifiers) ", hql);
+ appendOrderByClause(hql);
+
+ return session.createQuery(hql.toString())
+ .setParameterList("identifiers", list)
+ .list();
+ }
+ }
+
public List<Task> list() {
return (List<Task>) commandService.execute(this);
}
public Task uniqueResult() {
- return (Task)untypedUniqueResult();
+ return (Task) untypedUniqueResult();
}
}
Modified:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/custom/CustomHistoryTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/custom/CustomHistoryTest.java 2010-06-13
05:17:29 UTC (rev 6410)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/custom/CustomHistoryTest.java 2010-06-13
20:33:36 UTC (rev 6411)
@@ -70,7 +70,7 @@
List<HistoryActivityInstance> histActivities = historyService
.createHistoryActivityInstanceQuery()
.processInstanceId(processInstance.getId())
- .orderAsc("startTime").list();
+ .orderAsc("id").list();
assertEquals(2, histActivities.size());
assertEquals("c", histActivities.get(0).getActivityName());
Modified:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java 2010-06-13
05:17:29 UTC (rev 6410)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java 2010-06-13
20:33:36 UTC (rev 6411)
@@ -330,7 +330,7 @@
List<HistoryActivityInstance> history = historyService
.createHistoryActivityInstanceQuery()
.processInstanceId(ids.get(0))
- .orderAsc("startTime").list();
+ .orderAsc("id").list();
//first check size of history entries
assertEquals(3, history.size());
@@ -349,7 +349,10 @@
public void testQueryByExecutionIdMissingTask() {
deployTestProcessWithTask();
List<String> ids = generateHistoryForTestProcessWithTask();
- List<HistoryActivityInstance> history =
historyService.createHistoryActivityInstanceQuery().executionId(ids.get(0)).list();
+ List<HistoryActivityInstance> history = historyService
+ .createHistoryActivityInstanceQuery()
+ .executionId(ids.get(0))
+ .orderAsc("id").list();
// check size of history entries
assertEquals(2, history.size());
Modified:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java 2010-06-13
05:17:29 UTC (rev 6410)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java 2010-06-13
20:33:36 UTC (rev 6411)
@@ -86,11 +86,11 @@
public void testOrderByName() {
testOrderBy(TaskQuery.PROPERTY_NAME,
- new String[] {"change dyper", "do laundry", "find
venture capital", "start new business"});
+ "change dyper", "do laundry", "find venture
capital", "start new business");
}
public void testOrderByAssignee() {
- testOrderBy(TaskQuery.PROPERTY_ASSIGNEE, new String[] {"Alex",
"Joram", "Koen", "Tom"});
+ testOrderBy(TaskQuery.PROPERTY_ASSIGNEE, "Alex", "Joram",
"Koen", "Tom");
}
public void testOrderByCreateTime() {
@@ -106,7 +106,7 @@
}
public void testOrderByProgress() {
- testOrderBy(TaskQuery.PROPERTY_PROGRESS, new Integer[] {2, 15, 75, 99});
+ testOrderBy(TaskQuery.PROPERTY_PROGRESS, 2, 15, 75, 99);
}
public void testCount() {
@@ -175,7 +175,7 @@
return result;
}
- private void testOrderBy(String property, Object[] expectedValues) {
+ private void testOrderBy(String property, Object... expectedValues) {
List<Task> tasks = createTestTasks();
List<Task> taskListAsc =
taskService.createTaskQuery().orderAsc(property).list();
Modified:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryCandidatesTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryCandidatesTest.java 2010-06-13
05:17:29 UTC (rev 6410)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryCandidatesTest.java 2010-06-13
20:33:36 UTC (rev 6411)
@@ -136,17 +136,16 @@
taskService.addTaskParticipatingGroup(taskId, salesGroupId,
Participation.CANDIDATE);
taskService.addTaskParticipatingGroup(taskId, developmentGroupId,
Participation.CANDIDATE);
- // this tasks are a diversion to see if the query only selects the above task
- task = taskService.newTask();
- task.setName("dishes");
- String johnsOtherTaskId = taskService.saveTask(task);
+// // this tasks are a diversion to see if the query only selects the above task
+// task = taskService.newTask();
+// task.setName("dishes");
+// String johnsOtherTaskId = taskService.saveTask(task);
+//
+// // this tasks are a diversion to see if the query only selects the above task
+// task = taskService.newTask();
+// task.setName("dishes");
+// String joesOtherTaskId = taskService.saveTask(task);
- // this tasks are a diversion to see if the query only selects the above task
- task = taskService.newTask();
- task.setName("dishes");
- String joesOtherTaskId = taskService.saveTask(task);
-
-
List<Task> groupTasks = taskService.findGroupTasks("johndoe");
assertEquals(1, groupTasks.size());
assertEquals(taskId, groupTasks.get(0).getId());
@@ -159,8 +158,8 @@
assertEquals(1, groupTasks.size());
taskService.deleteTaskCascade(taskId);
- taskService.deleteTaskCascade(johnsOtherTaskId);
- taskService.deleteTaskCascade(joesOtherTaskId);
+// taskService.deleteTaskCascade(johnsOtherTaskId);
+// taskService.deleteTaskCascade(joesOtherTaskId);
}
public void testCountGroupCandidateDuplicate() {
@@ -186,7 +185,7 @@
taskService.addTaskParticipatingUser(taskId, "boss_rigging",
Participation.CANDIDATE);
taskService.addTaskParticipatingUser(taskId, "boss_rigging",
Participation.CANDIDATE);
- assertEquals(1,
taskService.createTaskQuery().candidate("boss_rigging").list().size());
+ assertEquals(1,
taskService.createTaskQuery().candidate("boss_rigging").count());
taskService.deleteTaskCascade(taskId);
}
Modified: jbpm4/trunk/pom.xml
===================================================================
--- jbpm4/trunk/pom.xml 2010-06-13 05:17:29 UTC (rev 6410)
+++ jbpm4/trunk/pom.xml 2010-06-13 20:33:36 UTC (rev 6411)
@@ -444,16 +444,11 @@
<configuration>
<source>1.5</source>
<target>1.5</target>
- <showDeprecation>true</showDeprecation>
- <showWarnings>true</showWarnings>
- <optimize>true</optimize>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <failIfNoTests>false</failIfNoTests>
- <trimStackTrace>false</trimStackTrace>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<excludes>
<exclude>**/*TestCase.java</exclude>