我有以下功能,并在第二行收到错误Unspecified value parameters :: type[T], Type mismatch, expected: Command[NotInferedT], actual: DeletePrivilegeMappingCmd
。
execute()
接受Command[T]
参数,DeletePrivilegeMappingCmd
扩展Command[T]
要求。
我根据错误想出我需要在签名中添加[Object]
,但我不确定我必须在[]
中包含哪种类型。添加任何Object
可以消除错误,但我假设如果没有使用正确的类型,将会出现运行时错误。
我应该添加什么类型?
错误讯息签名
def deleteGroupPrivilegeMapping(privilegeId: String, groupId: String) {
commandExecutor.execute(new DeletePrivilegeMappingCmd(privilegeId, null, groupId))
}
更新了邮件签名
def deleteGroupPrivilegeMapping(privilegeId: String, groupId: String) {
commandExecutor.execute(new DeletePrivilegeMappingCmd(privilegeId, null, groupId)[String][String])
}
编辑:
Command
和execute
public interface Command<T> extends BaseCommand<T, CommandContext> {
T execute(CommandContext commandContext);
}
DeletePrivilegeMappingCmd的实现
public class DeletePrivilegeCmd implements Command<Void>, Serializable {
private static final long serialVersionUID = 1L;
protected String id;
public DeletePrivilegeCmd(String id) {
if (id == null) {
throw new FlowableIllegalArgumentException("id is null");
}
this.id = id;
}
public Void execute(CommandContext commandContext) {
commandContext.gePrivilegeMappingEntityManager().deleteByPrivilegeId(id);
commandContext.getPrivilegeEntityManager().delete(id);
return null;
}
}
命令上下文定义
public class CommandContext extends AbstractCommandContext {
private static Logger log = LoggerFactory.getLogger(CommandContext.class);
protected ProcessEngineConfigurationImpl processEngineConfiguration;
protected FailedJobCommandFactory failedJobCommandFactory;
protected FlowableEngineAgenda agenda;
protected Map<String, ExecutionEntity> involvedExecutions = new HashMap(1);
protected LinkedList<Object> resultStack = new LinkedList();
public CommandContext(Command<?> command, ProcessEngineConfigurationImpl processEngineConfiguration) {
super(command);
this.processEngineConfiguration = processEngineConfiguration;
this.failedJobCommandFactory = processEngineConfiguration.getFailedJobCommandFactory();
this.sessionFactories = processEngineConfiguration.getSessionFactories();
this.agenda = processEngineConfiguration.getAgendaFactory().createAgenda(this);
}
protected void logException() {
if(!(this.exception instanceof JobNotFoundException) && !(this.exception instanceof FlowableTaskAlreadyClaimedException)) {
super.logException();
} else {
log.info("Error while closing command context", this.exception);
}
}
public void addCloseListener(CommandContextCloseListener commandContextCloseListener) {
if(this.closeListeners == null) {
this.closeListeners = new ArrayList(1);
}
this.closeListeners.add(commandContextCloseListener);
}
public DbSqlSession getDbSqlSession() {
return (DbSqlSession)this.getSession(DbSqlSession.class);
}
public EntityCache getEntityCache() {
return (EntityCache)this.getSession(EntityCache.class);
}
public DeploymentEntityManager getDeploymentEntityManager() {
return this.processEngineConfiguration.getDeploymentEntityManager();
}
public ResourceEntityManager getResourceEntityManager() {
return this.processEngineConfiguration.getResourceEntityManager();
}
public ByteArrayEntityManager getByteArrayEntityManager() {
return this.processEngineConfiguration.getByteArrayEntityManager();
}
public ProcessDefinitionEntityManager getProcessDefinitionEntityManager() {
return this.processEngineConfiguration.getProcessDefinitionEntityManager();
}
public ModelEntityManager getModelEntityManager() {
return this.processEngineConfiguration.getModelEntityManager();
}
public ProcessDefinitionInfoEntityManager getProcessDefinitionInfoEntityManager() {
return this.processEngineConfiguration.getProcessDefinitionInfoEntityManager();
}
public ExecutionEntityManager getExecutionEntityManager() {
return this.processEngineConfiguration.getExecutionEntityManager();
}
public TaskEntityManager getTaskEntityManager() {
return this.processEngineConfiguration.getTaskEntityManager();
}
public IdentityLinkEntityManager getIdentityLinkEntityManager() {
return this.processEngineConfiguration.getIdentityLinkEntityManager();
}
public VariableInstanceEntityManager getVariableInstanceEntityManager() {
return this.processEngineConfiguration.getVariableInstanceEntityManager();
}
public HistoricProcessInstanceEntityManager getHistoricProcessInstanceEntityManager() {
return this.processEngineConfiguration.getHistoricProcessInstanceEntityManager();
}
public HistoricDetailEntityManager getHistoricDetailEntityManager() {
return this.processEngineConfiguration.getHistoricDetailEntityManager();
}
public HistoricVariableInstanceEntityManager getHistoricVariableInstanceEntityManager() {
return this.processEngineConfiguration.getHistoricVariableInstanceEntityManager();
}
public HistoricActivityInstanceEntityManager getHistoricActivityInstanceEntityManager() {
return this.processEngineConfiguration.getHistoricActivityInstanceEntityManager();
}
public HistoricTaskInstanceEntityManager getHistoricTaskInstanceEntityManager() {
return this.processEngineConfiguration.getHistoricTaskInstanceEntityManager();
}
public HistoricIdentityLinkEntityManager getHistoricIdentityLinkEntityManager() {
return this.processEngineConfiguration.getHistoricIdentityLinkEntityManager();
}
public EventLogEntryEntityManager getEventLogEntryEntityManager() {
return this.processEngineConfiguration.getEventLogEntryEntityManager();
}
public JobEntityManager getJobEntityManager() {
return this.processEngineConfiguration.getJobEntityManager();
}
public TimerJobEntityManager getTimerJobEntityManager() {
return this.processEngineConfiguration.getTimerJobEntityManager();
}
public SuspendedJobEntityManager getSuspendedJobEntityManager() {
return this.processEngineConfiguration.getSuspendedJobEntityManager();
}
public DeadLetterJobEntityManager getDeadLetterJobEntityManager() {
return this.processEngineConfiguration.getDeadLetterJobEntityManager();
}
public AttachmentEntityManager getAttachmentEntityManager() {
return this.processEngineConfiguration.getAttachmentEntityManager();
}
public TableDataManager getTableDataManager() {
return this.processEngineConfiguration.getTableDataManager();
}
public CommentEntityManager getCommentEntityManager() {
return this.processEngineConfiguration.getCommentEntityManager();
}
public PropertyEntityManager getPropertyEntityManager() {
return this.processEngineConfiguration.getPropertyEntityManager();
}
public EventSubscriptionEntityManager getEventSubscriptionEntityManager() {
return this.processEngineConfiguration.getEventSubscriptionEntityManager();
}
public HistoryManager getHistoryManager() {
return this.processEngineConfiguration.getHistoryManager();
}
public JobManager getJobManager() {
return this.processEngineConfiguration.getJobManager();
}
public void addInvolvedExecution(ExecutionEntity executionEntity) {
if(executionEntity.getId() != null) {
this.involvedExecutions.put(executionEntity.getId(), executionEntity);
}
}
public boolean hasInvolvedExecutions() {
return this.involvedExecutions.size() > 0;
}
public Collection<ExecutionEntity> getInvolvedExecutions() {
return this.involvedExecutions.values();
}
public FailedJobCommandFactory getFailedJobCommandFactory() {
return this.failedJobCommandFactory;
}
public ProcessEngineConfigurationImpl getProcessEngineConfiguration() {
return this.processEngineConfiguration;
}
public FlowableEventDispatcher getEventDispatcher() {
return this.processEngineConfiguration.getEventDispatcher();
}
public FlowableEngineAgenda getAgenda() {
return this.agenda;
}
public Object getResult() {
return this.resultStack.pollLast();
}
public void setResult(Object result) {
this.resultStack.add(result);
}
}