Search in sources :

Example 1 with MetaModuleExtension

use of io.crnk.meta.MetaModuleExtension 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)

Aggregations

OptimisticLockExceptionMapper (io.crnk.jpa.internal.OptimisticLockExceptionMapper)1 PersistenceExceptionMapper (io.crnk.jpa.internal.PersistenceExceptionMapper)1 PersistenceRollbackExceptionMapper (io.crnk.jpa.internal.PersistenceRollbackExceptionMapper)1 JpaMetaProvider (io.crnk.jpa.meta.JpaMetaProvider)1 JpaMetaEnricher (io.crnk.jpa.meta.internal.JpaMetaEnricher)1 MetaLookup (io.crnk.meta.MetaLookup)1 MetaModuleExtension (io.crnk.meta.MetaModuleExtension)1 HashSet (java.util.HashSet)1