Search in sources :

Example 1 with EntityManagerSessionFactory

use of org.activiti.engine.impl.variable.EntityManagerSessionFactory in project Activiti by Activiti.

the class HistoricJPAVariableTest method initializeProcessEngine.

@Override
protected void initializeProcessEngine() {
    if (cachedProcessEngine == null) {
        ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("org/activiti/standalone/jpa/activiti.cfg.xml");
        cachedProcessEngine = processEngineConfiguration.buildProcessEngine();
        EntityManagerSessionFactory entityManagerSessionFactory = (EntityManagerSessionFactory) processEngineConfiguration.getSessionFactories().get(EntityManagerSession.class);
        entityManagerFactory = entityManagerSessionFactory.getEntityManagerFactory();
    }
    processEngine = cachedProcessEngine;
}
Also used : EntityManagerSession(org.activiti.engine.impl.variable.EntityManagerSession) EntityManagerSessionFactory(org.activiti.engine.impl.variable.EntityManagerSessionFactory) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)

Example 2 with EntityManagerSessionFactory

use of org.activiti.engine.impl.variable.EntityManagerSessionFactory in project Activiti by Activiti.

the class JPAVariableTest method initializeProcessEngine.

protected void initializeProcessEngine() {
    if (cachedProcessEngine == null) {
        ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("org/activiti/standalone/jpa/activiti.cfg.xml");
        cachedProcessEngine = processEngineConfiguration.buildProcessEngine();
        EntityManagerSessionFactory entityManagerSessionFactory = (EntityManagerSessionFactory) processEngineConfiguration.getSessionFactories().get(EntityManagerSession.class);
        entityManagerFactory = entityManagerSessionFactory.getEntityManagerFactory();
    }
    processEngine = cachedProcessEngine;
}
Also used : EntityManagerSession(org.activiti.engine.impl.variable.EntityManagerSession) EntityManagerSessionFactory(org.activiti.engine.impl.variable.EntityManagerSessionFactory) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)

Example 3 with EntityManagerSessionFactory

use of org.activiti.engine.impl.variable.EntityManagerSessionFactory in project Activiti by Activiti.

the class ProcessEngineConfigurationImpl method initJpa.

// JPA
// //////////////////////////////////////////////////////////////////////
public void initJpa() {
    if (jpaPersistenceUnitName != null) {
        jpaEntityManagerFactory = JpaHelper.createEntityManagerFactory(jpaPersistenceUnitName);
    }
    if (jpaEntityManagerFactory != null) {
        sessionFactories.put(EntityManagerSession.class, new EntityManagerSessionFactory(jpaEntityManagerFactory, jpaHandleTransaction, jpaCloseEntityManager));
        VariableType jpaType = variableTypes.getVariableType(JPAEntityVariableType.TYPE_NAME);
        // Add JPA-type
        if (jpaType == null) {
            // We try adding the variable right before SerializableType, if
            // available
            int serializableIndex = variableTypes.getTypeIndex(SerializableType.TYPE_NAME);
            if (serializableIndex > -1) {
                variableTypes.addType(new JPAEntityVariableType(), serializableIndex);
            } else {
                variableTypes.addType(new JPAEntityVariableType());
            }
        }
        jpaType = variableTypes.getVariableType(JPAEntityListVariableType.TYPE_NAME);
        // Add JPA-list type after regular JPA type if not already present
        if (jpaType == null) {
            variableTypes.addType(new JPAEntityListVariableType(), variableTypes.getTypeIndex(JPAEntityVariableType.TYPE_NAME));
        }
    }
}
Also used : EntityManagerSessionFactory(org.activiti.engine.impl.variable.EntityManagerSessionFactory) JPAEntityListVariableType(org.activiti.engine.impl.variable.JPAEntityListVariableType) VariableType(org.activiti.engine.impl.variable.VariableType) JPAEntityVariableType(org.activiti.engine.impl.variable.JPAEntityVariableType) JPAEntityVariableType(org.activiti.engine.impl.variable.JPAEntityVariableType) JPAEntityListVariableType(org.activiti.engine.impl.variable.JPAEntityListVariableType)

Example 4 with EntityManagerSessionFactory

use of org.activiti.engine.impl.variable.EntityManagerSessionFactory in project Activiti by Activiti.

