use of org.kie.api.runtime.Environment in project drools by kiegroup.
the class MoreBatchExecutionPersistenceTest method createKnowledgeSession.
protected StatefulKnowledgeSession createKnowledgeSession(KieBase kbase) {
if (context == null) {
context = DroolsPersistenceUtil.setupWithPoolingDataSource(DROOLS_PERSISTENCE_UNIT_NAME);
}
KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
Environment env = createEnvironment(context);
if (this.locking) {
env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
}
return JPAKnowledgeService.newStatefulKnowledgeSession(kbase, ksconf, env);
}
use of org.kie.api.runtime.Environment in project drools by kiegroup.
the class JtaTransactionManagerFactoryTest method usesEnvironmentToCreateTransactionManager.
@Test
public void usesEnvironmentToCreateTransactionManager() throws Exception {
Environment env = EnvironmentFactory.newEnvironment();
env.set(EnvironmentName.TRANSACTION, DUMMY_UT);
JtaTransactionManager txm = (JtaTransactionManager) new JtaTransactionManagerFactory().newTransactionManager(env);
assertEquals(DUMMY_UT, txm.ut);
}
use of org.kie.api.runtime.Environment in project drools by kiegroup.
the class JtaTransactionManagerTest method basicTransactionRollbackTest.
@Test
public void basicTransactionRollbackTest() {
Environment env = createEnvironment(context);
Object tm = env.get(EnvironmentName.TRANSACTION_MANAGER);
TransactionManager txm = new JtaTransactionManager(env.get(EnvironmentName.TRANSACTION), env.get(EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY), tm);
// Create linked transactionTestObjects
TransactionTestObject mainObject = new TransactionTestObject();
mainObject.setName("main");
TransactionTestObject subObject = new TransactionTestObject();
subObject.setName("sub");
mainObject.setSubObject(subObject);
EntityManager em = emf.createEntityManager();
try {
boolean txOwner = txm.begin();
boolean notTxOwner = txm.begin();
em.persist(mainObject);
txm.rollback(notTxOwner);
em.persist(subObject);
txm.rollback(txOwner);
} catch (Exception e) {
fail("There should not be an exception thrown here: " + e.getMessage());
}
}
use of org.kie.api.runtime.Environment in project drools by kiegroup.
the class TransactionTestCommand method initializeEnvironment.
private Environment initializeEnvironment() {
Environment env = EnvironmentFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());
env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManager.transactionManager());
return env;
}
use of org.kie.api.runtime.Environment in project drools by kiegroup.
the class MapBasedPersistenceTest method createSession.
@Override
protected KieSession createSession(KieBase kbase) {
EnvironmentBuilder envBuilder = new KnowledgeSessionStorageEnvironmentBuilder(storage);
Environment env = KieServices.Factory.get().newEnvironment();
env.set(EnvironmentName.TRANSACTION_MANAGER, envBuilder.getTransactionManager());
env.set(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, envBuilder.getPersistenceContextManager());
return JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
}
Aggregations