use of org.eclipse.persistence.internal.dynamic.DynamicTypeImpl in project eclipselink by eclipse-ee4j.
the class SimpleTypeTestSuite method verifyConfig.
@Test
public void verifyConfig() throws Exception {
ClassDescriptor descriptor = session.getClassDescriptorForAlias("Simple");
assertNotNull("No descriptor found for alias='Simple'", descriptor);
DynamicTypeImpl simpleType = (DynamicTypeImpl) dynamicHelper.getType("Simple");
assertNotNull("'Simple' EntityType not found", simpleType);
assertEquals(1 + descriptor.getPrimaryKeyFields().size(), simpleType.getMappingsRequiringInitialization().size());
assertEquals(descriptor, simpleType.getDescriptor());
}
use of org.eclipse.persistence.internal.dynamic.DynamicTypeImpl in project eclipselink by eclipse-ee4j.
the class DynamicTypeBuilder method createType.
/**
* Create EntityType for a descriptor including the creation of a new
* dynamic type. This method needs to handle inheritance where the parent
* type needs to be defined before this type.
*/
private static DynamicType createType(DynamicClassLoader dcl, ClassDescriptor descriptor, Project project) {
Class<?> javaClass = null;
try {
javaClass = dcl.loadClass(descriptor.getJavaClassName());
} catch (ClassNotFoundException e) {
}
if (javaClass != null) {
descriptor.setJavaClass(javaClass);
}
DynamicType parent = null;
if (descriptor.hasInheritance() && descriptor.getInheritancePolicy().getParentClassName() != null) {
ClassDescriptor parentDesc = null;
for (Iterator<?> i = project.getOrderedDescriptors().iterator(); parentDesc == null && i.hasNext(); ) {
ClassDescriptor d = (ClassDescriptor) i.next();
if (d.getJavaClassName().equals(descriptor.getInheritancePolicy().getParentClassName())) {
parentDesc = d;
}
}
if (parentDesc == null) {
throw ValidationException.missingDescriptor(descriptor.getInheritancePolicy().getParentClassName());
}
parent = DynamicHelper.getType(parentDesc);
if (parent == null) {
parent = createType(dcl, parentDesc, project);
}
}
DynamicType type = DynamicHelper.getType(descriptor);
if (type == null) {
type = new DynamicTypeBuilder(dcl, descriptor, parent).getType();
}
// JAXB generates some classes that do not conform to DynamicEntity interface - ignore
if (javaClass != null && DynamicEntity.class.isAssignableFrom(javaClass)) {
try {
Field dpmField = javaClass.getField(DynamicPropertiesManager.PROPERTIES_MANAGER_FIELD);
DynamicPropertiesManager dpm = (DynamicPropertiesManager) dpmField.get(null);
dpm.setType(type);
((DynamicTypeImpl) type).setDynamicPropertiesManager(dpm);
} catch (Exception e) {
// this is bad! Without the dpmField, not much to do but die :-( ...
e.printStackTrace();
return null;
}
}
return type;
}
use of org.eclipse.persistence.internal.dynamic.DynamicTypeImpl in project eclipselink by eclipse-ee4j.
the class SimpleTypeTestSuite method verifyConfig.
@Test
public void verifyConfig() throws Exception {
ClassDescriptor descriptor = helper.getSession().getClassDescriptorForAlias("Simple");
assertNotNull("No descriptor found for alias='Simple'", descriptor);
DynamicTypeImpl simpleTypeImpl = (DynamicTypeImpl) simpleType;
assertNotNull("'Simple' EntityType not found", simpleTypeImpl);
assertEquals(1 + descriptor.getPrimaryKeyFields().size(), simpleTypeImpl.getMappingsRequiringInitialization().size());
assertEquals(descriptor, simpleTypeImpl.getDescriptor());
}
use of org.eclipse.persistence.internal.dynamic.DynamicTypeImpl in project eclipselink by eclipse-ee4j.
the class SimpleTypeTestSuite method verifyDefaultValuesFromDescriptor.
@Test
public void verifyDefaultValuesFromDescriptor() throws Exception {
DynamicTypeImpl simpleTypeImpl = (DynamicTypeImpl) simpleType;
assertNotNull(simpleTypeImpl);
DynamicEntity simpleInstance = (DynamicEntity) simpleTypeImpl.getDescriptor().getObjectBuilder().buildNewInstance();
assertDefaultValues(simpleInstance);
}
use of org.eclipse.persistence.internal.dynamic.DynamicTypeImpl in project eclipselink by eclipse-ee4j.
the class SimpleTypes_AggregateObject method verifyProperties.
@Test
public void verifyProperties() {
DynamicTypeImpl simpleTypeA = (DynamicTypeImpl) helper.getType("SimpleA");
assertNotNull(simpleTypeA);
assertEquals(4, simpleTypeA.getNumberOfProperties());
assertEquals("id", simpleTypeA.getPropertiesNames().get(0));
assertEquals("value1", simpleTypeA.getPropertiesNames().get(1));
assertEquals("b", simpleTypeA.getPropertiesNames().get(2));
assertEquals("c", simpleTypeA.getPropertiesNames().get(3));
}
Aggregations