Search in sources :

Example 16 with MetaLookup

use of io.crnk.meta.MetaLookup in project crnk-framework by crnk-project.

the class JpaMetaProviderAttributeTest method setup.

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

Example 17 with MetaLookup

use of io.crnk.meta.MetaLookup in project crnk-framework by crnk-project.

the class ValidationMetaProviderTest method setup.

private void setup(boolean addValidationProvider) {
    CrnkBoot boot = new CrnkBoot();
    boot.addModule(new JaxrsModule(null));
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery("io.crnk.validation.mock", new SampleJsonServiceLocator()));
    boot.boot();
    resourceMetaProvider = new ResourceMetaProvider();
    lookup = new MetaLookup();
    lookup.setModuleContext(boot.getModuleRegistry().getContext());
    lookup.addProvider(resourceMetaProvider);
    if (addValidationProvider) {
        lookup.addProvider(new ValidationMetaProvider());
    }
    lookup.initialize();
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) MetaLookup(io.crnk.meta.MetaLookup) ResourceMetaProvider(io.crnk.meta.provider.resource.ResourceMetaProvider) JaxrsModule(io.crnk.rs.internal.JaxrsModule) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery)

Example 18 with MetaLookup

use of io.crnk.meta.MetaLookup 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 19 with MetaLookup

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

MetaLookup (io.crnk.meta.MetaLookup)19 Before (org.junit.Before)6 JpaMetaProvider (io.crnk.jpa.meta.JpaMetaProvider)5 MetaElement (io.crnk.meta.model.MetaElement)3 CrnkBoot (io.crnk.core.boot.CrnkBoot)2 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)2 ResourceNotFoundException (io.crnk.core.exception.ResourceNotFoundException)2 MetaModule (io.crnk.meta.MetaModule)2 MetaKey (io.crnk.meta.model.MetaKey)2 MetaPartition (io.crnk.meta.provider.MetaPartition)2 EntityManager (javax.persistence.EntityManager)2 Test (org.junit.Test)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 ModuleRegistry (io.crnk.core.module.ModuleRegistry)1 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)1 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)1 JpaResourceInformationProvider (io.crnk.jpa.internal.JpaResourceInformationProvider)1