Search in sources :

Example 1 with RepositoryMethodMetadata

use of org.apache.deltaspike.data.impl.meta.RepositoryMethodMetadata in project deltaspike by apache.

the class CdiQueryContextHolderTest method dummyRepoMethod.

private RepositoryMethodMetadata dummyRepoMethod(RepositoryMetadata metadata) {
    RepositoryMethodMetadata methodMetadata = new RepositoryMethodMetadata(dummyMethod());
    methodMetadata.setMethodPrefix(new RepositoryMethodPrefix(metadata.getRepositoryClass().getAnnotation(Repository.class).methodPrefix(), dummyMethod().getName()));
    return methodMetadata;
}
Also used : Repository(org.apache.deltaspike.data.api.Repository) SimpleRepository(org.apache.deltaspike.data.test.service.SimpleRepository) RepositoryMethodMetadata(org.apache.deltaspike.data.impl.meta.RepositoryMethodMetadata) RepositoryMethodPrefix(org.apache.deltaspike.data.impl.meta.RepositoryMethodPrefix)

Example 2 with RepositoryMethodMetadata

use of org.apache.deltaspike.data.impl.meta.RepositoryMethodMetadata in project deltaspike by apache.

the class QueryHandler method process.

public Object process(Object proxy, Method method, Object[] args) throws Throwable {
    CdiQueryInvocationContext queryContext = null;
    EntityManagerRef entityManagerRef = null;
    try {
        List<Class<?>> candidates = ProxyUtils.getProxyAndBaseTypes(proxy.getClass());
        RepositoryMetadata repositoryMetadata = metadataHandler.lookupComponent(candidates);
        RepositoryMethodMetadata repositoryMethodMetadata = metadataHandler.lookupMethod(repositoryMetadata, method);
        entityManagerRef = entityManagerRefLookup.lookupReference(repositoryMetadata);
        queryContext = createContext(proxy, method, args, entityManagerRef.getEntityManager(), repositoryMetadata, repositoryMethodMetadata);
        QueryBuilder builder = queryBuilderFactory.build(repositoryMethodMetadata, queryContext);
        Object result = runner.executeQuery(builder, queryContext);
        return result;
    } catch (PersistenceException e) {
        throw e;
    } catch (Exception e) {
        log.log(Level.FINEST, "Query execution error", e);
        if (queryContext != null) {
            throw new QueryInvocationException(e, queryContext);
        }
        throw new QueryInvocationException(e, proxy.getClass(), method);
    } finally {
        if (entityManagerRef != null) {
            entityManagerRef.release();
        }
        context.dispose();
    }
}
Also used : RepositoryMetadata(org.apache.deltaspike.data.impl.meta.RepositoryMetadata) QueryInvocationException(org.apache.deltaspike.data.api.QueryInvocationException) PersistenceException(javax.persistence.PersistenceException) RepositoryMethodMetadata(org.apache.deltaspike.data.impl.meta.RepositoryMethodMetadata) QueryBuilder(org.apache.deltaspike.data.impl.builder.QueryBuilder) QueryInvocationException(org.apache.deltaspike.data.api.QueryInvocationException) PersistenceException(javax.persistence.PersistenceException)

Aggregations

RepositoryMethodMetadata (org.apache.deltaspike.data.impl.meta.RepositoryMethodMetadata)2 PersistenceException (javax.persistence.PersistenceException)1 QueryInvocationException (org.apache.deltaspike.data.api.QueryInvocationException)1 Repository (org.apache.deltaspike.data.api.Repository)1 QueryBuilder (org.apache.deltaspike.data.impl.builder.QueryBuilder)1 RepositoryMetadata (org.apache.deltaspike.data.impl.meta.RepositoryMetadata)1 RepositoryMethodPrefix (org.apache.deltaspike.data.impl.meta.RepositoryMethodPrefix)1 SimpleRepository (org.apache.deltaspike.data.test.service.SimpleRepository)1