Search in sources :

Example 1 with JpaQueryFactoryContext

use of io.crnk.jpa.query.JpaQueryFactoryContext in project crnk-framework by crnk-project.

the class JpaModule method initQueryFactory.

private void initQueryFactory() {
    JpaQueryFactory queryFactory = config.getQueryFactory();
    queryFactory.initalize(new JpaQueryFactoryContext() {

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

        @Override
        public MetaPartition getMetaPartition() {
            return jpaMetaProvider.getPartition();
        }
    });
    if (queryFactory instanceof QuerydslQueryFactory) {
        QuerydslQueryFactory querydslFactory = (QuerydslQueryFactory) queryFactory;
        querydslFactory.addInterceptor(new JpaQuerydslTranslationInterceptor());
    }
}
Also used : QuerydslQueryFactory(io.crnk.jpa.query.querydsl.QuerydslQueryFactory) EntityManager(javax.persistence.EntityManager) JpaQueryFactoryContext(io.crnk.jpa.query.JpaQueryFactoryContext) JpaQueryFactory(io.crnk.jpa.query.JpaQueryFactory) MetaPartition(io.crnk.meta.provider.MetaPartition)

Example 2 with JpaQueryFactoryContext

use of io.crnk.jpa.query.JpaQueryFactoryContext 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

JpaQueryFactoryContext (io.crnk.jpa.query.JpaQueryFactoryContext)2 MetaPartition (io.crnk.meta.provider.MetaPartition)2 EntityManager (javax.persistence.EntityManager)2 JpaMetaProvider (io.crnk.jpa.meta.JpaMetaProvider)1 JpaQueryFactory (io.crnk.jpa.query.JpaQueryFactory)1 QuerydslQueryFactory (io.crnk.jpa.query.querydsl.QuerydslQueryFactory)1 MetaLookup (io.crnk.meta.MetaLookup)1 MovieEntity (io.crnk.operations.model.MovieEntity)1 PersonEntity (io.crnk.operations.model.PersonEntity)1