Java 类org.springframework.data.repository.RepositoryDefinition 实例源码

项目:ef-orm    文件:GqRepositoryFactoryBean.java   
private Object generateCustomImplementation() {
    EntityManagerFactory emf = context.getBean(entityManagerFactoryRef, EntityManagerFactory.class);
    for (Class<?> clz : repositoryInterface.getInterfaces()) {
        if (Repository.class.isAssignableFrom(clz)) {
            continue;
        } else if (clz.getAnnotation(RepositoryDefinition.class) != null) {
            continue;
        }
        String implementation=clz.getName() + StringUtils.trimToEmpty(repositoryImplementationPostfix);
        ClassEx implClz = ClassEx.forName(implementation);
        if (implClz == null) {
            log.error("Lack of implementation class: " + clz.getName());
            throw new IllegalArgumentException("Lack of implementation class: " + implementation);
        }
        try {
            Object obj = implClz.newInstance();
            for (FieldEx field : implClz.getDeclaredFields()) {
                if (field.getAnnotation(PersistenceContext.class) != null) {
                    field.set(obj, QueryUtils.getEntityManager((JefEntityManagerFactory) emf));
                }
            }
            if (obj instanceof ApplicationContextAware) {
                ((ApplicationContextAware) obj).setApplicationContext(context);
            }
            if (obj instanceof InitializingBean) {
                ((InitializingBean) obj).afterPropertiesSet();
            }
            return obj;
        } catch (Exception ex) {
            log.error("", ex);
            return null;
        }
    }
    return null;
}