提交 e622e3b5 编写于 作者: T tombaeyens

ACT-80 fixing various persistence related problems

上级 def4247c
......@@ -32,12 +32,12 @@ public class CallActivityTest extends ProcessEngineTestCase {
// After the process has started, the 'verify credit history' task should be active
runtimeService.startProcessInstanceByKey("orderProcess");
TaskQuery taskQuery = taskService.createTaskQuery();
Task verifyCreditTask = taskQuery.singleResult();
Task verifyCreditTask = taskQuery.listPage();
assertEquals("Verify credit history", verifyCreditTask.getName());
// Completing the task with approval, will end the subprocess and continue the original process
taskService.complete(verifyCreditTask.getId(), CollectionUtil.singletonMap("creditApproved", true));
Task prepareAndShipTask = taskQuery.singleResult();
Task prepareAndShipTask = taskQuery.listPage();
assertEquals("Prepare and Ship", prepareAndShipTask.getName());
}
}
......@@ -34,7 +34,7 @@ public class BoundaryTimerEventTest extends ProcessEngineTestCase {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("interruptingBoundaryTimer");
// There should be one task, with a timer : first line support
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).listPage();
assertEquals("First line support", task.getName());
// Set clock to the future such that the timer can fire
......@@ -42,7 +42,7 @@ public class BoundaryTimerEventTest extends ProcessEngineTestCase {
waitForJobExecutorToProcessAllJobs(10000L, 250L);
// The timer has fired, and the second task (secondlinesupport) now exists
task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
task = taskService.createTaskQuery().processInstanceId(pi.getId()).listPage();
assertEquals("Second line support", task.getName());
}
......
......@@ -31,14 +31,14 @@ public class UelExpressionTest extends ProcessEngineTestCase {
UelExpressionTestOrder order = new UelExpressionTestOrder(150);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("uelExpressions",
CollectionUtil.singletonMap("order", order));
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).listPage();
assertEquals("Standard service", task.getName());
// While an order of 300, gives us a premium service (goes through an UEL method expression)
order = new UelExpressionTestOrder(300);
processInstance = runtimeService.startProcessInstanceByKey("uelExpressions",
CollectionUtil.singletonMap("order", order));
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).listPage();
assertEquals("Premium service", task.getName());
}
......
......@@ -41,19 +41,19 @@ public class ExclusiveGatewayTest extends ProcessEngineTestCase {
// Test with input == 1
variables.put("input", 1);
ProcessInstance pi = runtimeService.startProcessInstanceByKey("exclusiveGateway", variables);
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).listPage();
assertEquals("Send e-mail for more information", task.getName());
// Test with input == 2
variables.put("input", 2);
pi = runtimeService.startProcessInstanceByKey("exclusiveGateway", variables);
task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
task = taskService.createTaskQuery().processInstanceId(pi.getId()).listPage();
assertEquals("Check account balance", task.getName());
// Test with input == 3
variables.put("input", 3);
pi = runtimeService.startProcessInstanceByKey("exclusiveGateway", variables);
task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
task = taskService.createTaskQuery().processInstanceId(pi.getId()).listPage();
assertEquals("Call customer", task.getName());
// Test with input == 4
......
......@@ -30,7 +30,7 @@ public class ReceiveTaskTest extends ProcessEngineTestCase {
Execution execution = runtimeService.createExecutionQuery()
.processInstanceId(pi.getId())
.activityId("waitState")
.singleResult();
.listPage();
assertNotNull(execution);
runtimeService.signal(execution.getId());
......
......@@ -29,7 +29,7 @@ public class JavaServiceTaskTest extends ProcessEngineTestCase {
Execution execution = runtimeService.createExecutionQuery()
.processInstanceId(pi.getId())
.activityId("waitState")
.singleResult();
.listPage();
assertEquals("ACTIVITI BPM ENGINE", runtimeService.getVariable(execution.getId(), "input"));
}
......
......@@ -50,7 +50,7 @@ public class SubProcessTest extends ProcessEngineTestCase {
// Completing boith the tasks finishes the subprocess and enables the task after the subprocess
taskService.complete(investigateHardwareTask.getId());
taskService.complete(investigateSoftwareTask.getId());
Task writeReportTask = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
Task writeReportTask = taskService.createTaskQuery().processInstanceId(pi.getId()).listPage();
assertEquals("Write report", writeReportTask.getName());
// Clean up
......
......@@ -31,22 +31,18 @@ public class TablePageQueryTest extends ProcessEngineTestCase {
TablePage tablePage = managementService.createTablePageQuery()
.tableName("ACT_TASK")
.start(0)
.size(5)
.singleResult();
.listPage(0, 5);
assertEquals(0, tablePage.getStart());
assertEquals(0, tablePage.getFirstResult());
assertEquals(5, tablePage.getSize());
assertEquals(5, tablePage.getRows().size());
assertEquals(20, tablePage.getTotal());
tablePage = managementService.createTablePageQuery()
.tableName("ACT_TASK")
.start(14)
.size(10)
.singleResult();
.listPage(14, 10);
assertEquals(14, tablePage.getStart());
assertEquals(14, tablePage.getFirstResult());
assertEquals(6, tablePage.getSize());
assertEquals(6, tablePage.getRows().size());
assertEquals(20, tablePage.getTotal());
......@@ -60,20 +56,16 @@ public class TablePageQueryTest extends ProcessEngineTestCase {
// With an ascending sort
TablePage tablePage = managementService.createTablePageQuery()
.tableName("ACT_TASK")
.start(1)
.size(7)
.orderAsc("NAME_")
.singleResult();
.listPage(1, 7);
String[] expectedTaskNames = new String[] {"B", "C", "D", "E", "F", "G", "H"};
verifyTaskNames(expectedTaskNames, tablePage.getRows());
// With a descending sort
tablePage = managementService.createTablePageQuery()
.tableName("ACT_TASK")
.start(6)
.size(8)
.orderDesc("NAME_")
.singleResult();
.listPage(6, 8);
expectedTaskNames = new String[] {"I", "H", "G", "F", "E", "D", "C", "B"} ;
verifyTaskNames(expectedTaskNames, tablePage.getRows());
......
......@@ -93,11 +93,17 @@ public class ProcessDefinitionsTest extends ProcessEngineTestCase {
.list();
assertNotNull(processDefinitions);
assertEquals(1, processDefinitions.size());
assertEquals(2, processDefinitions.size());
ProcessDefinition processDefinition = processDefinitions.get(0);
assertEquals("IDR", processDefinition.getKey());
assertEquals("Insurance Damage Report", processDefinition.getName());
assertEquals("IDR:2", processDefinition.getId());
assertEquals(2, processDefinition.getVersion());
processDefinition = processDefinitions.get(1);
assertEquals("IDR", processDefinition.getKey());
assertEquals("Insurance Damage Report", processDefinition.getName());
assertEquals("IDR:1", processDefinition.getId());
assertEquals(1, processDefinition.getVersion());
......@@ -114,6 +120,4 @@ public class ProcessDefinitionsTest extends ProcessEngineTestCase {
repositoryService.deleteDeployment(deploymentId);
}
}
}
......@@ -51,7 +51,7 @@ public class TaskFormsTest extends ProcessEngineTestCase {
runtimeService.startProcessInstanceByKey("vacationRequest", parameters);
// Management should now have a task assigned to them
Task task = taskService.createTaskQuery().candidateGroup("management").singleResult();
Task task = taskService.createTaskQuery().candidateGroup("management").listPage();
assertEquals("Vacation request by kermit", task.getDescription());
Object taskForm = taskService.getTaskForm(task.getId());
assertNotNull(taskForm);
......@@ -63,7 +63,7 @@ public class TaskFormsTest extends ProcessEngineTestCase {
assertNull(repositoryService.getStartFormByKey("noStartOrTaskForm"));
runtimeService.startProcessInstanceByKey("noStartOrTaskForm");
Task task = taskService.createTaskQuery().singleResult();
Task task = taskService.createTaskQuery().listPage();
assertNull(taskService.getTaskForm(task.getId()));
}
......
......@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.examples.mgmt;
package org.activiti.test.processengines;
import java.util.List;
......@@ -19,6 +19,7 @@ import junit.framework.TestCase;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineInfo;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.test.ProcessEngineTestCase;
/**
* @author Tom Baeyens
......@@ -28,6 +29,7 @@ public class ProcessEnginesTest extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
ProcessEngineTestCase.closeProcessEngines();
ProcessEngines.init();
}
......
......@@ -28,7 +28,7 @@ public interface ExecutionQuery {
ExecutionQuery processDefinitionId(String processDefinitionId);
List<Execution> list();
List<Execution> paginatedList(int start, int maxResults);
Execution singleResult();
List<Execution> listPage(int start, int maxResults);
Execution listPage();
long count();
}
......@@ -31,10 +31,10 @@ public interface JobQuery {
long count();
Job singleResult();
Job listPage();
List<Job> list();
List<Job> paginatedList(int start, int size);
List<Job> listPage(int start, int size);
}
......@@ -17,24 +17,23 @@ package org.activiti.engine;
* holds the parameters of a page (partial result) for a query.
*
* @author Joram Barrez
* @author Tom Baeyens
*/
public class Page {
protected int offset;
protected int firstResult;
protected int maxResults;
public Page(int offset, int maxResults) {
this.offset = offset;
public Page(int firstResult, int maxResults) {
this.firstResult = firstResult;
this.maxResults = maxResults;
}
public int getOffset() {
return offset;
public int getFirstResult() {
return firstResult;
}
public int getMaxResults() {
return maxResults;
}
}
......@@ -33,9 +33,9 @@ public interface ProcessDefinitionQuery {
long count();
ProcessDefinition singleResult();
ProcessDefinition listPage();
List<ProcessDefinition> list();
List<ProcessDefinition> paginatedList(int start, int size);
List<ProcessDefinition> listPage(int start, int size);
}
......@@ -26,7 +26,7 @@ public interface ProcessInstanceQuery {
ProcessInstanceQuery processDefinitionKey(String processDefinitionKey);
List<ProcessInstance> list();
List<ProcessInstance> paginatedList(int start, int maxResults);
ProcessInstance singleResult();
List<ProcessInstance> listPage(int start, int maxResults);
ProcessInstance listPage();
long count();
}
......@@ -37,7 +37,7 @@ public class TablePage {
* For example in a paginated database table, this value identifies the record number of
* the result on the first row.
*/
protected long start;
protected long firstResult;
/**
* Indicates the key or column on which the signalData is sorted.
......@@ -62,13 +62,6 @@ public class TablePage {
}
public TablePage(String tableName, long start, long total, List<Map<String, Object>> rowData) {
this.tableName = tableName;
this.start = start;
this.total = total;
this.rowData = rowData;
}
public String getTableName() {
return tableName;
}
......@@ -81,12 +74,12 @@ public class TablePage {
* @return the start index of this page
* (ie the index of the first element in the page)
*/
public long getStart() {
return start;
public long getFirstResult() {
return firstResult;
}
public void setStart(long start) {
this.start = start;
public void setFirstResult(long firstResult) {
this.firstResult = firstResult;
}
public void setRows(List<Map<String, Object>> rowData) {
......
......@@ -24,17 +24,6 @@ public interface TablePageQuery {
*/
TablePageQuery tableName(String tableName);
/**
* the record number of the first element of the page.
* Note that this is zero-based (ie. the first element has index '0')
*/
TablePageQuery start(int start);
/**
* the number of elements that the page maximum can contain
*/
TablePageQuery size(int size);
/**
* orders the resulting table page rows by the given column in ascending order.
*/
......@@ -48,6 +37,5 @@ public interface TablePageQuery {
/**
* executes the query and returns the {@link TablePage}.
*/
TablePage singleResult();
TablePage listPage(int firstResult, int maxResults);
}
......@@ -42,10 +42,10 @@ public interface TaskQuery {
long count();
Task singleResult();
Task listPage();
List<Task> list();
List<Task> paginatedList(int start, int size);
List<Task> listPage(int start, int size);
}
......@@ -16,7 +16,6 @@ import java.util.List;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.Page;
import org.activiti.engine.SortOrder;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.interceptor.CommandExecutor;
......@@ -33,14 +32,14 @@ public abstract class AbstractQuery<T> implements Command<Object>{
protected static final String SORTORDER_DESC = "desc";
private static enum ResultType {
LIST, PAGINATED_LIST, SINGLE_RESULT, COUNT
LIST, LIST_PAGE, SINGLE_RESULT, COUNT
}
protected CommandExecutor commandExecutor;
protected String orderBy;
protected int start;
protected int size;
protected int firstResult;
protected int maxResults;
protected ResultType resultType;
protected AbstractQuery() {
......@@ -51,7 +50,7 @@ public abstract class AbstractQuery<T> implements Command<Object>{
}
@SuppressWarnings("unchecked")
public T singleResult() {
public T listPage() {
this.resultType = ResultType.SINGLE_RESULT;
return (T) commandExecutor.execute(this);
}
......@@ -63,10 +62,10 @@ public abstract class AbstractQuery<T> implements Command<Object>{
}
@SuppressWarnings("unchecked")
public List<T> paginatedList(int start, int size) {
this.start = start;
this.size = size;
this.resultType = ResultType.PAGINATED_LIST;
public List<T> listPage(int firstResult, int maxResults) {
this.firstResult = firstResult;
this.maxResults = maxResults;
this.resultType = ResultType.LIST_PAGE;
return (List) commandExecutor.execute(this);
}
......@@ -80,8 +79,8 @@ public abstract class AbstractQuery<T> implements Command<Object>{
return executeList(commandContext, null);
} else if (resultType==ResultType.SINGLE_RESULT) {
return executeSingleResult(commandContext);
} else if (resultType==ResultType.PAGINATED_LIST) {
return executeList(commandContext, new Page(start, size));
} else if (resultType==ResultType.LIST_PAGE) {
return executeList(commandContext, new Page(firstResult, maxResults));
} else {
return executeCount(commandContext);
}
......@@ -111,7 +110,7 @@ public abstract class AbstractQuery<T> implements Command<Object>{
} else {
orderBy = orderBy+", ";
}
orderBy += orderBy+column+" "+sortOrder;
orderBy = orderBy+column+" "+sortOrder;
}
public String getOrderBy() {
......
......@@ -84,7 +84,7 @@ public class ExecutionQueryImpl extends AbstractQuery<Execution> implements Exec
public List<Execution> executeList(CommandContext commandContext, Page page) {
return (List) commandContext
.getRuntimeSession()
.findExecutionsByQueryCriteria(this);
.findExecutionsByQueryCriteria(this, page);
}
public String getProcessDefinitionKey() {
......
......@@ -85,7 +85,7 @@ public class ProcessInstanceQueryImpl extends AbstractQuery<ProcessInstance> imp
public List<ProcessInstance> executeList(CommandContext commandContext, Page page) {
return (List) commandContext
.getRuntimeSession()
.findExecutionsByQueryCriteria(this);
.findExecutionsByQueryCriteria(this, page);
}
public String getProcessDefinitionKey() {
......
......@@ -12,8 +12,6 @@
*/
package org.activiti.engine.impl;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.SortOrder;
import org.activiti.engine.TablePage;
import org.activiti.engine.TablePageQuery;
import org.activiti.engine.impl.interceptor.Command;
......@@ -25,63 +23,59 @@ import org.activiti.engine.impl.interceptor.CommandExecutor;
*
* @author Joram Barrez
*/
public class TablePageQueryImpl implements TablePageQuery {
public class TablePageQueryImpl implements TablePageQuery, Command<TablePage> {
protected CommandExecutor commandExecutor;
CommandExecutor commandExecutor;
protected String tableName;
protected int start = -1;
protected int maxRows = -1;
protected String sortColumn;
protected SortOrder sortOrder;
protected String orderBy;
protected int firstResult;
protected int maxResults;
public TablePageQueryImpl() {
}
public TablePageQueryImpl(CommandExecutor commandExecutor) {
this.commandExecutor = commandExecutor;
}
public TablePageQuery tableName(String tableName) {
public TablePageQueryImpl tableName(String tableName) {
this.tableName = tableName;
return this;
}
public TablePageQuery start(int start) {
this.start = start;
public TablePageQueryImpl orderAsc(String column) {
addOrder(column, AbstractQuery.SORTORDER_ASC);
return this;
}
public TablePageQuery size(int size) {
this.maxRows = size;
public TablePageQueryImpl orderDesc(String column) {
addOrder(column, AbstractQuery.SORTORDER_DESC);
return this;
}
public TablePageQuery orderAsc(String column) {
if (sortColumn != null) {
throw new ActivitiException("Invalid usage: cannot use both orderAsc and orderDesc in same query");
}
this.sortOrder = SortOrder.ASC;
this.sortColumn = column;
return this;
public String getTableName() {
return tableName;
}
public TablePageQuery orderDesc(String column) {
if (sortColumn != null) {
throw new ActivitiException("Invalid usage: cannot use both orderAsc and orderDesc in same query");
protected void addOrder(String column, String sortOrder) {
if (orderBy==null) {
orderBy = "";
} else {
orderBy = orderBy+", ";
}
this.sortOrder = SortOrder.DESC;
this.sortColumn = column;
return this;
orderBy = orderBy+column+" "+sortOrder;
}
public TablePage singleResult() {
return commandExecutor.execute(new Command<TablePage>() {
public TablePage execute(CommandContext commandContext) {
if (tableName == null || start == -1 || maxRows == -1) {
throw new ActivitiException("Table name, offset and maxResults are " +
"minimally needed to execute a TablePageQuery");
public TablePage listPage(int firstResult, int maxResults) {
this.firstResult = firstResult;
this.maxResults = maxResults;
return commandExecutor.execute(this);
}
return commandContext.getManagementSession()
.getTablePage(tableName, start, maxRows, sortColumn, sortOrder);
};
});
public TablePage execute(CommandContext commandContext) {
return commandContext
.getManagementSession()
.getTablePage(this, firstResult, maxResults);
}
}
......@@ -70,7 +70,7 @@ public class TaskServiceImpl extends ServiceImpl implements TaskService {
public List<Task> findAssignedTasks(String assignee, Page page) {
TaskQuery query = createTaskQuery().assignee(assignee);
if (page != null) {
return query.paginatedList(page.getOffset(), page.getMaxResults());
return query.listPage(page.getFirstResult(), page.getMaxResults());
} else {
return query.list();
}
......@@ -83,7 +83,7 @@ public class TaskServiceImpl extends ServiceImpl implements TaskService {
public List<Task> findUnassignedTasks(String userId, Page page) {
TaskQuery query = createTaskQuery().candidateUser(userId);
if (page != null) {
return query.paginatedList(page.getOffset(), page.getMaxResults());
return query.listPage(page.getFirstResult(), page.getMaxResults());
} else {
return query.list();
}
......
......@@ -38,9 +38,11 @@ public class BpmnDeployer implements Deployer, ProcessEngineConfigurationAware {
public static final String BPMN_RESOURCE_SUFFIX = "bpmn20.xml";
protected ExpressionManager expressionManager;
protected BpmnParser bpmnParser;
public void configurationCompleted(ProcessEngineConfiguration processEngineConfiguration) {
this.expressionManager = processEngineConfiguration.getExpressionManager();
this.bpmnParser = new BpmnParser(expressionManager);
}
public List<ProcessDefinitionEntity> deploy(DeploymentEntity deployment) {
......@@ -54,7 +56,7 @@ public class BpmnDeployer implements Deployer, ProcessEngineConfigurationAware {
ResourceEntity resource = resources.get(resourceName);
byte[] bytes = resource.getBytes();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
BpmnParse bpmnParse = new BpmnParser(expressionManager)
BpmnParse bpmnParse = bpmnParser
.createParse()
.sourceInputStream(inputStream)
.name(resourceName)
......
......@@ -15,9 +15,9 @@ package org.activiti.engine.impl.cfg;
import java.util.Map;
import org.activiti.engine.SortOrder;
import org.activiti.engine.TableMetaData;
import org.activiti.engine.TablePage;
import org.activiti.engine.impl.TablePageQueryImpl;
import org.activiti.engine.impl.persistence.db.IdBlock;
......@@ -28,7 +28,7 @@ public interface ManagementSession {
/* Management */
Map<String, Long> getTableCount();
TablePage getTablePage(String tableName, int offset, int maxResults, String sortColumn, SortOrder sortOrder);
TablePage getTablePage(TablePageQueryImpl tablePageQuery, int firstResult, int maxResults);
TableMetaData getTableMetaData(String tableName);
IdBlock getNextIdBlock();
......
......@@ -34,7 +34,7 @@ public interface RuntimeSession {
void deleteProcessInstance(String processInstanceId, String deleteReason);
ExecutionEntity findSubProcessInstanceBySuperExecutionId(String superExecutionId);
long findExecutionCountByQueryCriteria(Object executionQuery);
List<ExecutionEntity> findExecutionsByQueryCriteria(Object executionQuery);
List<ExecutionEntity> findExecutionsByQueryCriteria(Object executionQuery, Page page);
List<ExecutionEntity> findChildExecutionsByParentExecutionId(String executionId);
ExecutionEntity findExecutionById(String activityInstanceId);
......@@ -46,9 +46,9 @@ public interface RuntimeSession {
JobEntity findJobById(String jobId);
List<JobEntity> findJobs();
List<JobEntity> findNextJobsToExecute(int maxNrOfJobs);
List<JobEntity> findNextJobsToExecute(Page page);
List<JobEntity> findLockedJobs();
List<TimerEntity> findUnlockedTimersByDuedate(Date duedate, int nrOfTimers);
List<TimerEntity> findUnlockedTimersByDuedate(Date duedate, Page page);
List<TimerEntity> findTimersByExecutionId(String executionId);
List<Job> findJobsByQueryCriteria(JobQueryImpl jobQuery, Page page);
long findJobCountByQueryCriteria(JobQueryImpl jobQuery);
......
......@@ -17,6 +17,7 @@ import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import org.activiti.engine.Page;
import org.activiti.engine.impl.cfg.RuntimeSession;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
......@@ -44,7 +45,7 @@ public class AcquireJobsCmd implements Command<AcquiredJobs> {
AcquiredJobs acquiredJobs = new AcquiredJobs();
List<JobEntity> jobs = runtimeSession.findNextJobsToExecute(maxJobsPerAcquisition);
List<JobEntity> jobs = runtimeSession.findNextJobsToExecute(new Page(0, maxJobsPerAcquisition));
for (JobEntity job: jobs) {
List<String> jobIds = new ArrayList<String>();
......
......@@ -15,6 +15,7 @@ package org.activiti.engine.impl.jobexecutor;
import java.util.Date;
import java.util.List;
import org.activiti.engine.Page;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.persistence.runtime.TimerEntity;
......@@ -27,15 +28,14 @@ import org.activiti.engine.impl.persistence.runtime.TimerEntity;
public class GetUnlockedTimersByDuedateCmd implements Command<List<TimerEntity>> {
protected Date duedate;
protected Page page;
protected int nrOfTimers = -1;
public GetUnlockedTimersByDuedateCmd(Date duedate, int nrOfTimers) {
public GetUnlockedTimersByDuedateCmd(Date duedate, Page page) {
this.duedate = duedate;
this.nrOfTimers = nrOfTimers;
this.page = page;
}
public List<TimerEntity> execute(CommandContext commandContext) {
return commandContext.getRuntimeSession().findUnlockedTimersByDuedate(duedate, nrOfTimers);
return commandContext.getRuntimeSession().findUnlockedTimersByDuedate(duedate, page);
}
}
......@@ -17,6 +17,7 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.activiti.engine.Page;
import org.activiti.engine.impl.interceptor.CommandExecutor;
import org.activiti.engine.impl.persistence.runtime.TimerEntity;
import org.activiti.engine.impl.util.ClockUtil;
......@@ -73,7 +74,7 @@ public class JobAcquisitionThread extends Thread {
// check if the next timer should fire before the normal sleep time is over
Date duedate = new Date(ClockUtil.getCurrentTime().getTime() + millisToWait);
List<TimerEntity> nextTimers = commandExecutor.execute(new GetUnlockedTimersByDuedateCmd(duedate, 1));
List<TimerEntity> nextTimers = commandExecutor.execute(new GetUnlockedTimersByDuedateCmd(duedate, new Page(0, 1)));
if (!nextTimers.isEmpty()) {
long millisTillNextTimer = nextTimers.get(0).getDuedate().getTime() - ClockUtil.getCurrentTime().getTime();
......
......@@ -43,6 +43,8 @@ public class TimerExecuteNestedActivityJobHandler implements JobHandler {
}
try {
execution.setActivity(borderEventActivity);
borderEventActivity
.getActivityBehavior()
.execute(execution);
......
......@@ -24,13 +24,14 @@ import java.util.logging.Logger;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.ActivitiOptimisticLockingException;
import org.activiti.engine.SortOrder;
import org.activiti.engine.TableMetaData;
import org.activiti.engine.TablePage;
import org.activiti.engine.impl.TablePageQueryImpl;
import org.activiti.engine.impl.cfg.ManagementSession;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.interceptor.Session;
import org.activiti.engine.impl.persistence.repository.PropertyEntity;
import org.apache.ibatis.session.RowBounds;
/**
......@@ -84,32 +85,19 @@ public class DbManagementSession implements ManagementSession, Session {
}
@SuppressWarnings("unchecked")
public TablePage getTablePage(String tableName, int offset, int maxResults,
String sortColumn, SortOrder sortOrder) {
public TablePage getTablePage(TablePageQueryImpl tablePageQuery, int firstResult, int maxResults) {
TablePage tablePage = new TablePage();
Map<String, String> params = new HashMap<String, String>();
params.put("tableName", tableName);
if (sortColumn != null) {
params.put("sortColumn", sortColumn);
if (sortOrder.equals(SortOrder.ASC)) {
params.put("sortOrder", "asc");
} else {
params.put("sortOrder", "desc");
}
tablePage.setSort(sortColumn);
tablePage.setOrder(sortOrder);
}
List<Map<String, Object>> tableData =
(List<Map<String, Object>>) dbSqlSession.selectList("selectTableData", params, offset, maxResults);
List<Map<String, Object>> tableData = (List<Map<String, Object>>) dbSqlSession
.getSqlSession()
.selectList("selectTableData", tablePageQuery, new RowBounds(firstResult, maxResults));
tablePage.setTableName(tableName);
tablePage.setStart(offset);
tablePage.setTotal(getTableCount(tableName));
tablePage.setTableName(tablePageQuery.getTableName());
tablePage.setTotal(getTableCount(tablePageQuery.getTableName()));
tablePage.setRows(tableData);
tablePage.setFirstResult(firstResult);
return tablePage;
}
......@@ -162,5 +150,4 @@ public class DbManagementSession implements ManagementSession, Session {
public void flush() {
}
}
......@@ -55,7 +55,19 @@ public class DbRepositorySession implements Session, RepositorySession {
for (Deployer deployer: dbRepositorySessionFactory.getDeployers()) {
List<ProcessDefinitionEntity> processDefinitions = deployer.deploy(deployment);
for (ProcessDefinitionEntity processDefinition : processDefinitions) {
int processDefinitionVersion;
ProcessDefinitionEntity latestProcessDefinition = findLatestProcessDefinitionByKey(processDefinition.getKey());
if (latestProcessDefinition!=null) {
processDefinitionVersion = latestProcessDefinition.getVersion()+1;
} else {
processDefinitionVersion = 1;
}
processDefinition.setVersion(processDefinitionVersion);
processDefinition.setDeploymentId(deployment.getId());
processDefinition.setId(processDefinition.getKey()+":"+processDefinition.getVersion());
dbSqlSession.insert(processDefinition);
addToProcessDefinitionCache(processDefinition);
}
......@@ -157,6 +169,10 @@ public class DbRepositorySession implements Session, RepositorySession {
return (ProcessDefinitionEntity) dbSqlSession.selectOne("selectProcessDefinitionById", processDefinitionId);
}
protected ProcessDefinitionEntity findLatestProcessDefinitionByKey(String processDefinitionKey) {
return (ProcessDefinitionEntity) dbSqlSession.selectOne("selectLatestProcessDefinitionByKey", processDefinitionKey);
}
public ProcessDefinitionEntity findDeployedLatestProcessDefinitionByKey(String processDefinitionKey) {
ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) dbSqlSession.selectOne("selectLatestProcessDefinitionByKey", processDefinitionKey);
processDefinition = resolveProcessDefinition(processDefinition);
......@@ -190,11 +206,7 @@ public class DbRepositorySession implements Session, RepositorySession {
@SuppressWarnings("unchecked")
public List<ProcessDefinition> findProcessDefinitionsByQueryCriteria(ProcessDefinitionQueryImpl processDefinitionQuery, Page page) {
final String query = "selectProcessDefinitionsByQueryCriteria";
if (page == null) {
return dbSqlSession.selectList(query, processDefinitionQuery);
} else {
return dbSqlSession.selectList(query, processDefinitionQuery, page.getOffset(), page.getMaxResults());
}
return dbSqlSession.selectList(query, processDefinitionQuery, page);
}
public long findProcessDefinitionCountByQueryCriteria(ProcessDefinitionQueryImpl processDefinitionQuery) {
......
......@@ -55,8 +55,8 @@ public class DbRuntimeSession implements Session, RuntimeSession {
}
@SuppressWarnings("unchecked")
public List<ExecutionEntity> findExecutionsByQueryCriteria(Object executionQuery) {
return dbSqlSession.selectList("selectExecutionsByQueryCriteria", executionQuery);
public List<ExecutionEntity> findExecutionsByQueryCriteria(Object executionQuery, Page page) {
return dbSqlSession.selectList("selectExecutionsByQueryCriteria", executionQuery, page);
}
public ExecutionEntity findExecutionById(String executionId) {
......@@ -106,9 +106,9 @@ public class DbRuntimeSession implements Session, RuntimeSession {
}
@SuppressWarnings("unchecked")
public List<JobEntity> findNextJobsToExecute(int maxNrOfJobs) {
public List<JobEntity> findNextJobsToExecute(Page page) {
Date now = ClockUtil.getCurrentTime();
return dbSqlSession.selectList("selectNextJobsToExecute", now, 0, maxNrOfJobs);
return dbSqlSession.selectList("selectNextJobsToExecute", now, page);
}
@SuppressWarnings("unchecked")
......@@ -117,13 +117,9 @@ public class DbRuntimeSession implements Session, RuntimeSession {
}
@SuppressWarnings("unchecked")
public List<TimerEntity> findUnlockedTimersByDuedate(Date duedate, int nrOfTimers) {
public List<TimerEntity> findUnlockedTimersByDuedate(Date duedate, Page page) {
final String query = "selectUnlockedTimersByDuedate";
if (nrOfTimers > 0) {
return dbSqlSession.selectList(query, duedate, 0, nrOfTimers);
} else {
return dbSqlSession.selectList(query, duedate);
}
return dbSqlSession.selectList(query, duedate, page);
}
@SuppressWarnings("unchecked")
......@@ -134,11 +130,7 @@ public class DbRuntimeSession implements Session, RuntimeSession {
@SuppressWarnings("unchecked")
public List<Job> findJobsByQueryCriteria(JobQueryImpl jobQuery, Page page) {
final String query = "org.activiti.persistence.selectJobByQueryCriteria";
if (page == null) {
return dbSqlSession.selectList(query, jobQuery);
} else {
return dbSqlSession.selectList(query, jobQuery, page.getOffset(), page.getMaxResults());
}
return dbSqlSession.selectList(query, jobQuery, page);
}
public long findJobCountByQueryCriteria(JobQueryImpl jobQuery) {
......
......@@ -21,6 +21,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.Page;
import org.activiti.engine.impl.interceptor.Session;
import org.activiti.engine.impl.persistence.PersistentObject;
import org.activiti.engine.impl.persistence.runtime.VariableInstanceEntity;
......@@ -143,9 +144,14 @@ public class DbSqlSession implements Session {
}
@SuppressWarnings("unchecked")
public List selectList(String statement, Object parameter, int offset, int maxResults) {
public List selectList(String statement, Object parameter, Page page) {
statement = dbSqlSessionFactory.mapStatement(statement);
List loadedObjects = sqlSession.selectList(statement, parameter, new RowBounds(offset, maxResults));
List loadedObjects;
if (page!=null) {
loadedObjects = sqlSession.selectList(statement, parameter, new RowBounds(page.getFirstResult(), page.getMaxResults()));
} else {
loadedObjects = sqlSession.selectList(statement, parameter);
}
return filterLoadedObjects(loadedObjects);
}
......
......@@ -55,11 +55,7 @@ public class DbTaskSession implements TaskSession, Session {
@SuppressWarnings("unchecked")
public List<Task> findTasksByQueryCriteria(TaskQueryImpl taskQuery, Page page) {
final String query = "selectTaskByQueryCriteria";
if (page == null) {
return dbSqlSession.selectList(query, taskQuery);
} else {
return dbSqlSession.selectList(query, taskQuery, page.getOffset(), page.getMaxResults());
}
return dbSqlSession.selectList(query, taskQuery, page);
}
public long findTaskCountByQueryCriteria(TaskQueryImpl taskQuery) {
......
......@@ -27,13 +27,10 @@ public class ByteArrayEntity implements Serializable, PersistentObject {
private static final Object PERSISTENTSTATE_NULL = new Object();
protected String id;
protected int revision;
protected String name;
protected byte[] bytes;
protected String deploymentId;
protected ByteArrayType variable;
public ByteArrayEntity() {
......@@ -50,13 +47,6 @@ public class ByteArrayEntity implements Serializable, PersistentObject {
}
public byte[] getBytes() {
// // the bytes are lazy initialized
// if (bytes == null) {
// bytes = CommandContext
// .getCurrent()
// .getPersistenceSession()
// .getByteArrayBytes(id);
// }
return bytes;
}
......@@ -64,6 +54,10 @@ public class ByteArrayEntity implements Serializable, PersistentObject {
return (bytes != null ? bytes : PERSISTENTSTATE_NULL);
}
public int getRevisionNext() {
return revision+1;
}
// getters and setters //////////////////////////////////////////////////////
public String getId() {
......@@ -84,5 +78,10 @@ public class ByteArrayEntity implements Serializable, PersistentObject {
public void setBytes(byte[] bytes) {
this.bytes = bytes;
}
public int getRevision() {
return revision;
}
public void setRevision(int revision) {
this.revision = revision;
}
}
......@@ -39,6 +39,7 @@ public abstract class JobEntity implements Serializable, Job, PersistentObject {
private static final long serialVersionUID = 1L;
protected String id;
protected int revision;
protected Date duedate;
......@@ -74,6 +75,10 @@ public abstract class JobEntity implements Serializable, Job, PersistentObject {
return persistentState;
}
public int getRevisionNext() {
return revision+1;
}
public void setExecution(ExecutionEntity execution) {
executionId = execution.getId();
processInstanceId = execution.getProcessInstanceId();
......@@ -147,4 +152,10 @@ public abstract class JobEntity implements Serializable, Job, PersistentObject {
public void setJobHandlerConfiguration(String jobHandlerConfiguration) {
this.jobHandlerConfiguration = jobHandlerConfiguration;
}
public int getRevision() {
return revision;
}
public void setRevision(int revision) {
this.revision = revision;
}
}
......@@ -120,6 +120,10 @@ public class VariableInstanceEntity implements Serializable, PersistentObject {
return persistentState;
}
public int getRevisionNext() {
return revision+1;
}
// lazy initialized relations ///////////////////////////////////////////////
public void setProcessInstanceId(String processInstanceId) {
......
......@@ -93,6 +93,9 @@ public class ActivityContextBindings implements Bindings {
}
public Object remove(Object key) {
if (UNSTORED_KEYS.contains(key)) {
return null;
}
throw new UnsupportedOperationException();
}
......
......@@ -98,7 +98,7 @@ public class ProcessEngineTestCase extends PvmTestCase {
.getRuntimeService()
.createProcessInstanceQuery()
.processInstanceId(processInstanceId)
.singleResult();
.listPage();
if (processInstance!=null) {
throw new AssertionFailedError("expected finished process instance '"+processInstanceId+"' but it was still in the db");
......
......@@ -33,14 +33,14 @@
<!-- TABLE DATA -->
<!-- The property passing doesn't seem to work with parameterType='string', so we are forced to use a map here -->
<select id="selectTableCount" parameterType="map" resultType="long" >
<select id="selectTableCount" parameterType="org.activiti.engine.impl.TablePageQueryImpl" resultType="long" >
select count(*) from ${tableName}
</select>
<select id="selectTableData" parameterType="map" resultType="map">
<select id="selectTableData" parameterType="org.activiti.engine.impl.TablePageQueryImpl" resultType="map">
select * from ${tableName}
<if test="sortColumn != null">
order by ${sortColumn} ${sortOrder}
<if test="orderBy != null">
order by ${orderBy}
</if>
</select>
</mapper>
......@@ -100,6 +100,7 @@
<insert id="insertTimer" parameterType="org.activiti.engine.impl.persistence.runtime.TimerEntity">
insert into ACT_JOB (
ID_,
REV_,
TYPE_,
LOCK_OWNER_,
LOCK_EXP_TIME_,
......@@ -113,6 +114,7 @@
HANDLER_TYPE_,
HANDLER_CFG_ )
values (#{id, jdbcType=VARCHAR},
1,
'timer',
#{lockOwner, jdbcType=VARCHAR},
#{lockExpirationTime, jdbcType=TIMESTAMP},
......@@ -133,6 +135,7 @@
<update id="updateTimer" parameterType="org.activiti.engine.impl.persistence.runtime.TimerEntity">
update ACT_JOB
<set>
REV= #{revisionNext, jdbcType=INTEGER},
LOCK_EXP_TIME_ = #{lockExpirationTime, jdbcType=TIMESTAMP},
LOCK_OWNER_ = #{lockOwner, jdbcType=VARCHAR},
RETRIES_ = #{retries, jdbcType=INTEGER},
......@@ -140,6 +143,7 @@
DUEDATE_ = #{duedate, jdbcType=TIMESTAMP}
</set>
where ID_= #{id, jdbcType=VARCHAR}
and REV = #{revision, jdbcType=INTEGER}
</update>
<!-- TIMER SELECT -->
......@@ -169,6 +173,7 @@
<insert id="insertMessage" parameterType="org.activiti.engine.impl.persistence.runtime.MessageEntity">
insert into ACT_JOB (
ID_,
REV_,
TYPE_,
LOCK_OWNER_,
LOCK_EXP_TIME_,
......@@ -180,6 +185,7 @@
HANDLER_TYPE_,
HANDLER_CFG_)
values (#{id, jdbcType=VARCHAR},
1,
'message',
#{lockOwner, jdbcType=VARCHAR},
#{lockExpirationTime, jdbcType=TIMESTAMP},
......@@ -198,12 +204,14 @@
<update id="updateMessage" parameterType="org.activiti.engine.impl.persistence.runtime.MessageEntity">
update ACT_JOB
<set>
REV_ = #{revisionNext, jdbcType=INTEGER},
LOCK_EXP_TIME_ = #{lockExpirationTime, jdbcType=TIMESTAMP},
LOCK_OWNER_ = #{lockOwner, jdbcType=VARCHAR},
RETRIES_ = #{retries, jdbcType=INTEGER},
EXCEPTION_ = #{exception, jdbcType=VARCHAR}
</set>
where ID_= #{id, jdbcType=VARCHAR}
and REV = #{revision, jdbcType=INTEGER}
</update>
</mapper>
......@@ -27,7 +27,7 @@
<update id="updateVariableInstance" parameterType="org.activiti.engine.impl.persistence.runtime.VariableInstanceEntity">
update ACT_VARIABLE
set
REV_ = #{revisionNext, jdbcType=INTEGER}
REV_ = #{revisionNext, jdbcType=INTEGER},
BYTEARRAY_ID_ = #{byteArrayValueId, jdbcType=VARCHAR},
DOUBLE_ = #{doubleValue, jdbcType=DOUBLE},
LONG_ = #{longValue, jdbcType=BIGINT},
......@@ -96,7 +96,7 @@
<update id="updateByteArray" parameterType="org.activiti.engine.impl.persistence.runtime.ByteArrayEntity">
update ACT_BYTEARRAY
set
REV_ = #{revisionNext, jdbcType=INTEGER}
REV_ = #{revisionNext, jdbcType=INTEGER},
BYTES_ = #{bytes, jdbcType=BLOB}
where ID_ = #{id}
and REV_ = #{revision, jdbcType=INTEGER}
......
......@@ -37,17 +37,17 @@ public class CallActivityAdvancedTest extends ProcessEngineImplTestCase {
// one task in the subprocess should be active after starting the process instance
TaskQuery taskQuery = taskService.createTaskQuery();
Task taskBeforeSubProcess = taskQuery.singleResult();
Task taskBeforeSubProcess = taskQuery.listPage();
assertEquals("Task before subprocess", taskBeforeSubProcess.getName());
// Completing the task continues the process which leads to calling the subprocess
taskService.complete(taskBeforeSubProcess.getId());
Task taskInSubProcess = taskQuery.singleResult();
Task taskInSubProcess = taskQuery.listPage();
assertEquals("Task in subprocess", taskInSubProcess.getName());
// Completing the task in the subprocess, finishes the subprocess
taskService.complete(taskInSubProcess.getId());
Task taskAfterSubProcess = taskQuery.singleResult();
Task taskAfterSubProcess = taskQuery.listPage();
assertEquals("Task after subprocess", taskAfterSubProcess.getName());
// Completing this task end the process instance
......@@ -67,7 +67,7 @@ public class CallActivityAdvancedTest extends ProcessEngineImplTestCase {
// one task in the subprocess should be active after starting the process instance
TaskQuery taskQuery = taskService.createTaskQuery();
Task taskBeforeSubProcess = taskQuery.singleResult();
Task taskBeforeSubProcess = taskQuery.listPage();
assertEquals("Task in subprocess", taskBeforeSubProcess.getName());
// Completing this task ends the subprocess which leads to the end of the whole process instance
......@@ -113,14 +113,14 @@ public class CallActivityAdvancedTest extends ProcessEngineImplTestCase {
// After process start, the task in the subprocess should be active
runtimeService.startProcessInstanceByKey("timerOnCallActivity");
TaskQuery taskQuery = taskService.createTaskQuery();
Task taskInSubProcess = taskQuery.singleResult();
Task taskInSubProcess = taskQuery.listPage();
assertEquals("Task in subprocess", taskInSubProcess.getName());
// When the timer on the subprocess is fired, the complete subprocess is destroyed
ClockUtil.setCurrentTime(new Date(startTime.getTime() + (6 * 60 * 1000))); // + 6 minutes, timer fires on 5 minutes
waitForJobExecutorToProcessAllJobs(10000000, 1000000);
waitForJobExecutorToProcessAllJobs(10000, 100);
Task escalatedTask = taskQuery.singleResult();
Task escalatedTask = taskQuery.listPage();
assertEquals("Escalated Task", escalatedTask.getName());
// Completing the task ends the complete process
......
......@@ -93,7 +93,7 @@ public class EngineRebootProcessDefinitionCacheTest extends TestCase {
.getRuntimeService()
.createProcessInstanceQuery()
.processInstanceId(processInstanceId)
.singleResult();
.listPage();
assertNotNull(processInstance);
......@@ -111,7 +111,7 @@ public class EngineRebootProcessDefinitionCacheTest extends TestCase {
.getRuntimeService()
.createProcessInstanceQuery()
.processInstanceId(processInstanceId)
.singleResult();
.listPage();
assertNull(processInstance);
......
......@@ -23,7 +23,7 @@ import org.activiti.engine.test.ProcessEngineImplTestCase;
*/
public class CommandContextTest extends ProcessEngineImplTestCase {
public void testOne() {
public void testCommandContextGetCurrentAfterException() {
try {
processEngineConfiguration.getCommandExecutor().execute(new Command<Object>() {
public Object execute(CommandContext commandContext) {
......
......@@ -560,7 +560,9 @@ public class ExecutionImpl implements
parent.collectVariables(collectedVariables);
}
ensureVariablesInitialized();
collectedVariables.putAll(variables);
for (String variableName: variables.keySet()) {
collectedVariables.put(variableName, variables.get(variableName));
}
}
public void setVariables(Map<String, Object> variables) {
......
......@@ -41,10 +41,13 @@ public class TableDataGet extends ActivitiWebScript
{
String tableName = getMandatoryPathParameter(req, "tableName");
int size = getInt(req, "size", 10);
TablePageQuery query = getManagementService().createTablePageQuery()
.tableName(tableName)
.start(getInt(req, "start", 10))
.size(size);
int firstResult = getInt(req, "start", 10);
int maxResults = size;
TablePageQuery query = getManagementService()
.createTablePageQuery()
.tableName(tableName);
String sort = getString(req, "sort");
if (sort != null && !sort.trim().equals("")) {
String order = getString(req, "order", "asc");
......@@ -55,8 +58,9 @@ public class TableDataGet extends ActivitiWebScript
query.orderDesc(sort);
}
}
model.put("size", size);
model.put("tablePage", query.singleResult());
model.put("size", maxResults);
model.put("tablePage", query.listPage(firstResult, maxResults));
}
}
\ No newline at end of file
......@@ -55,7 +55,7 @@ public class TasksGet extends ActivitiWebScript
else {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Tasks must be filtered with 'assignee', 'candidate' or 'candidate-group'");
}
model.put("tasks", tq.paginatedList(start, size));
model.put("tasks", tq.listPage(start, size));
model.put("start", start);
model.put("total", tq.count());
model.put("size", size);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册