Search in sources :

Example 1 with ProcessDefinition

use of org.apache.camel.bam.model.ProcessDefinition in project camel by apache.

the class ProcessBuilder method findOrCreateActivityDefinition.

// Implementation methods
// -------------------------------------------------------------------------
public ActivityDefinition findOrCreateActivityDefinition(String activityName) {
    ProcessDefinition definition = getProcessDefinition();
    Map<String, Object> params = new HashMap<String, Object>(2);
    params.put("definition", definition);
    params.put("name", activityName);
    List<ActivityDefinition> list = entityManagerTemplate.find(ActivityDefinition.class, "select x from " + QueryUtils.getTypeName(ActivityDefinition.class) + " x where x.processDefinition = :definition and x.name = :name", params);
    if (!list.isEmpty()) {
        return list.get(0);
    } else {
        ActivityDefinition answer = new ActivityDefinition();
        answer.setName(activityName);
        answer.setProcessDefinition(ProcessDefinition.getRefreshedProcessDefinition(entityManagerTemplate, definition));
        entityManagerTemplate.persist(answer);
        return answer;
    }
}
Also used : HashMap(java.util.HashMap) ProcessDefinition(org.apache.camel.bam.model.ProcessDefinition) ActivityDefinition(org.apache.camel.bam.model.ActivityDefinition)

Example 2 with ProcessDefinition

use of org.apache.camel.bam.model.ProcessDefinition in project camel by apache.

the class ProcessBuilder method findOrCreateProcessDefinition.

protected ProcessDefinition findOrCreateProcessDefinition() {
    Map<String, Object> params = new HashMap<String, Object>(1);
    params.put("name", processName);
    List<ProcessDefinition> list = entityManagerTemplate.find(ProcessDefinition.class, "select x from " + QueryUtils.getTypeName(ProcessDefinition.class) + " x where x.name = :name", params);
    if (!list.isEmpty()) {
        return list.get(0);
    } else {
        ProcessDefinition answer = new ProcessDefinition();
        answer.setName(processName);
        entityManagerTemplate.persist(answer);
        return answer;
    }
}
Also used : HashMap(java.util.HashMap) ProcessDefinition(org.apache.camel.bam.model.ProcessDefinition)

Example 3 with ProcessDefinition

use of org.apache.camel.bam.model.ProcessDefinition in project camel by apache.

the class JpaBamProcessorSupport method loadEntity.

// Implementatiom methods
// -----------------------------------------------------------------------
protected T loadEntity(Exchange exchange, Object key) throws Exception {
    LOCK.lock();
    try {
        LOG.trace("LoadEntity call");
        T entity = findEntityByCorrelationKey(key);
        if (entity == null) {
            entity = createEntity(exchange, key);
            setKeyProperty(entity, key);
            ProcessDefinition definition = ProcessDefinition.getRefreshedProcessDefinition(entityManagerTemplate, getActivityRules().getProcessRules().getProcessDefinition());
            setProcessDefinitionProperty(entity, definition);
            entityManagerTemplate.persist(entity);
            // Now we must flush to avoid concurrent updates clashing trying to
            // insert the same row
            LOG.debug("About to flush on entity: {} with key: {}", entity, key);
            entityManagerTemplate.flush();
        }
        return entity;
    } finally {
        LOCK.unlock();
    }
}
Also used : ProcessDefinition(org.apache.camel.bam.model.ProcessDefinition)

Aggregations

ProcessDefinition (org.apache.camel.bam.model.ProcessDefinition)3 HashMap (java.util.HashMap)2 ActivityDefinition (org.apache.camel.bam.model.ActivityDefinition)1