Search in sources :

Example 1 with JpaMetaProvider

use of io.crnk.jpa.meta.JpaMetaProvider in project crnk-framework by crnk-project.

the class AnyTypeUtilsTest method setup.

@Before
public void setup() {
    metaProvider = new JpaMetaProvider(Collections.<Class>emptySet());
    MetaLookup lookup = new MetaLookup();
    lookup.addProvider(metaProvider);
    metaProvider.discoverMeta(TestAnyType.class);
}
Also used : MetaLookup(io.crnk.meta.MetaLookup) JpaMetaProvider(io.crnk.jpa.meta.JpaMetaProvider) Before(org.junit.Before)

Example 2 with JpaMetaProvider

use of io.crnk.jpa.meta.JpaMetaProvider in project crnk-framework by crnk-project.

the class JpaResourceInformationProviderTest method setup.

@Before
public void setup() {
    jpaMetaProvider = new JpaMetaProvider(Collections.<Class>emptySet());
    lookup = new MetaLookup();
    lookup.addProvider(jpaMetaProvider);
    builder = new JpaResourceInformationProvider(new NullPropertiesProvider());
    builder.init(new DefaultResourceInformationProviderContext(builder, new DefaultInformationBuilder(new TypeParser()), new TypeParser(), new ObjectMapper()));
}
Also used : JpaResourceInformationProvider(io.crnk.jpa.internal.JpaResourceInformationProvider) MetaLookup(io.crnk.meta.MetaLookup) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) TypeParser(io.crnk.core.engine.parser.TypeParser) JpaMetaProvider(io.crnk.jpa.meta.JpaMetaProvider) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) DefaultResourceInformationProviderContext(io.crnk.legacy.registry.DefaultResourceInformationProviderContext) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 3 with JpaMetaProvider

use of io.crnk.jpa.meta.JpaMetaProvider in project crnk-framework by crnk-project.

the class AbstractJpaTest method clear.

