Search in sources :

Example 1 with RepositoryMetadata

use of org.apache.deltaspike.data.impl.meta.RepositoryMetadata 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

PersistenceException (javax.persistence.PersistenceException)1 QueryInvocationException (org.apache.deltaspike.data.api.QueryInvocationException)1 QueryBuilder (org.apache.deltaspike.data.impl.builder.QueryBuilder)1 RepositoryMetadata (org.apache.deltaspike.data.impl.meta.RepositoryMetadata)1 RepositoryMethodMetadata (org.apache.deltaspike.data.impl.meta.RepositoryMethodMetadata)1