Search in sources :

Example 21 with Environment

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);
}
Also used : Environment(org.kie.api.runtime.Environment) DroolsPersistenceUtil.createEnvironment(org.drools.persistence.util.DroolsPersistenceUtil.createEnvironment) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration)

Example 22 with Environment

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);
}
Also used : Environment(org.kie.api.runtime.Environment) Test(org.junit.Test)

Example 23 with Environment

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());
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TransactionManager(org.drools.persistence.api.TransactionManager) DroolsPersistenceUtil.createEnvironment(org.drools.persistence.util.DroolsPersistenceUtil.createEnvironment) Environment(org.kie.api.runtime.Environment) NamingException(javax.naming.NamingException) RollbackException(javax.transaction.RollbackException) TransientObjectException(org.hibernate.TransientObjectException) Test(org.junit.Test)

Example 24 with Environment

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;
}
Also used : Environment(org.kie.api.runtime.Environment) MapGlobalResolver(org.drools.core.base.MapGlobalResolver)

Example 25 with Environment

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);
}
Also used : KnowledgeSessionStorageEnvironmentBuilder(org.drools.persistence.map.KnowledgeSessionStorageEnvironmentBuilder) EnvironmentBuilder(org.drools.persistence.map.EnvironmentBuilder) KnowledgeSessionStorageEnvironmentBuilder(org.drools.persistence.map.KnowledgeSessionStorageEnvironmentBuilder) Environment(org.kie.api.runtime.Environment)

Aggregations

Environment (org.kie.api.runtime.Environment)31 Test (org.junit.Test)15 KieBase (org.kie.api.KieBase)9 KieSession (org.kie.api.runtime.KieSession)9 ArrayList (java.util.ArrayList)6 DroolsPersistenceUtil.createEnvironment (org.drools.persistence.util.DroolsPersistenceUtil.createEnvironment)6 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)6 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)5 IdentityPlaceholderResolverStrategy (org.drools.core.marshalling.impl.IdentityPlaceholderResolverStrategy)4 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)4 Cheese (org.drools.compiler.Cheese)3 PersistenceContext (org.drools.persistence.api.PersistenceContext)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Collection (java.util.Collection)2 List (java.util.List)2 EntityManager (javax.persistence.EntityManager)2 UserTransaction (javax.transaction.UserTransaction)2 Person (org.drools.compiler.Person)2 IteratorToList (org.drools.compiler.integrationtests.IteratorToList)2