public static void clear(final EntityManager em, JpaQueryFactory factory) {
    factory.initalize(new JpaQueryFactoryContext() {

        @Override
        public EntityManager getEntityManager() {
            return em;
        }

        @Override
        public MetaPartition getMetaPartition() {
            JpaMetaProvider jpaMetaProvider = new JpaMetaProvider(em.getEntityManagerFactory());
            MetaLookup metaLookup = new MetaLookup();
            metaLookup.addProvider(jpaMetaProvider);
            metaLookup.initialize();
            return jpaMetaProvider.getPartition();
        }
    });
    clear(em, factory.query(OneToOneTestEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(ManyToManyTestEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(ManyToManyOppositeEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(TestSubclassWithSuperclassPk.class).buildExecutor().getResultList());
    clear(em, factory.query(RelatedEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(TestEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(OtherRelatedEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(CountryTranslationEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(CountryEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(LangEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(BasicAttributesTestEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(RenamedTestEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(UuidTestEntity.class).buildExecutor().getResultList());
    em.flush();
    em.clear();
}
Also used : MetaLookup(io.crnk.meta.MetaLookup) JpaMetaProvider(io.crnk.jpa.meta.JpaMetaProvider) EntityManager(javax.persistence.EntityManager) MetaPartition(io.crnk.meta.provider.MetaPartition)

Example 4 with JpaMetaProvider

use of io.crnk.jpa.meta.JpaMetaProvider in project crnk-framework by crnk-project.

the class JpaModule method setupModule.

@Override
public void setupModule(ModuleContext context) {
    this.context = context;
    Set<Class> jpaTypes = new HashSet<>();
    if (config != null) {
        for (JpaRepositoryConfig<?> config : config.getRepositories()) {
            jpaTypes.add(config.getEntityClass());
        }
    }
    jpaMetaProvider = new JpaMetaProvider(jpaTypes);
    jpaMetaLookup = new MetaLookup();
    jpaMetaLookup.addProvider(jpaMetaProvider);
    jpaMetaLookup.setModuleContext(context);
    jpaMetaLookup.initialize();
    if (config != null) {
        initQueryFactory();
    }
    context.addResourceInformationBuilder(getResourceInformationProvider(context.getPropertiesProvider()));
    context.addExceptionMapper(new OptimisticLockExceptionMapper());
    context.addExceptionMapper(new PersistenceExceptionMapper(context));
    context.addExceptionMapper(new PersistenceRollbackExceptionMapper(context));
    addHibernateConstraintViolationExceptionMapper();
    addTransactionRollbackExceptionMapper();
    context.addRepositoryDecoratorFactory(new JpaRepositoryDecoratorFactory());
    if (em != null) {
        metaEnricher = new JpaMetaEnricher();
        // enrich resource meta model with JPA information where incomplete
        MetaModuleExtension metaModuleExtension = new MetaModuleExtension();
        metaModuleExtension.addProvider(metaEnricher.getProvider());
        context.addExtension(metaModuleExtension);
        setupTransactionMgmt();
    }
}
Also used : MetaLookup(io.crnk.meta.MetaLookup) JpaMetaEnricher(io.crnk.jpa.meta.internal.JpaMetaEnricher) JpaMetaProvider(io.crnk.jpa.meta.JpaMetaProvider) MetaModuleExtension(io.crnk.meta.MetaModuleExtension) OptimisticLockExceptionMapper(io.crnk.jpa.internal.OptimisticLockExceptionMapper) PersistenceRollbackExceptionMapper(io.crnk.jpa.internal.PersistenceRollbackExceptionMapper) PersistenceExceptionMapper(io.crnk.jpa.internal.PersistenceExceptionMapper) HashSet(java.util.HashSet)

Example 5 with JpaMetaProvider

use of io.crnk.jpa.meta.JpaMetaProvider in project crnk-framework by crnk-project.

the class AbstractOperationsTest method clear.

public static void clear(final EntityManager em, JpaQueryFactory factory) {
    factory.initalize(new JpaQueryFactoryContext() {

        @Override
        public MetaPartition getMetaPartition() {
            MetaLookup metaLookup = new MetaLookup();
            JpaMetaProvider metaProvider = new JpaMetaProvider(em.getEntityManagerFactory());
            metaLookup.addProvider(metaProvider);
            metaLookup.initialize();
            return metaProvider.getPartition();
        }

        @Override
        public EntityManager getEntityManager() {
            return em;
        }
    });
    clear(em, factory.query(MovieEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(PersonEntity.class).buildExecutor().getResultList());
    em.flush();
    em.clear();
}
Also used : EntityManager(javax.persistence.EntityManager) MetaLookup(io.crnk.meta.MetaLookup) MovieEntity(io.crnk.operations.model.MovieEntity) JpaQueryFactoryContext(io.crnk.jpa.query.JpaQueryFactoryContext) JpaMetaProvider(io.crnk.jpa.meta.JpaMetaProvider) MetaPartition(io.crnk.meta.provider.MetaPartition) PersonEntity(io.crnk.operations.model.PersonEntity)

Aggregations

JpaMetaProvider (io.crnk.jpa.meta.JpaMetaProvider)5 MetaLookup (io.crnk.meta.MetaLookup)5 MetaPartition (io.crnk.meta.provider.MetaPartition)2 EntityManager (javax.persistence.EntityManager)2 Before (org.junit.Before)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultInformationBuilder (io.crnk.core.engine.internal.information.DefaultInformationBuilder)1 TypeParser (io.crnk.core.engine.parser.TypeParser)1 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)1 JpaResourceInformationProvider (io.crnk.jpa.internal.JpaResourceInformationProvider)1 OptimisticLockExceptionMapper (io.crnk.jpa.internal.OptimisticLockExceptionMapper)1 PersistenceExceptionMapper (io.crnk.jpa.internal.PersistenceExceptionMapper)1 PersistenceRollbackExceptionMapper (io.crnk.jpa.internal.PersistenceRollbackExceptionMapper)1 JpaMetaEnricher (io.crnk.jpa.meta.internal.JpaMetaEnricher)1 JpaQueryFactoryContext (io.crnk.jpa.query.JpaQueryFactoryContext)1 DefaultResourceInformationProviderContext (io.crnk.legacy.registry.DefaultResourceInformationProviderContext)1 MetaModuleExtension (io.crnk.meta.MetaModuleExtension)1 MovieEntity (io.crnk.operations.model.MovieEntity)1 PersonEntity (io.crnk.operations.model.PersonEntity)1 HashSet (java.util.HashSet)1