Search in sources :

Example 1 with SpringTransactionRunner

use of io.crnk.jpa.util.SpringTransactionRunner in project crnk-framework by crnk-project.

the class AbstractJpaJerseyTest method tearDown.

@Override
@After
public void tearDown() throws Exception {
    super.tearDown();
    SpringTransactionRunner transactionRunner = context.getBean(SpringTransactionRunner.class);
    transactionRunner.doInTransaction(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            EntityManager em = context.getBean(EntityManagerProducer.class).getEntityManager();
            AbstractJpaTest.clear(em);
            return null;
        }
    });
    if (context != null) {
        context.destroy();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) SpringTransactionRunner(io.crnk.jpa.util.SpringTransactionRunner) After(org.junit.After)

Example 2 with SpringTransactionRunner

use of io.crnk.jpa.util.SpringTransactionRunner in project crnk-framework by crnk-project.

the class CustomResourceFieldTest method setup.

@Override
@Before
public void setup() {
    super.setup();
    SpringTransactionRunner transactionRunner = context.getBean(SpringTransactionRunner.class);
    transactionRunner.doInTransaction(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            EntityManager em = context.getBean(EntityManagerProducer.class).getEntityManager();
            AbstractJpaTest.clear(em);
            LangEntity en = new LangEntity();
            en.setLangCd("en");
            em.persist(en);
            LangEntity de = new LangEntity();
            de.setLangCd("de");
            em.persist(de);
            CountryEntity ch = new CountryEntity();
            ch.setCountryCd("ch");
            ch.setCtlActCd(true);
            em.persist(ch);
            CountryTranslationEntity chDe = new CountryTranslationEntity();
            CountryTranslationPK chDePk = new CountryTranslationPK();
            chDePk.setCountry(ch);
            chDePk.setLang(de);
            chDe.setCountryTranslationPk(chDePk);
            chDe.setTxt("Schweiz");
            em.persist(chDe);
            CountryTranslationEntity chEn = new CountryTranslationEntity();
            CountryTranslationPK chEnPk = new CountryTranslationPK();
            chEnPk.setCountry(ch);
            chEnPk.setLang(en);
            chEn.setCountryTranslationPk(chEnPk);
            chEn.setTxt("Switzerland");
            em.persist(chEn);
            em.flush();
            return null;
        }
    });
}
Also used : LangEntity(io.crnk.jpa.model.LangEntity) EntityManager(javax.persistence.EntityManager) CountryTranslationEntity(io.crnk.jpa.model.CountryTranslationEntity) SpringTransactionRunner(io.crnk.jpa.util.SpringTransactionRunner) CountryTranslationPK(io.crnk.jpa.model.CountryTranslationPK) CountryEntity(io.crnk.jpa.model.CountryEntity) Before(org.junit.Before)

Aggregations

SpringTransactionRunner (io.crnk.jpa.util.SpringTransactionRunner)2 EntityManager (javax.persistence.EntityManager)2 CountryEntity (io.crnk.jpa.model.CountryEntity)1 CountryTranslationEntity (io.crnk.jpa.model.CountryTranslationEntity)1 CountryTranslationPK (io.crnk.jpa.model.CountryTranslationPK)1 LangEntity (io.crnk.jpa.model.LangEntity)1 After (org.junit.After)1 Before (org.junit.Before)1