org.activiti.engine.impl.variable.EntityManagerSession Java Examples

The following examples show how to use org.activiti.engine.impl.variable.EntityManagerSession. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JPAEnhancedVariableTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: HistoricJPAVariableTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #3
Source File: JPAVariableTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void initializeProcessEngine() {
    if (cachedProcessEngine == null) {
        ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("org/activiti/standalone/jpa/flowable.cfg.xml");

        cachedProcessEngine = processEngineConfiguration.buildProcessEngine();

        org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl activiti5ProcessEngineConfig = (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ((ProcessEngineConfigurationImpl) cachedProcessEngine
                .getProcessEngineConfiguration()).getFlowable5CompatibilityHandler().getRawProcessConfiguration();

        EntityManagerSessionFactory entityManagerSessionFactory = (EntityManagerSessionFactory) activiti5ProcessEngineConfig
                .getSessionFactories()
                .get(EntityManagerSession.class);

        entityManagerFactory = entityManagerSessionFactory.getEntityManagerFactory();
    }
    processEngine = cachedProcessEngine;
}
 
Example #4
Source File: JPAEnhancedVariableTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void initializeProcessEngine() {
    if (cachedProcessEngine == null) {
        ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("org/activiti/standalone/jpa/flowable.cfg.xml");

        cachedProcessEngine = processEngineConfiguration.buildProcessEngine();

        activiti5ProcessEngineConfig = (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ((ProcessEngineConfigurationImpl) cachedProcessEngine.getProcessEngineConfiguration()).getFlowable5CompatibilityHandler()
                .getRawProcessConfiguration();

        EntityManagerSessionFactory entityManagerSessionFactory = (EntityManagerSessionFactory) activiti5ProcessEngineConfig
                .getSessionFactories()
                .get(EntityManagerSession.class);

        entityManagerFactory = entityManagerSessionFactory.getEntityManagerFactory();

        setupJPAVariables();
    }
    processEngine = cachedProcessEngine;
}
 
Example #5
Source File: HistoricJPAVariableTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void initializeProcessEngine() {
    if (cachedProcessEngine == null) {
        ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("org/activiti/standalone/jpa/flowable.cfg.xml");

        cachedProcessEngine = processEngineConfiguration.buildProcessEngine();

        org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl activiti5ProcessEngineConfig = (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ((ProcessEngineConfigurationImpl) cachedProcessEngine
                .getProcessEngineConfiguration()).getFlowable5CompatibilityHandler().getRawProcessConfiguration();

        EntityManagerSessionFactory entityManagerSessionFactory = (EntityManagerSessionFactory) activiti5ProcessEngineConfig
                .getSessionFactories()
                .get(EntityManagerSession.class);

        entityManagerFactory = entityManagerSessionFactory.getEntityManagerFactory();
    }
    processEngine = cachedProcessEngine;
}
 
Example #6
Source File: ProcessEngineConfigurationImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected 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));
        }
    }
}
 
Example #7
Source File: LeaveJpaEntityTest.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
protected void initializeProcessEngine() {
    if (cachedProcessEngine == null) {
        ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("activiti.jpa.cfg.xml");

        cachedProcessEngine = processEngineConfiguration.buildProcessEngine();

        EntityManagerSessionFactory entityManagerSessionFactory = (EntityManagerSessionFactory) processEngineConfiguration
                .getSessionFactories()
                .get(EntityManagerSession.class);

        System.out.println("entityManagerSessionFactory=" + entityManagerSessionFactory);
        entityManagerFactory = entityManagerSessionFactory.getEntityManagerFactory();
    }
    processEngine = cachedProcessEngine;
}
 
Example #8
Source File: SpringProcessEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void initJpa() {
  super.initJpa();
  if (jpaEntityManagerFactory != null) {
    sessionFactories.put(EntityManagerSession.class, new SpringEntityManagerSessionFactory(jpaEntityManagerFactory, jpaHandleTransaction, jpaCloseEntityManager));
  }
}
 
