Search in sources :

Example 1 with ProcessDefinitionInfoEntityManager

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager in project Activiti by Activiti.

the class ProcessDefinitionInfoCache method get.

public ProcessDefinitionInfoCacheObject get(final String processDefinitionId) {
    ProcessDefinitionInfoCacheObject infoCacheObject = null;
    if (cache.containsKey(processDefinitionId)) {
        infoCacheObject = commandExecutor.execute(new Command<ProcessDefinitionInfoCacheObject>() {

            @Override
            public ProcessDefinitionInfoCacheObject execute(CommandContext commandContext) {
                ProcessDefinitionInfoEntityManager infoEntityManager = commandContext.getProcessDefinitionInfoEntityManager();
                ObjectMapper objectMapper = commandContext.getProcessEngineConfiguration().getObjectMapper();
                ProcessDefinitionInfoCacheObject cacheObject = cache.get(processDefinitionId);
                ProcessDefinitionInfoEntity infoEntity = infoEntityManager.findProcessDefinitionInfoByProcessDefinitionId(processDefinitionId);
                if (infoEntity != null && infoEntity.getRevision() != cacheObject.getRevision()) {
                    cacheObject.setRevision(infoEntity.getRevision());
                    if (infoEntity.getInfoJsonId() != null) {
                        byte[] infoBytes = infoEntityManager.findInfoJsonById(infoEntity.getInfoJsonId());
                        try {
                            ObjectNode infoNode = (ObjectNode) objectMapper.readTree(infoBytes);
                            cacheObject.setInfoNode(infoNode);
                        } catch (Exception e) {
                            throw new ActivitiException("Error reading json info node for process definition " + processDefinitionId, e);
                        }
                    }
                } else if (infoEntity == null) {
                    cacheObject.setRevision(0);
                    cacheObject.setInfoNode(objectMapper.createObjectNode());
                }
                return cacheObject;
            }
        });
    }
    return infoCacheObject;
}
Also used : ProcessDefinitionInfoEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager) ActivitiException(org.activiti.engine.ActivitiException) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.activiti.engine.impl.interceptor.Command) ProcessDefinitionInfoEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ActivitiException(org.activiti.engine.ActivitiException)

Example 2 with ProcessDefinitionInfoEntityManager

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager in project Activiti by Activiti.

the class CachingAndArtifactsManager method addDefinitionInfoToCache.

