Search in sources :

Example 1 with DynamicTypeImpl

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());
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DynamicTypeImpl(org.eclipse.persistence.internal.dynamic.DynamicTypeImpl) Test(org.junit.Test)

Example 2 with DynamicTypeImpl

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;
}
Also used : Field(java.lang.reflect.Field) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DynamicPropertiesManager(org.eclipse.persistence.internal.dynamic.DynamicPropertiesManager) DynamicTypeImpl(org.eclipse.persistence.internal.dynamic.DynamicTypeImpl) ValidationException(org.eclipse.persistence.exceptions.ValidationException) IOException(java.io.IOException)

Example 3 with DynamicTypeImpl

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());
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DynamicTypeImpl(org.eclipse.persistence.internal.dynamic.DynamicTypeImpl) Test(org.junit.Test)

Example 4 with DynamicTypeImpl

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);
}
Also used : DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) DynamicTypeImpl(org.eclipse.persistence.internal.dynamic.DynamicTypeImpl) Test(org.junit.Test)

Example 5 with DynamicTypeImpl

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));
}
Also used : DynamicTypeImpl(org.eclipse.persistence.internal.dynamic.DynamicTypeImpl) Test(org.junit.Test)

Aggregations

DynamicTypeImpl (org.eclipse.persistence.internal.dynamic.DynamicTypeImpl)15 Test (org.junit.Test)12 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)8 DynamicEntity (org.eclipse.persistence.dynamic.DynamicEntity)5 EntityManager (jakarta.persistence.EntityManager)4 Field (java.lang.reflect.Field)3 DynamicPropertiesManager (org.eclipse.persistence.internal.dynamic.DynamicPropertiesManager)3 IOException (java.io.IOException)2 ValidationException (org.eclipse.persistence.exceptions.ValidationException)2 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)2 IdentityMapAccessor (org.eclipse.persistence.sessions.IdentityMapAccessor)2 Server (org.eclipse.persistence.sessions.server.Server)2 ArrayList (java.util.ArrayList)1 DynamicType (org.eclipse.persistence.dynamic.DynamicType)1 AggregateAttributeChangeListener (org.eclipse.persistence.internal.descriptors.changetracking.AggregateAttributeChangeListener)1 DynamicEntityImpl (org.eclipse.persistence.internal.dynamic.DynamicEntityImpl)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 AggregateObjectMapping (org.eclipse.persistence.mappings.AggregateObjectMapping)1 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)1 DatabasePlatform (org.eclipse.persistence.platform.database.DatabasePlatform)1