Example #9
Source File: JPAVariableTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: FullHistoryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@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();

  assertEquals(1, variableUpdates.size());
  HistoricVariableUpdate update = (HistoricVariableUpdate) variableUpdates.get(0);
  assertNotNull(update.getValue());
  assertTrue(update.getValue() instanceof FieldAccessJPAEntity);

  assertEquals(entity.getId(), ((FieldAccessJPAEntity) update.getValue()).getId());
}
 
Example #11
Source File: FullHistoryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/standalone/jpa/JPAVariableTest.testQueryJPAVariable.bpmn20.xml" })
public void testReadJpaVariableValueFromHistoricVariableUpdate() {
    org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl activiti5ProcessEngineConfig = (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) processEngineConfiguration.getFlowable5CompatibilityHandler()
            .getRawProcessConfiguration();

    EntityManagerSessionFactory entityManagerSessionFactory = (EntityManagerSessionFactory) activiti5ProcessEngineConfig
            .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();

    org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(executionId).taskName("my task").singleResult();

    runtimeService.setVariable(executionId, variableName, entity);
    taskService.complete(task.getId());

    List<org.activiti.engine.history.HistoricDetail> variableUpdates = activiti5ProcessEngineConfig.getHistoryService().createHistoricDetailQuery().processInstanceId(executionId).variableUpdates().list();

    assertEquals(1, variableUpdates.size());
    org.activiti.engine.history.HistoricVariableUpdate update = (org.activiti.engine.history.HistoricVariableUpdate) variableUpdates.get(0);
    assertNotNull(update.getValue());
    assertTrue(update.getValue() instanceof FieldAccessJPAEntity);

    assertEquals(entity.getId(), ((FieldAccessJPAEntity) update.getValue()).getId());
}
 
Example #12
Source File: SpringProcessEngineConfiguration.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void initJpa() {
    super.initJpa();
    if (jpaEntityManagerFactory != null) {
        sessionFactories.put(EntityManagerSession.class, new SpringEntityManagerSessionFactory(jpaEntityManagerFactory, jpaHandleTransaction, jpaCloseEntityManager));
    }
}
 
Example #13
Source File: LeaveJpaEntityTest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
protected void initializeProcessEngine() {
    if (cachedProcessEngine == null) {
        ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("activiti.jpa.cfg.xml");

        cachedProcessEngine = processEngineConfiguration.buildProcessEngine();

        EntityManagerSessionFactory entityManagerSessionFactory = (EntityManagerSessionFactory) processEngineConfiguration
                .getSessionFactories()
                .get(EntityManagerSession.class);

        entityManagerFactory = entityManagerSessionFactory.getEntityManagerFactory();
    }
    processEngine = cachedProcessEngine;
}
 
Example #14
Source File: LeaveJpaEntityTest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
protected void initializeProcessEngine() {
    if (cachedProcessEngine == null) {
        ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("activiti.jpa.cfg.xml");

        cachedProcessEngine = processEngineConfiguration.buildProcessEngine();

        EntityManagerSessionFactory entityManagerSessionFactory = (EntityManagerSessionFactory) processEngineConfiguration
                .getSessionFactories()
                .get(EntityManagerSession.class);

        entityManagerFactory = entityManagerSessionFactory.getEntityManagerFactory();
    }
    processEngine = cachedProcessEngine;
}
 
Example #15
Source File: LeaveJpaEntityTest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
protected void initializeProcessEngine() {
    if (cachedProcessEngine == null) {
        ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("activiti.jpa.cfg.xml");

        cachedProcessEngine = processEngineConfiguration.buildProcessEngine();

        EntityManagerSessionFactory entityManagerSessionFactory = (EntityManagerSessionFactory) processEngineConfiguration
                .getSessionFactories()
                .get(EntityManagerSession.class);

        entityManagerFactory = entityManagerSessionFactory.getEntityManagerFactory();
    }
    processEngine = cachedProcessEngine;
}