Search in sources :

Example 1 with Repository

use of org.apache.deltaspike.data.api.Repository in project deltaspike by apache.

the class EntityMetadataInitializer method extract.

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 = extractFromType(intf);
        if (entityMetadata != null) {
            return entityMetadata;
        }
    }
    if (repositoryClass.getSuperclass() != null) {
        return extract(repositoryClass.getSuperclass());
    }
    return null;
}
Also used : Repository(org.apache.deltaspike.data.api.Repository) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type)

Aggregations

ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Repository (org.apache.deltaspike.data.api.Repository)1