use of org.eclipse.persistence.internal.jpa.metamodel.proxy.ListAttributeProxyImpl in project eclipselink by eclipse-ee4j.
the class EntityManagerSetupImpl method preInitializeCanonicalMetamodel.
/**
* INTERNAL:
* First phase of canonical metamodel initialization. For each class the metamodel is aware of, check
* for a canonical metamodel class and initialize each attribute in it with a proxy that can cause the
* rest of the metamodel population. Attributes are found reflectively rather than through the metamodel
* to avoid having to further initialize the metamodel.
*/
public void preInitializeCanonicalMetamodel(EntityManagerFactoryImpl factory) {
// 338837: verify that the collection is not empty - this would mean entities did not make it into the search path
if (null == metaModel.getManagedTypes() || metaModel.getManagedTypes().isEmpty()) {
getSession().log(SessionLog.FINER, SessionLog.METAMODEL, "metamodel_type_collection_empty");
}
for (ManagedType manType : metaModel.getManagedTypes()) {
boolean classInitialized = false;
String className = MetadataHelper.getQualifiedCanonicalName(((ManagedTypeImpl) manType).getJavaTypeName(), getSession());
try {
Class<?> clazz = this.getSession().getDatasourcePlatform().convertObject(className, ClassConstants.CLASS);
classInitialized = true;
this.getSession().log(SessionLog.FINER, SessionLog.METAMODEL, "metamodel_canonical_model_class_found", className);
Field[] fields = null;
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
fields = AccessController.doPrivileged(new PrivilegedGetDeclaredFields(clazz));
} else {
fields = PrivilegedAccessHelper.getDeclaredFields(clazz);
}
for (Field attribute : fields) {
if (Attribute.class.isAssignableFrom(attribute.getType())) {
Object assignedAttribute = null;
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
assignedAttribute = AccessController.doPrivileged(new PrivilegedGetValueFromField(attribute, null));
} else {
assignedAttribute = PrivilegedAccessHelper.getValueFromField(attribute, null);
}
AttributeProxyImpl proxy = null;
if (assignedAttribute == null) {
if (SingularAttribute.class.isAssignableFrom(attribute.getType())) {
proxy = new SingularAttributeProxyImpl();
} else if (MapAttribute.class.isAssignableFrom(attribute.getType())) {
proxy = new MapAttributeProxyImpl();
} else if (SetAttribute.class.isAssignableFrom(attribute.getType())) {
proxy = new SetAttributeProxyImpl();
} else if (ListAttribute.class.isAssignableFrom(attribute.getType())) {
proxy = new ListAttributeProxyImpl();
} else if (CollectionAttribute.class.isAssignableFrom(attribute.getType())) {
proxy = new CollectionAttributeProxyImpl();
}
if (proxy != null) {
attribute.setAccessible(true);
attribute.set(null, proxy);
}
} else if (assignedAttribute instanceof AttributeProxyImpl) {
proxy = (AttributeProxyImpl) assignedAttribute;
}
if (proxy != null) {
proxy.addFactory(factory);
}
}
}
} catch (PrivilegedActionException pae) {
getSession().logThrowable(SessionLog.FINEST, SessionLog.METAMODEL, pae);
} catch (IllegalAccessException iae) {
getSession().logThrowable(SessionLog.FINEST, SessionLog.METAMODEL, iae);
} catch (ConversionException ce) {
}
if (!classInitialized) {
getSession().log(SessionLog.FINER, SessionLog.METAMODEL, "metamodel_canonical_model_class_not_found", className);
}
}
}
Aggregations