public MutablePersistenceUnitInfo createUnit(Class<? extends Annotation> qualifier, String unitName) {
ClassLoader classLoader = holder.getCurrentReloadableClassLoader();
MutablePersistenceUnitInfo result = new MutablePersistenceUnitInfo();
result.setExcludeUnlistedClasses(true);
result.setValidationMode(ValidationMode.NONE);
result.setPersistenceUnitName(unitName);
result.setSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE);
try {
result.setPersistenceUnitRootUrl(new URL("http://foo.foo"));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
result.addProperty(PersistenceUnitProperties.SESSION_CUSTOMIZER, CompositeSessionCustomizer.class.getName());
// search for entities
{
Set<Class<?>> jpaAnnotations = new HashSet<>(
Arrays.asList(Entity.class, MappedSuperclass.class, Embeddable.class));
for (ClassNode classNode : index.getAllNodes()) {
String className = Type.getObjectType(classNode.name).getClassName();
if (classNode.visibleAnnotations == null)
continue;
boolean jpaAnnotationFound = false;
for (AnnotationNode annotation : classNode.visibleAnnotations) {
Class<?> annotationClass = AsmUtil.loadClass(Type.getType(annotation.desc), classLoader);
// test if the annotation is one of the jpa annotations
if (jpaAnnotations.contains(annotationClass))
jpaAnnotationFound = true;
}
if (jpaAnnotationFound && isPartOfPU(classNode, qualifier, classLoader)) {
result.addManagedClassName(className);
}
}
}
// search converters
{
index.getAllChildren(AttributeConverter.class).stream()
.filter(node -> isPartOfPU(node, qualifier, classLoader))
.map(node -> AsmUtil.loadClass(Type.getObjectType(node.name), classLoader)).forEach(cls -> {
Converter converter = cls.getAnnotation(Converter.class);
if (converter != null && converter.autoApply())
result.addManagedClassName(cls.getName());
});
}
return result;
}
PersistenceUnitManagerHelper.java 文件源码
java
阅读 35
收藏 0
点赞 0
评论 0
项目:rise
作者:
评论列表
文章目录