the class FullHistoryTest method testReadJpaVariableValueFromHistoricVariableUpdate.

@Deployment(resources = { "org/activiti/standalone/jpa/JPAVariableTest.testQueryJPAVariable.bpmn20.xml" })
public void testReadJpaVariableValueFromHistoricVariableUpdate() {
    EntityManagerSessionFactory entityManagerSessionFactory = (EntityManagerSessionFactory) processEngineConfiguration.getSessionFactories().get(EntityManagerSession.class);
    EntityManagerFactory entityManagerFactory = entityManagerSessionFactory.getEntityManagerFactory();
    String executionId = runtimeService.startProcessInstanceByKey("JPAVariableProcess").getProcessInstanceId();
    String variableName = "name";
    FieldAccessJPAEntity entity = new FieldAccessJPAEntity();
    entity.setId(1L);
    entity.setValue("Test");
    EntityManager manager = entityManagerFactory.createEntityManager();
    manager.getTransaction().begin();
    manager.persist(entity);
    manager.flush();
    manager.getTransaction().commit();
    manager.close();
    Task task = taskService.createTaskQuery().processInstanceId(executionId).taskName("my task").singleResult();
    runtimeService.setVariable(executionId, variableName, entity);
    taskService.complete(task.getId());
    List<HistoricDetail> variableUpdates = historyService.createHistoricDetailQuery().processInstanceId(executionId).variableUpdates().list();
    assertThat(variableUpdates.size()).isEqualTo(1);
    HistoricVariableUpdate update = (HistoricVariableUpdate) variableUpdates.get(0);
    assertThat(update.getValue()).isNotNull();
    assertThat(update.getValue()).isInstanceOf(FieldAccessJPAEntity.class);
    assertThat(((FieldAccessJPAEntity) update.getValue()).getId()).isEqualTo(entity.getId());
}
Also used : EntityManagerSession(org.activiti.engine.impl.variable.EntityManagerSession) HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) EntityManagerSessionFactory(org.activiti.engine.impl.variable.EntityManagerSessionFactory) HistoricDetail(org.activiti.engine.history.HistoricDetail) EntityManager(javax.persistence.EntityManager) Task(org.activiti.engine.task.Task) EntityManagerFactory(javax.persistence.EntityManagerFactory) FieldAccessJPAEntity(org.activiti.standalone.jpa.FieldAccessJPAEntity) Deployment(org.activiti.engine.test.Deployment)

Example 5 with EntityManagerSessionFactory

use of org.activiti.engine.impl.variable.EntityManagerSessionFactory in project Activiti by Activiti.

the class JPAEnhancedVariableTest method initializeProcessEngine.

@Override
protected void initializeProcessEngine() {
    if (cachedProcessEngine == null) {
        ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("org/activiti/standalone/jpa/activiti.cfg.xml");
        cachedProcessEngine = processEngineConfiguration.buildProcessEngine();
        EntityManagerSessionFactory entityManagerSessionFactory = (EntityManagerSessionFactory) processEngineConfiguration.getSessionFactories().get(EntityManagerSession.class);
        entityManagerFactory = entityManagerSessionFactory.getEntityManagerFactory();
        setupJPAVariables();
    }
    processEngine = cachedProcessEngine;
}
Also used : EntityManagerSession(org.activiti.engine.impl.variable.EntityManagerSession) EntityManagerSessionFactory(org.activiti.engine.impl.variable.EntityManagerSessionFactory) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)

Aggregations

EntityManagerSessionFactory (org.activiti.engine.impl.variable.EntityManagerSessionFactory)5 EntityManagerSession (org.activiti.engine.impl.variable.EntityManagerSession)4 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)3 EntityManager (javax.persistence.EntityManager)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 HistoricDetail (org.activiti.engine.history.HistoricDetail)1 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)1 JPAEntityListVariableType (org.activiti.engine.impl.variable.JPAEntityListVariableType)1 JPAEntityVariableType (org.activiti.engine.impl.variable.JPAEntityVariableType)1 VariableType (org.activiti.engine.impl.variable.VariableType)1 Task (org.activiti.engine.task.Task)1 Deployment (org.activiti.engine.test.Deployment)1 FieldAccessJPAEntity (org.activiti.standalone.jpa.FieldAccessJPAEntity)1