提交 0bd4d10b 编写于 作者: T tombaeyens

ACT-741 refactoring persistence: refactoring RuuntimeSession into ExecutionManager and JobManager

上级 d83ef9d4
......@@ -116,7 +116,7 @@ public class ExecutionQueryImpl extends ExecutionVariableQueryImpl<ExecutionQuer
checkQueryOk();
ensureVariablesInitialized();
return commandContext
.getRuntimeSession()
.getExecutionManager()
.findExecutionCountByQueryCriteria(this);
}
......@@ -125,7 +125,7 @@ public class ExecutionQueryImpl extends ExecutionVariableQueryImpl<ExecutionQuer
checkQueryOk();
ensureVariablesInitialized();
return (List) commandContext
.getRuntimeSession()
.getExecutionManager()
.findExecutionsByQueryCriteria(this, page);
}
......
......@@ -162,14 +162,14 @@ public class JobQueryImpl extends AbstractQuery<JobQuery, Job> implements JobQue
public long executeCount(CommandContext commandContext) {
checkQueryOk();
return commandContext
.getRuntimeSession()
.getJobManager()
.findJobCountByQueryCriteria(this);
}
public List<Job> executeList(CommandContext commandContext, Page page) {
checkQueryOk();
return commandContext
.getRuntimeSession()
.getJobManager()
.findJobsByQueryCriteria(this, page);
}
......
......@@ -125,7 +125,7 @@ public class ProcessInstanceQueryImpl extends ExecutionVariableQueryImpl<Process
checkQueryOk();
ensureVariablesInitialized();
return commandContext
.getRuntimeSession()
.getExecutionManager()
.findProcessInstanceCountByQueryCriteria(this);
}
......@@ -133,7 +133,7 @@ public class ProcessInstanceQueryImpl extends ExecutionVariableQueryImpl<Process
checkQueryOk();
ensureVariablesInitialized();
return commandContext
.getRuntimeSession()
.getExecutionManager()
.findProcessInstanceByQueryCriteria(this, page);
}
......
......@@ -165,8 +165,11 @@ public class BpmnDeployer implements Deployer {
}
private void removeObsoleteTimers(ProcessDefinitionEntity processDefinition) {
List<Job> jobsToDelete = Context.getCommandContext().getRuntimeSession().
findJobsByConfiguration(TimerStartEventJobHandler.TYPE, processDefinition.getKey());
List<Job> jobsToDelete = Context
.getCommandContext()
.getJobManager()
.findJobsByConfiguration(TimerStartEventJobHandler.TYPE, processDefinition.getKey());
for (Job job :jobsToDelete) {
new DeleteJobsCmd(job.getId()).execute(Context.getCommandContext());
}
......
......@@ -64,7 +64,6 @@ import org.activiti.engine.impl.db.DbHistorySessionFactory;
import org.activiti.engine.impl.db.DbIdGenerator;
import org.activiti.engine.impl.db.DbIdentitySessionFactory;
import org.activiti.engine.impl.db.DbManagementSessionFactory;
import org.activiti.engine.impl.db.DbRuntimeSessionFactory;
import org.activiti.engine.impl.db.DbSqlSessionFactory;
import org.activiti.engine.impl.db.DbTaskSessionFactory;
import org.activiti.engine.impl.db.IbatisVariableTypeHandler;
......@@ -99,6 +98,7 @@ import org.activiti.engine.impl.persistence.mgr.HistoricDetailManager;
import org.activiti.engine.impl.persistence.mgr.HistoricProcessInstanceManager;
import org.activiti.engine.impl.persistence.mgr.HistoricTaskInstanceManager;
import org.activiti.engine.impl.persistence.mgr.IdentityLinkManager;
import org.activiti.engine.impl.persistence.mgr.JobManager;
import org.activiti.engine.impl.persistence.mgr.ProcessDefinitionManager;
import org.activiti.engine.impl.persistence.mgr.ResourceManager;
import org.activiti.engine.impl.persistence.mgr.TaskManager;
......@@ -512,7 +512,6 @@ public abstract class ProcessEngineConfigurationImpl extends ProcessEngineConfig
if (sessionFactories==null) {
sessionFactories = new HashMap<Class<?>, SessionFactory>();
addSessionFactory(new DbRuntimeSessionFactory());
addSessionFactory(new DbTaskSessionFactory());
addSessionFactory(new DbIdentitySessionFactory());
addSessionFactory(new DbManagementSessionFactory());
......@@ -542,6 +541,7 @@ public abstract class ProcessEngineConfigurationImpl extends ProcessEngineConfig
addSessionFactory(new GenericManagerFactory(HistoricActivityInstanceManager.class));
addSessionFactory(new GenericManagerFactory(HistoricTaskInstanceManager.class));
addSessionFactory(new GenericManagerFactory(HistoricDetailManager.class));
addSessionFactory(new GenericManagerFactory(JobManager.class));
}
if (customSessionFactories!=null) {
for (SessionFactory sessionFactory: customSessionFactories) {
......
......@@ -45,8 +45,9 @@ public class AcquireJobsCmd implements Command<AcquiredJobs> {
AcquiredJobs acquiredJobs = new AcquiredJobs();
List<JobEntity> jobs = commandContext
.getRuntimeSession()
.getJobManager()
.findNextJobsToExecute(new Page(0, maxJobsPerAcquisition));
for (JobEntity job: jobs) {
List<String> jobIds = new ArrayList<String>();
......
......@@ -16,7 +16,6 @@ package org.activiti.engine.impl.cmd;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.activiti.engine.impl.cfg.RuntimeSession;
import org.activiti.engine.impl.cfg.TransactionContext;
import org.activiti.engine.impl.cfg.TransactionState;
import org.activiti.engine.impl.context.Context;
......@@ -40,8 +39,10 @@ public class DecrementJobRetriesCmd implements Command<Object> {
}
public Object execute(CommandContext commandContext) {
RuntimeSession runtimeSession = commandContext.getRuntimeSession();
JobEntity job = runtimeSession.findJobById(jobId);
JobEntity job = Context
.getCommandContext()
.getJobManager()
.findJobById(jobId);
job.setRetries(job.getRetries() - 1);
job.setLockOwner(null);
job.setLockExpirationTime(null);
......
......@@ -13,7 +13,6 @@
package org.activiti.engine.impl.cmd;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
......
......@@ -16,6 +16,7 @@ package org.activiti.engine.impl.cmd;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.runtime.JobEntity;
......@@ -40,7 +41,11 @@ public class DeleteJobsCmd implements Command<Void> {
public Void execute(CommandContext commandContext) {
JobEntity jobToDelete = null;
for (String jobId: jobIds) {
jobToDelete = commandContext.getRuntimeSession().findJobById(jobId);
jobToDelete = Context
.getCommandContext()
.getJobManager()
.findJobById(jobId);
if(jobToDelete != null) {
// When given job doesn't exist, ignore
jobToDelete.delete();
......
......@@ -36,7 +36,7 @@ public class DeleteProcessInstanceCmd implements Command<Void> {
}
commandContext
.getRuntimeSession()
.getExecutionManager()
.deleteProcessInstance(processInstanceId, deleteReason);
return null;
}
......
......@@ -46,7 +46,9 @@ public class ExecuteJobsCmd implements Command<Object> {
if (log.isLoggable(Level.FINE)) {
log.fine("Executing job " + jobId);
}
JobEntity job = commandContext.getRuntimeSession().findJobById(jobId);
JobEntity job = commandContext
.getJobManager()
.findJobById(jobId);
if (job == null) {
throw new ActivitiException("No job found with id '" + jobId + "'");
......
......@@ -38,7 +38,7 @@ public class FindActiveActivityIdsCmd implements Command<List<String>> {
}
ExecutionEntity execution = commandContext
.getRuntimeSession()
.getExecutionManager()
.findExecutionById(executionId);
if (execution==null) {
......
......@@ -42,7 +42,7 @@ public class GetExecutionVariableCmd implements Command<Object> {
}
ExecutionEntity execution = commandContext
.getRuntimeSession()
.getExecutionManager()
.findExecutionById(executionId);
if (execution==null) {
......
......@@ -43,7 +43,7 @@ public class GetExecutionVariablesCmd implements Command<Map<String, Object>> {
}
ExecutionEntity execution = commandContext
.getRuntimeSession()
.getExecutionManager()
.findExecutionById(executionId);
if (execution==null) {
......
......@@ -36,7 +36,10 @@ public class GetJobExceptionStacktraceCmd implements Command<String>{
throw new ActivitiException("jobId is null");
}
JobEntity job = commandContext.getRuntimeSession().findJobById(jobId);
JobEntity job = commandContext
.getJobManager()
.findJobById(jobId);
if(job == null) {
throw new ActivitiException("No job found with id " + jobId);
}
......
......@@ -41,7 +41,7 @@ public class SetExecutionVariablesCmd implements Command<Object> {
}
ExecutionEntity execution = commandContext
.getRuntimeSession()
.getExecutionManager()
.findExecutionById(executionId);
if (execution==null) {
......
......@@ -40,7 +40,7 @@ public class SignalCmd implements Command<Object> {
}
ExecutionEntity execution = commandContext
.getRuntimeSession()
.getExecutionManager()
.findExecutionById(executionId);
if (execution==null) {
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.db;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.JobQueryImpl;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.TaskQueryImpl;
import org.activiti.engine.impl.cfg.RuntimeSession;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.interceptor.Session;
import org.activiti.engine.impl.runtime.ByteArrayEntity;
import org.activiti.engine.impl.runtime.ExecutionEntity;
import org.activiti.engine.impl.runtime.JobEntity;
import org.activiti.engine.impl.runtime.TimerEntity;
import org.activiti.engine.impl.runtime.VariableInstanceEntity;
import org.activiti.engine.impl.task.TaskEntity;
import org.activiti.engine.impl.util.ClockUtil;
import org.activiti.engine.runtime.Job;
import org.activiti.engine.runtime.ProcessInstance;
/**
* @author Joram Barrez
* @author Tom Baeyens
*/
public class DbRuntimeSession implements Session, RuntimeSession {
protected DbSqlSession dbSqlSession;
public DbRuntimeSession() {
this.dbSqlSession = Context.getCommandContext().getDbSqlSession();
}
@SuppressWarnings("unchecked")
public void deleteProcessInstance(String processInstanceId, String deleteReason) {
ExecutionEntity execution = findExecutionById(processInstanceId);
if(execution == null) {
throw new ActivitiException("No process instance found for id '" + processInstanceId + "'");
}
List<TaskEntity> tasks = (List) new TaskQueryImpl(Context.getCommandContext())
.processInstanceId(processInstanceId)
.list();
for (TaskEntity task: tasks) {
task.delete(TaskEntity.DELETE_REASON_DELETED);
}
execution.deleteCascade(deleteReason);
}
public ExecutionEntity findSubProcessInstanceBySuperExecutionId(String superExecutionId) {
return (ExecutionEntity) dbSqlSession.selectOne("selectSubProcessInstanceBySuperExecutionId", superExecutionId);
}
public long findExecutionCountByQueryCriteria(Object executionQuery) {
return (Long) dbSqlSession.selectOne("selectExecutionCountByQueryCriteria", executionQuery);
}
@SuppressWarnings("unchecked")
public List<ExecutionEntity> findExecutionsByQueryCriteria(Object executionQuery, Page page) {
return dbSqlSession.selectList("selectExecutionsByQueryCriteria", executionQuery, page);
}
public long findProcessInstanceCountByQueryCriteria(Object executionQuery) {
return (Long) dbSqlSession.selectOne("selectProcessInstanceCountByQueryCriteria", executionQuery);
}
@SuppressWarnings("unchecked")
public List<ProcessInstance> findProcessInstanceByQueryCriteria(Object executionQuery, Page page) {
return dbSqlSession.selectList("selectProcessInstanceByQueryCriteria", executionQuery, page);
}
public ExecutionEntity findExecutionById(String executionId) {
return (ExecutionEntity) dbSqlSession.selectOne("selectExecutionById", executionId);
}
@SuppressWarnings("unchecked")
public List<ExecutionEntity> findChildExecutionsByParentExecutionId(String parentExecutionId) {
return dbSqlSession.selectList("selectExecutionsByParentExecutionId", parentExecutionId);
}
@SuppressWarnings("unchecked")
public List<VariableInstanceEntity> findVariableInstancesByExecutionId(String executionId) {
return dbSqlSession.selectList("selectVariablesByExecutionId", executionId);
}
@SuppressWarnings("unchecked")
public List<VariableInstanceEntity> findVariablesByTaskId(String taskId) {
return dbSqlSession.selectList("selectVariablesByTaskId", taskId);
}
public void insertByteArray(ByteArrayEntity byteArrayEntity) {
dbSqlSession.insert(byteArrayEntity);
}
public void deleteByteArray(String byteArrayId) {
dbSqlSession.delete(ByteArrayEntity.class, byteArrayId);
}
@SuppressWarnings("unchecked")
public byte[] getByteArrayBytes(String byteArrayId) {
Map<String, Object> temp = (Map) dbSqlSession.selectOne("selectBytesOfByteArray", byteArrayId);
return (byte[]) temp.get("BYTES_");
}
public JobEntity findJobById(String jobId) {
return (JobEntity) dbSqlSession.selectOne("selectJob", jobId);
}
@SuppressWarnings("unchecked")
public List<JobEntity> findNextJobsToExecute(Page page) {
Date now = ClockUtil.getCurrentTime();
return dbSqlSession.selectList("selectNextJobsToExecute", now, page);
}
@SuppressWarnings("unchecked")
public List<TimerEntity> findUnlockedTimersByDuedate(Date duedate, Page page) {
final String query = "selectUnlockedTimersByDuedate";
return dbSqlSession.selectList(query, duedate, page);
}
@SuppressWarnings("unchecked")
public List<TimerEntity> findTimersByExecutionId(String executionId) {
return dbSqlSession.selectList("selectTimersByExecutionId", executionId);
}
@SuppressWarnings("unchecked")
public List<Job> findJobsByQueryCriteria(JobQueryImpl jobQuery, Page page) {
final String query = "org.activiti.persistence.selectJobByQueryCriteria";
return dbSqlSession.selectList(query, jobQuery, page);
}
@SuppressWarnings("unchecked")
public List<Job> findJobsByConfiguration(String jobHandlerType, String jobHandlerConfiguration) {
Map<String, String> params = new HashMap<String, String>();
params.put("handlerType", jobHandlerType);
params.put("handlerConfiguration", jobHandlerConfiguration);
return dbSqlSession.selectList("org.activiti.persistence.selectJobsByConfiguration", params);
}
public long findJobCountByQueryCriteria(JobQueryImpl jobQuery) {
return (Long) dbSqlSession.selectOne("org.activiti.persistence.selectJobCountByQueryCriteria", jobQuery);
}
public void close() {
}
public void flush() {
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.db;
import org.activiti.engine.impl.cfg.RuntimeSession;
import org.activiti.engine.impl.interceptor.Session;
import org.activiti.engine.impl.interceptor.SessionFactory;
/**
* @author Tom Baeyens
*/
public class DbRuntimeSessionFactory implements SessionFactory {
public Class< ? > getSessionType() {
return RuntimeSession.class;
}
public Session openSession() {
return new DbRuntimeSession();
}
}
......@@ -24,7 +24,6 @@ import org.activiti.engine.impl.cfg.IdentitySession;
import org.activiti.engine.impl.cfg.ManagementSession;
import org.activiti.engine.impl.cfg.MessageSession;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.cfg.RuntimeSession;
import org.activiti.engine.impl.cfg.TaskSession;
import org.activiti.engine.impl.cfg.TimerSession;
import org.activiti.engine.impl.cfg.TransactionContext;
......@@ -37,6 +36,7 @@ import org.activiti.engine.impl.persistence.mgr.HistoricDetailManager;
import org.activiti.engine.impl.persistence.mgr.HistoricProcessInstanceManager;
import org.activiti.engine.impl.persistence.mgr.HistoricTaskInstanceManager;
import org.activiti.engine.impl.persistence.mgr.IdentityLinkManager;
import org.activiti.engine.impl.persistence.mgr.JobManager;
import org.activiti.engine.impl.persistence.mgr.ProcessDefinitionManager;
import org.activiti.engine.impl.persistence.mgr.ResourceManager;
import org.activiti.engine.impl.persistence.mgr.TaskManager;
......@@ -194,7 +194,7 @@ public class CommandContext {
return getSession(ProcessDefinitionManager.class);
}
public ExecutionManager getProcessInstanceManager() {
public ExecutionManager getExecutionManager() {
return getSession(ExecutionManager.class);
}
......@@ -225,12 +225,15 @@ public class CommandContext {
public HistoricTaskInstanceManager getHistoricTaskInstanceManager() {
return getSession(HistoricTaskInstanceManager.class);
}
public JobManager getJobManager() {
return getSession(JobManager.class);
}
public RuntimeSession getRuntimeSession() {
return getSession(RuntimeSession.class);
}
public IdentitySession getIdentitySession() {
return getSession(IdentitySession.class);
}
......
......@@ -16,6 +16,7 @@ import java.util.Date;
import java.util.List;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.runtime.TimerEntity;
......@@ -36,6 +37,9 @@ public class GetUnlockedTimersByDuedateCmd implements Command<List<TimerEntity>>
}
public List<TimerEntity> execute(CommandContext commandContext) {
return commandContext.getRuntimeSession().findUnlockedTimersByDuedate(duedate, page);
return Context
.getCommandContext()
.getJobManager()
.findUnlockedTimersByDuedate(duedate, page);
}
}
......@@ -63,7 +63,7 @@ public class JobExecutorTimerSession implements TimerSession, Session {
public void cancelTimers(ExecutionEntity execution) {
List<TimerEntity> timers = Context
.getCommandContext()
.getRuntimeSession()
.getJobManager()
.findTimersByExecutionId(execution.getId());
for (TimerEntity timer: timers) {
......
......@@ -16,6 +16,7 @@ package org.activiti.engine.impl.persistence.mgr;
import java.util.List;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.runtime.ExecutionEntity;
import org.activiti.engine.impl.task.TaskEntity;
......@@ -27,7 +28,7 @@ import org.activiti.engine.runtime.ProcessInstance;
* @author Tom Baeyens
*/
public class ExecutionManager extends AbstractManager {
public void deleteProcessInstancesByProcessDefinition(ProcessDefinition processDefinition, String deleteReason) {
List<ProcessInstance> processInstances = getPersistenceSession()
.createProcessInstanceQuery()
......@@ -63,7 +64,35 @@ public class ExecutionManager extends AbstractManager {
execution.deleteCascade(deleteReason);
}
public ExecutionEntity findSubProcessInstanceBySuperExecutionId(String superExecutionId) {
return (ExecutionEntity) getPersistenceSession().selectOne("selectSubProcessInstanceBySuperExecutionId", superExecutionId);
}
@SuppressWarnings("unchecked")
public List<ExecutionEntity> findChildExecutionsByParentExecutionId(String parentExecutionId) {
return getPersistenceSession().selectList("selectExecutionsByParentExecutionId", parentExecutionId);
}
public ExecutionEntity findExecutionById(String executionId) {
return (ExecutionEntity) getPersistenceSession().selectOne("selectExecutionById", executionId);
return (ExecutionEntity) getPersistenceSession().selectById(ExecutionEntity.class, executionId);
}
public long findExecutionCountByQueryCriteria(Object executionQuery) {
return (Long) getPersistenceSession().selectOne("selectExecutionCountByQueryCriteria", executionQuery);
}
@SuppressWarnings("unchecked")
public List<ExecutionEntity> findExecutionsByQueryCriteria(Object executionQuery, Page page) {
return getPersistenceSession().selectList("selectExecutionsByQueryCriteria", executionQuery, page);
}
public long findProcessInstanceCountByQueryCriteria(Object executionQuery) {
return (Long) getPersistenceSession().selectOne("selectProcessInstanceCountByQueryCriteria", executionQuery);
}
@SuppressWarnings("unchecked")
public List<ProcessInstance> findProcessInstanceByQueryCriteria(Object executionQuery, Page page) {
return getPersistenceSession().selectList("selectProcessInstanceByQueryCriteria", executionQuery, page);
}
}
......@@ -15,7 +15,6 @@ package org.activiti.engine.impl.persistence.mgr;
import java.util.List;
import org.activiti.engine.history.HistoricVariableUpdate;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.db.DbSqlSession;
......
......@@ -11,45 +11,63 @@
* limitations under the License.
*/
package org.activiti.engine.impl.cfg;
package org.activiti.engine.impl.persistence.mgr;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.activiti.engine.impl.JobQueryImpl;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.runtime.ExecutionEntity;
import org.activiti.engine.impl.runtime.JobEntity;
import org.activiti.engine.impl.runtime.TimerEntity;
import org.activiti.engine.impl.runtime.VariableInstanceEntity;
import org.activiti.engine.impl.util.ClockUtil;
import org.activiti.engine.runtime.Job;
import org.activiti.engine.runtime.ProcessInstance;
/**
* @author Tom Baeyens
*/
public interface RuntimeSession {
void deleteProcessInstance(String processInstanceId, String deleteReason);
ExecutionEntity findSubProcessInstanceBySuperExecutionId(String superExecutionId);
long findExecutionCountByQueryCriteria(Object executionQuery);
List<ExecutionEntity> findExecutionsByQueryCriteria(Object executionQuery, Page page);
long findProcessInstanceCountByQueryCriteria(Object executionQuery);
List<ProcessInstance> findProcessInstanceByQueryCriteria(Object executionQuery, Page page);
List<ExecutionEntity> findChildExecutionsByParentExecutionId(String executionId);
ExecutionEntity findExecutionById(String executionId);
public class JobManager extends AbstractManager {
public JobEntity findJobById(String jobId) {
return (JobEntity) getPersistenceSession().selectOne("selectJob", jobId);
}
List<VariableInstanceEntity> findVariableInstancesByExecutionId(String executionId);
List<VariableInstanceEntity> findVariablesByTaskId(String taskId);
byte[] getByteArrayBytes(String byteArrayId);
JobEntity findJobById(String jobId);
List<JobEntity> findNextJobsToExecute(Page page);
List<TimerEntity> findUnlockedTimersByDuedate(Date duedate, Page page);
List<TimerEntity> findTimersByExecutionId(String executionId);
List<Job> findJobsByQueryCriteria(JobQueryImpl jobQuery, Page page);
List<Job> findJobsByConfiguration(String jobHandlerType, String jobHandlerConfiguration);
long findJobCountByQueryCriteria(JobQueryImpl jobQuery);
@SuppressWarnings("unchecked")
public List<JobEntity> findNextJobsToExecute(Page page) {
Date now = ClockUtil.getCurrentTime();
return getPersistenceSession().selectList("selectNextJobsToExecute", now, page);
}
@SuppressWarnings("unchecked")
public List<TimerEntity> findUnlockedTimersByDuedate(Date duedate, Page page) {
final String query = "selectUnlockedTimersByDuedate";
return getPersistenceSession().selectList(query, duedate, page);
}
@SuppressWarnings("unchecked")
public List<TimerEntity> findTimersByExecutionId(String executionId) {
return getPersistenceSession().selectList("selectTimersByExecutionId", executionId);
}
@SuppressWarnings("unchecked")
public List<Job> findJobsByQueryCriteria(JobQueryImpl jobQuery, Page page) {
final String query = "org.activiti.persistence.selectJobByQueryCriteria";
return getPersistenceSession().selectList(query, jobQuery, page);
}
@SuppressWarnings("unchecked")
public List<Job> findJobsByConfiguration(String jobHandlerType, String jobHandlerConfiguration) {
Map<String, String> params = new HashMap<String, String>();
params.put("handlerType", jobHandlerType);
params.put("handlerConfiguration", jobHandlerConfiguration);
return getPersistenceSession().selectList("org.activiti.persistence.selectJobsByConfiguration", params);
}
public long findJobCountByQueryCriteria(JobQueryImpl jobQuery) {
return (Long) getPersistenceSession().selectOne("org.activiti.persistence.selectJobCountByQueryCriteria", jobQuery);
}
}
......@@ -24,11 +24,6 @@ import org.activiti.engine.impl.runtime.VariableInstanceEntity;
*/
public class VariableInstanceManager extends AbstractManager {
@SuppressWarnings("unchecked")
public List<VariableInstanceEntity> findVariableInstancesByTaskId(String taskId) {
return getPersistenceSession().selectList("selectVariablesByTaskId", taskId);
}
public void deleteVariableInstance(VariableInstanceEntity variableInstance) {
getPersistenceSession().delete(VariableInstanceEntity.class, variableInstance.getId());
......@@ -42,4 +37,13 @@ public class VariableInstanceManager extends AbstractManager {
}
}
@SuppressWarnings("unchecked")
public List<VariableInstanceEntity> findVariableInstancesByTaskId(String taskId) {
return getPersistenceSession().selectList("selectVariablesByTaskId", taskId);
}
@SuppressWarnings("unchecked")
public List<VariableInstanceEntity> findVariableInstancesByExecutionId(String executionId) {
return getPersistenceSession().selectList("selectVariablesByExecutionId", executionId);
}
}
......@@ -25,7 +25,6 @@ import org.activiti.engine.impl.JobQueryImpl;
import org.activiti.engine.impl.TaskQueryImpl;
import org.activiti.engine.impl.bpmn.parser.BpmnParse;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.cfg.RuntimeSession;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.db.DbSqlSession;
import org.activiti.engine.impl.db.PersistentObject;
......@@ -510,7 +509,7 @@ public class ExecutionEntity extends VariableScopeImpl implements ActivityExecut
if (executions==null) {
this.executions = (List) Context
.getCommandContext()
.getRuntimeSession()
.getExecutionManager()
.findChildExecutionsByParentExecutionId(id);
}
}
......@@ -607,7 +606,7 @@ public class ExecutionEntity extends VariableScopeImpl implements ActivityExecut
if ((processInstance == null) && (processInstanceId != null)) {
processInstance = Context
.getCommandContext()
.getRuntimeSession()
.getExecutionManager()
.findExecutionById(processInstanceId);
}
}
......@@ -659,7 +658,7 @@ public class ExecutionEntity extends VariableScopeImpl implements ActivityExecut
if (parent == null && parentId != null) {
parent = Context
.getCommandContext()
.getRuntimeSession()
.getExecutionManager()
.findExecutionById(parentId);
}
}
......@@ -702,7 +701,7 @@ public class ExecutionEntity extends VariableScopeImpl implements ActivityExecut
if (superExecution == null && superExecutionId != null) {
superExecution = Context
.getCommandContext()
.getRuntimeSession()
.getExecutionManager()
.findExecutionById(superExecutionId);
}
}
......@@ -720,7 +719,7 @@ public class ExecutionEntity extends VariableScopeImpl implements ActivityExecut
if (subProcessInstance == null) {
subProcessInstance = Context
.getCommandContext()
.getRuntimeSession()
.getExecutionManager()
.findSubProcessInstanceBySuperExecutionId(id);
}
}
......@@ -831,7 +830,10 @@ public class ExecutionEntity extends VariableScopeImpl implements ActivityExecut
}
// update the related jobs
List<VariableInstanceEntity> variables = (List) commandContext.getRuntimeSession().findVariableInstancesByExecutionId(id);
List<VariableInstanceEntity> variables = (List) commandContext
.getVariableInstanceManager()
.findVariableInstancesByExecutionId(id);
for (VariableInstanceEntity variable: variables) {
variable.setExecutionId(replacedBy.getId());
}
......@@ -874,7 +876,9 @@ public class ExecutionEntity extends VariableScopeImpl implements ActivityExecut
@Override
protected List<VariableInstanceEntity> loadVariableInstances() {
return Context.getCommandContext().getSession(RuntimeSession.class)
return Context
.getCommandContext()
.getVariableInstanceManager()
.findVariableInstancesByExecutionId(id);
}
......
......@@ -19,7 +19,6 @@ import java.util.HashMap;
import java.util.Map;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.cfg.RuntimeSession;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.db.DbSqlSession;
import org.activiti.engine.impl.db.PersistentObject;
......@@ -68,10 +67,9 @@ public abstract class JobEntity implements Serializable, Job, PersistentObject {
protected String exceptionMessage;
public void execute(CommandContext commandContext) {
RuntimeSession runtimeSession = commandContext.getRuntimeSession();
ExecutionEntity execution = null;
if (executionId != null) {
execution = runtimeSession.findExecutionById(executionId);
execution = commandContext.getExecutionManager().findExecutionById(executionId);
}
Map<String, JobHandler> jobHandlers = Context.getProcessEngineConfiguration().getJobHandlers();
......
......@@ -28,7 +28,6 @@ import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.cfg.RuntimeSession;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.db.DbSqlSession;
import org.activiti.engine.impl.db.PersistentObject;
......@@ -231,8 +230,8 @@ public class TaskEntity extends VariableScopeImpl implements Task, DelegateTask,
protected List<VariableInstanceEntity> loadVariableInstances() {
return Context
.getCommandContext()
.getSession(RuntimeSession.class)
.findVariablesByTaskId(id);
.getVariableInstanceManager()
.findVariableInstancesByTaskId(id);
}
// execution ////////////////////////////////////////////////////////////////
......@@ -241,7 +240,7 @@ public class TaskEntity extends VariableScopeImpl implements Task, DelegateTask,
if ( (execution==null) && (executionId!=null) ) {
this.execution = Context
.getCommandContext()
.getRuntimeSession()
.getExecutionManager()
.findExecutionById(executionId);
}
return execution;
......
......@@ -63,7 +63,7 @@
<!-- EXECUTION SELECT -->
<select id="selectExecutionById" parameterType="string" resultMap="executionResultMap">
<select id="selectExecution" parameterType="string" resultMap="executionResultMap">
select * from ACT_RU_EXECUTION where ID_ = #{id}
</select>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册