use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class HibernateAnnotationScanner method getClassesInJar.
@Override
public Set<Class<?>> getClassesInJar(URL jarToScan, Set<Class<? extends Annotation>> annotationsToLookFor) {
if (jarToScan == null) {
throw JPA_LOGGER.nullVar("jarToScan");
}
JPA_LOGGER.tracef("getClassesInJar url=%s annotations=%s", jarToScan.getPath(), annotationsToLookFor);
PersistenceUnitMetadata pu = PERSISTENCE_UNIT_METADATA_TLS.get();
if (pu == null) {
throw JPA_LOGGER.missingPersistenceUnitMetadata();
}
if (pu.getAnnotationIndex() != null) {
Index index = getJarFileIndex(jarToScan, pu);
if (index == null) {
JPA_LOGGER.tracef("No classes to scan for annotations in jar '%s' (jars with classes '%s')", jarToScan, pu.getAnnotationIndex().keySet());
return new HashSet<Class<?>>();
}
if (annotationsToLookFor == null) {
throw JPA_LOGGER.nullVar("annotationsToLookFor");
}
if (annotationsToLookFor.size() == 0) {
throw JPA_LOGGER.emptyParameter("annotationsToLookFor");
}
Set<Class<?>> result = new HashSet<Class<?>>();
for (Class<? extends Annotation> annClass : annotationsToLookFor) {
DotName annotation = DotName.createSimple(annClass.getName());
List<AnnotationInstance> classesWithAnnotation = index.getAnnotations(annotation);
Set<Class<?>> classesForAnnotation = new HashSet<Class<?>>();
for (AnnotationInstance annotationInstance : classesWithAnnotation) {
// may generate bytecode with annotations placed on methods (see AS7-2559)
if (annotationInstance.target() instanceof ClassInfo) {
String className = annotationInstance.target().toString();
try {
JPA_LOGGER.tracef("getClassesInJar found class %s with annotation %s", className, annClass.getName());
Class<?> clazz = pu.cacheTempClassLoader().loadClass(className);
result.add(clazz);
classesForAnnotation.add(clazz);
} catch (ClassNotFoundException e) {
JPA_LOGGER.cannotLoadEntityClass(e, className);
} catch (NoClassDefFoundError e) {
JPA_LOGGER.cannotLoadEntityClass(e, className);
}
}
}
cacheClasses(pu, jarToScan, annClass, classesForAnnotation);
}
return result;
} else {
return getCachedClasses(pu, jarToScan, annotationsToLookFor);
}
}
use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class HibernateAnnotationScanner method getPackagesInJar.
@Override
public Set<Package> getPackagesInJar(URL jarToScan, Set<Class<? extends Annotation>> annotationsToLookFor) {
if (jarToScan == null) {
throw JPA_LOGGER.nullVar("jarToScan");
}
JPA_LOGGER.tracef("getPackagesInJar url=%s annotations=%s", jarToScan.getPath(), annotationsToLookFor);
Set<Class<?>> resultClasses = new HashSet<Class<?>>();
PersistenceUnitMetadata pu = PERSISTENCE_UNIT_METADATA_TLS.get();
if (pu == null) {
throw JPA_LOGGER.missingPersistenceUnitMetadata();
}
if (annotationsToLookFor.size() > 0) {
// Hibernate doesn't pass any annotations currently
resultClasses = getClassesInJar(jarToScan, annotationsToLookFor);
} else {
if (pu.getAnnotationIndex() != null) {
Index index = getJarFileIndex(jarToScan, pu);
if (index == null) {
JPA_LOGGER.tracef("No classes to scan for annotations in jar '%s' (jars with classes '%s')", jarToScan, pu.getAnnotationIndex().keySet());
return new HashSet<Package>();
}
Collection<ClassInfo> allClasses = index.getKnownClasses();
for (ClassInfo classInfo : allClasses) {
String className = classInfo.name().toString();
try {
resultClasses.add(pu.cacheTempClassLoader().loadClass(className));
} catch (ClassNotFoundException e) {
JPA_LOGGER.cannotLoadEntityClass(e, className);
} catch (NoClassDefFoundError e) {
JPA_LOGGER.cannotLoadEntityClass(e, className);
}
}
}
}
if (pu.getAnnotationIndex() != null || annotationsToLookFor.size() > 0) {
Map<String, Package> uniquePackages = new HashMap<String, Package>();
for (Class<?> classWithAnnotation : resultClasses) {
Package classPackage = classWithAnnotation.getPackage();
if (classPackage != null) {
JPA_LOGGER.tracef("getPackagesInJar found package %s", classPackage);
uniquePackages.put(classPackage.getName(), classPackage);
}
}
Set<Package> packages = new HashSet<Package>(uniquePackages.values());
cachePackages(pu, jarToScan, packages);
return new HashSet<Package>(packages);
} else {
return getCachedPackages(pu, jarToScan);
}
}
use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class PersistenceRefProcessor method getPersistenceUnitBindingSource.
private InjectionSource getPersistenceUnitBindingSource(final DeploymentUnit deploymentUnit, final String unitName) throws DeploymentUnitProcessingException {
final String searchName;
if (isEmpty(unitName)) {
searchName = null;
} else {
searchName = unitName;
}
final PersistenceUnitMetadata pu = PersistenceUnitSearch.resolvePersistenceUnitSupplier(deploymentUnit, searchName);
if (null == pu) {
throw new DeploymentUnitProcessingException(JpaLogger.ROOT_LOGGER.persistenceUnitNotFound(searchName, deploymentUnit));
}
String scopedPuName = pu.getScopedPersistenceUnitName();
ServiceName puServiceName = getPuServiceName(scopedPuName);
return new PersistenceUnitInjectionSource(puServiceName, deploymentUnit.getServiceRegistry(), EntityManagerFactory.class.getName(), pu);
}
use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class PersistenceUnitServiceHandler method setAnnotationIndexes.
/**
* Setup the annotation index map
*
* @param puHolder
* @param deploymentUnit
*/
private static void setAnnotationIndexes(final PersistenceUnitMetadataHolder puHolder, DeploymentUnit deploymentUnit) {
final Map<URL, Index> annotationIndexes = new HashMap<>();
do {
for (ResourceRoot root : DeploymentUtils.allResourceRoots(deploymentUnit)) {
final Index index = root.getAttachment(Attachments.ANNOTATION_INDEX);
if (index != null) {
try {
ROOT_LOGGER.tracef("adding '%s' to annotation index map", root.getRoot().toURL());
annotationIndexes.put(root.getRoot().toURL(), index);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}
// get annotation indexes for top level also
deploymentUnit = deploymentUnit.getParent();
} while (deploymentUnit != null);
for (PersistenceUnitMetadata pu : puHolder.getPersistenceUnits()) {
// hold onto the annotation index for Persistence Provider use during deployment
pu.setAnnotationIndex(annotationIndexes);
}
}
use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class JPAAnnotationProcessor method getBindingSource.
private InjectionSource getBindingSource(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, String injectionTypeName, final EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
PersistenceUnitMetadata pu = getPersistenceUnit(deploymentUnit, annotation, classDescription);
if (pu == null) {
return null;
}
String scopedPuName = pu.getScopedPersistenceUnitName();
ServiceName puServiceName = getPuServiceName(scopedPuName);
if (isPersistenceContext(annotation)) {
if (pu.getTransactionType() == PersistenceUnitTransactionType.RESOURCE_LOCAL) {
classDescription.setInvalid(JpaLogger.ROOT_LOGGER.cannotInjectResourceLocalEntityManager());
return null;
}
AnnotationValue pcType = annotation.value("type");
PersistenceContextType type = (pcType == null || PersistenceContextType.TRANSACTION.name().equals(pcType.asString())) ? PersistenceContextType.TRANSACTION : PersistenceContextType.EXTENDED;
AnnotationValue stType = annotation.value("synchronization");
SynchronizationType synchronizationType = (stType == null || SynchronizationType.SYNCHRONIZED.name().equals(stType.asString())) ? SynchronizationType.SYNCHRONIZED : SynchronizationType.UNSYNCHRONIZED;
Map<String, String> properties;
AnnotationValue value = annotation.value("properties");
AnnotationInstance[] props = value != null ? value.asNestedArray() : null;
if (props != null) {
properties = new HashMap<>();
for (int source = 0; source < props.length; source++) {
properties.put(props[source].value("name").asString(), props[source].value("value").asString());
}
} else {
properties = null;
}
// get deployment settings from top level du (jboss-all.xml is only parsed at the top level).
final JPADeploymentSettings jpaDeploymentSettings = DeploymentUtils.getTopDeploymentUnit(deploymentUnit).getAttachment(JpaAttachments.DEPLOYMENT_SETTINGS_KEY);
return new PersistenceContextInjectionSource(type, synchronizationType, properties, puServiceName, deploymentUnit.getServiceRegistry(), scopedPuName, injectionTypeName, pu, jpaDeploymentSettings);
} else {
return new PersistenceUnitInjectionSource(puServiceName, deploymentUnit.getServiceRegistry(), injectionTypeName, pu);
}
}
Aggregations