protected void addDefinitionInfoToCache(ProcessDefinitionEntity processDefinition, ProcessEngineConfigurationImpl processEngineConfiguration, CommandContext commandContext) {
    if (!processEngineConfiguration.isEnableProcessDefinitionInfoCache()) {
        return;
    }
    DeploymentManager deploymentManager = processEngineConfiguration.getDeploymentManager();
    ProcessDefinitionInfoEntityManager definitionInfoEntityManager = commandContext.getProcessDefinitionInfoEntityManager();
    ObjectMapper objectMapper = commandContext.getProcessEngineConfiguration().getObjectMapper();
    ProcessDefinitionInfoEntity definitionInfoEntity = definitionInfoEntityManager.findProcessDefinitionInfoByProcessDefinitionId(processDefinition.getId());
    ObjectNode infoNode = null;
    if (definitionInfoEntity != null && definitionInfoEntity.getInfoJsonId() != null) {
        byte[] infoBytes = definitionInfoEntityManager.findInfoJsonById(definitionInfoEntity.getInfoJsonId());
        if (infoBytes != null) {
            try {
                infoNode = (ObjectNode) objectMapper.readTree(infoBytes);
            } catch (Exception e) {
                throw new ActivitiException("Error deserializing json info for process definition " + processDefinition.getId());
            }
        }
    }
    ProcessDefinitionInfoCacheObject definitionCacheObject = new ProcessDefinitionInfoCacheObject();
    if (definitionInfoEntity == null) {
        definitionCacheObject.setRevision(0);
    } else {
        definitionCacheObject.setId(definitionInfoEntity.getId());
        definitionCacheObject.setRevision(definitionInfoEntity.getRevision());
    }
    if (infoNode == null) {
        infoNode = objectMapper.createObjectNode();
    }
    definitionCacheObject.setInfoNode(infoNode);
    deploymentManager.getProcessDefinitionInfoCache().add(processDefinition.getId(), definitionCacheObject);
}
Also used : ProcessDefinitionInfoEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager) ActivitiException(org.activiti.engine.ActivitiException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeploymentManager(org.activiti.engine.impl.persistence.deploy.DeploymentManager) ProcessDefinitionInfoEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinitionInfoCacheObject(org.activiti.engine.impl.persistence.deploy.ProcessDefinitionInfoCacheObject)

Example 3 with ProcessDefinitionInfoEntityManager

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager in project Activiti by Activiti.

the class BpmnDeployer method addDefinitionInfoToCache.

protected void addDefinitionInfoToCache(ProcessDefinitionEntity processDefinition, ProcessEngineConfigurationImpl processEngineConfiguration, CommandContext commandContext) {
    if (processEngineConfiguration.isEnableProcessDefinitionInfoCache() == false) {
        return;
    }
    DeploymentManager deploymentManager = processEngineConfiguration.getDeploymentManager();
    ProcessDefinitionInfoEntityManager definitionInfoEntityManager = commandContext.getProcessDefinitionInfoEntityManager();
    ObjectMapper objectMapper = commandContext.getProcessEngineConfiguration().getObjectMapper();
    ProcessDefinitionInfoEntity definitionInfoEntity = definitionInfoEntityManager.findProcessDefinitionInfoByProcessDefinitionId(processDefinition.getId());
    ObjectNode infoNode = null;
    if (definitionInfoEntity != null && definitionInfoEntity.getInfoJsonId() != null) {
        byte[] infoBytes = definitionInfoEntityManager.findInfoJsonById(definitionInfoEntity.getInfoJsonId());
        if (infoBytes != null) {
            try {
                infoNode = (ObjectNode) objectMapper.readTree(infoBytes);
            } catch (Exception e) {
                throw new ActivitiException("Error deserializing json info for process definition " + processDefinition.getId());
            }
        }
    }
    ProcessDefinitionInfoCacheObject definitionCacheObject = new ProcessDefinitionInfoCacheObject();
    if (definitionInfoEntity == null) {
        definitionCacheObject.setRevision(0);
    } else {
        definitionCacheObject.setId(definitionInfoEntity.getId());
        definitionCacheObject.setRevision(definitionInfoEntity.getRevision());
    }
    if (infoNode == null) {
        infoNode = objectMapper.createObjectNode();
    }
    definitionCacheObject.setInfoNode(infoNode);
    deploymentManager.getProcessDefinitionInfoCache().add(processDefinition.getId(), definitionCacheObject);
}
Also used : ProcessDefinitionInfoEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager) ActivitiException(org.activiti.engine.ActivitiException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeploymentManager(org.activiti.engine.impl.persistence.deploy.DeploymentManager) ProcessDefinitionInfoEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinitionInfoCacheObject(org.activiti.engine.impl.persistence.deploy.ProcessDefinitionInfoCacheObject)

Example 4 with ProcessDefinitionInfoEntityManager

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager in project Activiti by Activiti.

the class ProcessDefinitionInfoCache method retrieveProcessDefinitionInfoCacheObject.

protected ProcessDefinitionInfoCacheObject retrieveProcessDefinitionInfoCacheObject(String processDefinitionId, CommandContext commandContext) {
    ProcessDefinitionInfoEntityManager infoEntityManager = commandContext.getProcessDefinitionInfoEntityManager();
    ObjectMapper objectMapper = commandContext.getProcessEngineConfiguration().getObjectMapper();
    ProcessDefinitionInfoCacheObject cacheObject = null;
    if (cache.containsKey(processDefinitionId)) {
        cacheObject = cache.get(processDefinitionId);
    } else {
        cacheObject = new ProcessDefinitionInfoCacheObject();
        cacheObject.setRevision(0);
        cacheObject.setInfoNode(objectMapper.createObjectNode());
    }
    ProcessDefinitionInfoEntity infoEntity = infoEntityManager.findProcessDefinitionInfoByProcessDefinitionId(processDefinitionId);
    if (infoEntity != null && infoEntity.getRevision() != cacheObject.getRevision()) {
        cacheObject.setRevision(infoEntity.getRevision());
        if (infoEntity.getInfoJsonId() != null) {
            byte[] infoBytes = infoEntityManager.findInfoJsonById(infoEntity.getInfoJsonId());
            try {
                ObjectNode infoNode = (ObjectNode) objectMapper.readTree(infoBytes);
                cacheObject.setInfoNode(infoNode);
            } catch (Exception e) {
                throw new ActivitiException("Error reading json info node for process definition " + processDefinitionId, e);
            }
        }
    } else if (infoEntity == null) {
        cacheObject.setRevision(0);
        cacheObject.setInfoNode(objectMapper.createObjectNode());
    }
    return cacheObject;
}
Also used : ProcessDefinitionInfoEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager) ActivitiException(org.activiti.engine.ActivitiException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProcessDefinitionInfoEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ActivitiException(org.activiti.engine.ActivitiException)

Example 5 with ProcessDefinitionInfoEntityManager

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager in project Activiti by Activiti.

the class SaveProcessDefinitionInfoCmd method execute.

public Void execute(CommandContext commandContext) {
    if (processDefinitionId == null) {
        throw new ActivitiIllegalArgumentException("process definition id is null");
    }
    if (infoNode == null) {
        throw new ActivitiIllegalArgumentException("process definition info node is null");
    }
    ProcessDefinitionInfoEntityManager definitionInfoEntityManager = commandContext.getProcessDefinitionInfoEntityManager();
    ProcessDefinitionInfoEntity definitionInfoEntity = definitionInfoEntityManager.findProcessDefinitionInfoByProcessDefinitionId(processDefinitionId);
    if (definitionInfoEntity == null) {
        definitionInfoEntity = definitionInfoEntityManager.create();
        definitionInfoEntity.setProcessDefinitionId(processDefinitionId);
        commandContext.getProcessDefinitionInfoEntityManager().insertProcessDefinitionInfo(definitionInfoEntity);
    }
    if (infoNode != null) {
        try {
            ObjectWriter writer = commandContext.getProcessEngineConfiguration().getObjectMapper().writer();
            commandContext.getProcessDefinitionInfoEntityManager().updateInfoJson(definitionInfoEntity.getId(), writer.writeValueAsBytes(infoNode));
        } catch (Exception e) {
            throw new ActivitiException("Unable to serialize info node " + infoNode);
        }
    }
    return null;
}
Also used : ProcessDefinitionInfoEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ProcessDefinitionInfoEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntity) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Aggregations

ActivitiException (org.activiti.engine.ActivitiException)5 ProcessDefinitionInfoEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntity)5 ProcessDefinitionInfoEntityManager (org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 DeploymentManager (org.activiti.engine.impl.persistence.deploy.DeploymentManager)2 ProcessDefinitionInfoCacheObject (org.activiti.engine.impl.persistence.deploy.ProcessDefinitionInfoCacheObject)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 Command (org.activiti.engine.impl.interceptor.Command)1 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)1