org.apache.deltaspike.data.api.Repository Java Examples

The following examples show how to use org.apache.deltaspike.data.api.Repository. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepositoryMethodMetadataInitializer.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
public RepositoryMethodMetadata init(RepositoryMetadata repositoryMetadata, Method method, BeanManager beanManager)
{
    RepositoryMethodMetadata repositoryMethodMetadata = new RepositoryMethodMetadata();
    
    repositoryMethodMetadata.setMethod(method);

    repositoryMethodMetadata.setReturnsOptional(Optional.class.isAssignableFrom(method.getReturnType()));
    repositoryMethodMetadata.setReturnsStream(Stream.class.isAssignableFrom(method.getReturnType()));
    
    repositoryMethodMetadata.setQuery(method.isAnnotationPresent(Query.class)
            ? method.getAnnotation(Query.class) : null);
    repositoryMethodMetadata.setModifying(method.isAnnotationPresent(Modifying.class)
            ? method.getAnnotation(Modifying.class) : null);
    
    repositoryMethodMetadata.setTransactional(AnnotationUtils.extractAnnotationFromMethodOrClass(
            beanManager, method, repositoryMetadata.getRepositoryClass(), Transactional.class));

    repositoryMethodMetadata.setMethodPrefix(new RepositoryMethodPrefix(
                repositoryMetadata.getRepositoryClass().getAnnotation(Repository.class).methodPrefix(),
                method.getName()));
    repositoryMethodMetadata.setMethodType(
            extractMethodType(repositoryMetadata, repositoryMethodMetadata));
    
    repositoryMethodMetadata.setQueryProcessor(queryProcessorFactory.build(repositoryMethodMetadata));
    
    repositoryMethodMetadata.setQueryInOutMapperClass(
            extractMapper(method, repositoryMetadata));

    initQueryRoot(repositoryMetadata, repositoryMethodMetadata);
    initQueryInOutMapperIsNormalScope(repositoryMethodMetadata, beanManager);

    initSingleResultType(repositoryMethodMetadata);
    initRequiresTransaction(repositoryMethodMetadata);

    
    return repositoryMethodMetadata;
}
 
Example #2
Source File: EntityMetadataInitializer.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
private EntityMetadata extract(Class<?> repositoryClass)
{
    // get from annotation
    Repository repository = repositoryClass.getAnnotation(Repository.class);
    Class<?> entityClass = repository.forEntity();
    boolean isEntityClass = !Object.class.equals(entityClass) && EntityUtils.isEntityClass(entityClass);
    if (isEntityClass)
    {
        return new EntityMetadata(entityClass, EntityUtils.primaryKeyClass(entityClass));
    }
    
    // get from type
    for (Type inf : repositoryClass.getGenericInterfaces())
    {
        EntityMetadata result = extractFromType(inf);
        if (result != null)
        {
            return result;
        }
    }

    EntityMetadata entityMetadata = extractFromType(repositoryClass.getGenericSuperclass());
    if (entityMetadata != null)
    {
        return entityMetadata;
    }
    for (Type intf : repositoryClass.getGenericInterfaces())
    {
        entityMetadata = extract( (Class< ? >)intf );
        if (entityMetadata != null)
        {
            return entityMetadata;
        }
    }
    if (repositoryClass.getSuperclass() != null)
    {
        return extract(repositoryClass.getSuperclass());
    }
    return null;
}
 
Example #3
Source File: CdiQueryContextHolderTest.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
private RepositoryMethodMetadata dummyRepoMethod(RepositoryMetadata metadata)
{
    RepositoryMethodMetadata methodMetadata = new RepositoryMethodMetadata(dummyMethod());
    methodMetadata.setMethodPrefix(new RepositoryMethodPrefix(
                metadata.getRepositoryClass().getAnnotation(Repository.class).methodPrefix(),
                dummyMethod().getName()));
    
    return methodMetadata;
}
 
Example #4
Source File: RepositoryExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
private <X> boolean isRepository(AnnotatedType<X> annotatedType)
{
    return (annotatedType.isAnnotationPresent(Repository.class) ||
            annotatedType.getJavaClass().isAnnotationPresent(Repository.class)) &&
            !InvocationHandler.class.isAssignableFrom(annotatedType.getJavaClass());
}