Search in sources :

Example 1 with TransactionRunner

use of io.crnk.core.engine.transaction.TransactionRunner in project crnk-framework by crnk-project.

the class CdiTransactionRunnerTest method setup.

@Before
public void setup() {
    DefaultServiceDiscoveryFactory factory = new DefaultServiceDiscoveryFactory();
    ServiceDiscovery instance = factory.getInstance();
    List<TransactionRunner> runners = instance.getInstancesByType(TransactionRunner.class);
    Assert.assertEquals(1, runners.size());
    runner = runners.get(0);
}
Also used : DefaultServiceDiscoveryFactory(io.crnk.core.module.discovery.DefaultServiceDiscoveryFactory) CdiTransactionRunner(io.crnk.cdi.internal.CdiTransactionRunner) TransactionRunner(io.crnk.core.engine.transaction.TransactionRunner) ServiceDiscovery(io.crnk.core.module.discovery.ServiceDiscovery) Before(org.junit.Before)

Example 2 with TransactionRunner

use of io.crnk.core.engine.transaction.TransactionRunner in project crnk-framework by crnk-project.

the class TransactionOperationFilter method filter.

@Override
public List<OperationResponse> filter(final OperationFilterContext context, final OperationFilterChain chain) {
    ServiceDiscovery serviceDiscovery = context.getServiceDiscovery();
    List<TransactionRunner> transactionRunners = serviceDiscovery.getInstancesByType(TransactionRunner.class);
    PreconditionUtil.assertEquals("expected single transaction runner", 1, transactionRunners.size());
    TransactionRunner transactionRunner = transactionRunners.get(0);
    return transactionRunner.doInTransaction(new Callable<List<OperationResponse>>() {

        @Override
        public List<OperationResponse> call() throws Exception {
            return chain.doFilter(context);
        }
    });
}
Also used : TransactionRunner(io.crnk.core.engine.transaction.TransactionRunner) List(java.util.List) ServiceDiscovery(io.crnk.core.module.discovery.ServiceDiscovery)

Example 3 with TransactionRunner

use of io.crnk.core.engine.transaction.TransactionRunner in project crnk-framework by crnk-project.

the class QueryFactoryDiscoveryTest method checkJpaModuleIntegration.

@Test
public void checkJpaModuleIntegration() {
    TransactionRunner transactionRunner = Mockito.mock(TransactionRunner.class);
    EntityManager em = Mockito.mock(EntityManager.class);
    JpaModule module = JpaModule.newServerModule(em, transactionRunner);
    Assert.assertEquals(QuerydslQueryFactory.class, module.getQueryFactory().getClass());
}
Also used : EntityManager(javax.persistence.EntityManager) TransactionRunner(io.crnk.core.engine.transaction.TransactionRunner) JpaModule(io.crnk.jpa.JpaModule) Test(org.junit.Test)

Example 4 with TransactionRunner

use of io.crnk.core.engine.transaction.TransactionRunner in project crnk-framework by crnk-project.

the class JpaModuleTest method cannotPerformDuplicateRegistration.

@Test(expected = IllegalStateException.class)
public void cannotPerformDuplicateRegistration() {
    TransactionRunner transactionRunner = Mockito.mock(TransactionRunner.class);
    EntityManager em = Mockito.mock(EntityManager.class);
    JpaModule module = JpaModule.newServerModule(em, transactionRunner);
    module.addRepository(JpaRepositoryConfig.create(TestEntity.class));
    module.addRepository(JpaRepositoryConfig.create(TestEntity.class));
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) EntityManager(javax.persistence.EntityManager) TransactionRunner(io.crnk.core.engine.transaction.TransactionRunner) Test(org.junit.Test)

Aggregations

TransactionRunner (io.crnk.core.engine.transaction.TransactionRunner)4 ServiceDiscovery (io.crnk.core.module.discovery.ServiceDiscovery)2 EntityManager (javax.persistence.EntityManager)2 Test (org.junit.Test)2 CdiTransactionRunner (io.crnk.cdi.internal.CdiTransactionRunner)1 DefaultServiceDiscoveryFactory (io.crnk.core.module.discovery.DefaultServiceDiscoveryFactory)1 JpaModule (io.crnk.jpa.JpaModule)1 TestEntity (io.crnk.jpa.model.TestEntity)1 List (java.util.List)1 Before (org.junit.Before)1