Search in sources :

Example 1 with JPADynamicTypeBuilder

use of org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder in project eclipselink by eclipse-ee4j.

the class MetadataProject method createDynamicType.

/**
 * INTERNAL:
 * Create the dynamic types using JPA metadata processed descriptors. Called
 * at deploy time after all metadata processing has completed.
 */
protected void createDynamicType(MetadataDescriptor descriptor, Map<String, DynamicType> dynamicTypes, DynamicClassLoader dcl) {
    // Build the dynamic class only if we have not already done so.
    if (!dynamicTypes.containsKey(descriptor.getJavaClassName())) {
        JPADynamicTypeBuilder typeBuilder = null;
        if (descriptor.isInheritanceSubclass()) {
            // Get the parent descriptor
            MetadataDescriptor parentDescriptor = descriptor.getInheritanceParentDescriptor();
            // Recursively call up the parents.
            createDynamicType(parentDescriptor, dynamicTypes, dcl);
            // Create the dynamic type using the parent type.
            typeBuilder = new JPADynamicTypeBuilder(dcl, descriptor.getClassDescriptor(), dynamicTypes.get(parentDescriptor.getJavaClassName()));
        } else {
            // Create the dynamic type
            typeBuilder = new JPADynamicTypeBuilder(dcl, descriptor.getClassDescriptor(), null);
        }
        // Store the type builder by java class name.
        dynamicTypes.put(descriptor.getJavaClassName(), typeBuilder.getType());
    }
}
Also used : JPADynamicTypeBuilder(org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder)

Example 2 with JPADynamicTypeBuilder

use of org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder in project eclipselink by eclipse-ee4j.

the class DynamicEmployeeSystem method buildProject.

public static DynamicEmployeeSystem buildProject(DynamicHelper dynamicHelper) {
    DynamicClassLoader dcl = dynamicHelper.getDynamicClassLoader();
    Class<?> employeeClass = dcl.createDynamicClass(PACKAGE_PREFIX + ".Employee");
    Class<?> addressClass = dcl.createDynamicClass(PACKAGE_PREFIX + ".Address");
    Class<?> phoneClass = dcl.createDynamicClass(PACKAGE_PREFIX + ".PhoneNumber");
    Class<?> periodClass = dcl.createDynamicClass(PACKAGE_PREFIX + ".EmploymentPeriod");
    Class<?> projectClass = dcl.createDynamicClass(PACKAGE_PREFIX + ".Project");
    JPADynamicTypeBuilder employee = new JPADynamicTypeBuilder(employeeClass, null, "D_EMPLOYEE", "D_SALARY");
    JPADynamicTypeBuilder address = new JPADynamicTypeBuilder(addressClass, null, "D_ADDRESS");
    JPADynamicTypeBuilder phone = new JPADynamicTypeBuilder(phoneClass, null, "D_PHONE");
    JPADynamicTypeBuilder period = new JPADynamicTypeBuilder(periodClass, null);
    JPADynamicTypeBuilder project = new JPADynamicTypeBuilder(projectClass, null, "D_PROJECT");
    configureAddress(address);
    configureEmployee(employee, address, phone, period, project);
    configurePhone(phone, employee);
    configurePeriod(period);
    configureProject(project, employee);
    employee.addManyToManyMapping("projects", project.getType(), "D_PROJ_EMP");
    dynamicHelper.addTypes(true, true, employee.getType(), address.getType(), phone.getType(), period.getType(), project.getType());
    return new DynamicEmployeeSystem();
}
Also used : DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) JPADynamicTypeBuilder(org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder)

Example 3 with JPADynamicTypeBuilder

use of org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder in project eclipselink by eclipse-ee4j.

the class TableSequencingTestSuite method setUp.

@BeforeClass
public static void setUp() {
    emf = DynamicTestHelper.createEMF(DYNAMIC_PERSISTENCE_NAME);
    helper = new JPADynamicHelper(emf);
    DynamicClassLoader dcl = helper.getDynamicClassLoader();
    TableSequence sequence = new TableSequence();
    sequence.setTableName("TEST_SEQ");
    sequence.setCounterFieldName("SEQ_VALUE");
    sequence.setNameFieldName("SEQ_NAME");
    sequence.setPreallocationSize(5);
    helper.getSession().getProject().getLogin().setDefaultSequence(sequence);
    sequence.onConnect(helper.getSession().getPlatform());
    Class<?> javaType = dcl.createDynamicClass("model.sequencing." + ENTITY_TYPE);
    DynamicTypeBuilder typeBuilder = new JPADynamicTypeBuilder(javaType, null, TABLE_NAME);
    typeBuilder.setPrimaryKeyFields("SID");
    typeBuilder.addDirectMapping("id", int.class, "SID");
    typeBuilder.addDirectMapping("value1", String.class, "VAL_1");
    typeBuilder.configureSequencing(sequence, ENTITY_TYPE + "_SEQ", "SID");
    helper.addTypes(true, true, typeBuilder.getType());
}
Also used : DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) JPADynamicTypeBuilder(org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder) JPADynamicTypeBuilder(org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder) DynamicTypeBuilder(org.eclipse.persistence.dynamic.DynamicTypeBuilder) JPADynamicHelper(org.eclipse.persistence.jpa.dynamic.JPADynamicHelper) TableSequence(org.eclipse.persistence.sequencing.TableSequence) BeforeClass(org.junit.BeforeClass)

Example 4 with JPADynamicTypeBuilder

use of org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder in project eclipselink by eclipse-ee4j.

the class SimpleTypes_ManyToMany method setUp.

@BeforeClass
public static void setUp() {
    emf = DynamicTestHelper.createEMF(DYNAMIC_PERSISTENCE_NAME);
    helper = new JPADynamicHelper(emf);
    DynamicClassLoader dcl = helper.getDynamicClassLoader();
    Class<?> simpleTypeA = dcl.createDynamicClass("model.SimpleA");
    DynamicTypeBuilder aFactory = new JPADynamicTypeBuilder(simpleTypeA, null, "SIMPLE_TYPE_A");
    aFactory.setPrimaryKeyFields("SID");
    Class<?> simpleTypeB = dcl.createDynamicClass("model.SimpleB");
    DynamicTypeBuilder bFactory = new JPADynamicTypeBuilder(simpleTypeB, null, "SIMPLE_TYPE_B");
    bFactory.setPrimaryKeyFields("SID");
    bFactory.addDirectMapping("id", int.class, "SID");
    bFactory.addDirectMapping("value1", String.class, "VAL_1");
    bFactory.addOneToOneMapping("a", aFactory.getType(), "A_FK");
    aFactory.addDirectMapping("id", int.class, "SID");
    aFactory.addDirectMapping("value1", String.class, "VAL_1");
    aFactory.addManyToManyMapping("b", bFactory.getType(), "SIMPLE_A_B");
    helper.addTypes(true, true, aFactory.getType(), bFactory.getType());
}
Also used : DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) JPADynamicTypeBuilder(org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder) JPADynamicTypeBuilder(org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder) DynamicTypeBuilder(org.eclipse.persistence.dynamic.DynamicTypeBuilder) JPADynamicHelper(org.eclipse.persistence.jpa.dynamic.JPADynamicHelper) BeforeClass(org.junit.BeforeClass)

Example 5 with JPADynamicTypeBuilder

use of org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder in project eclipselink by eclipse-ee4j.

the class SimpleTypeCompositeKeyTestSuite method setUp.

@BeforeClass
public static void setUp() throws Exception {
    emf = DynamicTestHelper.createEMF(DYNAMIC_PERSISTENCE_NAME);
    helper = new JPADynamicHelper(emf);
    DynamicClassLoader dcl = helper.getDynamicClassLoader();
    Class<?> javaType = dcl.createDynamicClass("model.Simple");
    DynamicTypeBuilder typeBuilder = new JPADynamicTypeBuilder(javaType, null, "SIMPLE_TYPE");
    typeBuilder.setPrimaryKeyFields("SID1", "SID2");
    typeBuilder.addDirectMapping("id1", int.class, "SID1");
    typeBuilder.addDirectMapping("id2", int.class, "SID2");
    typeBuilder.addDirectMapping("value1", String.class, "VAL_1");
    typeBuilder.addDirectMapping("value2", boolean.class, "VAL_2");
    typeBuilder.addDirectMapping("value3", Calendar.class, "VAL_3");
    typeBuilder.addDirectMapping("value4", Character.class, "VAL_4");
    helper.addTypes(true, true, typeBuilder.getType());
    simpleType = helper.getType("Simple");
}
Also used : DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) JPADynamicTypeBuilder(org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder) JPADynamicTypeBuilder(org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder) DynamicTypeBuilder(org.eclipse.persistence.dynamic.DynamicTypeBuilder) JPADynamicHelper(org.eclipse.persistence.jpa.dynamic.JPADynamicHelper) BeforeClass(org.junit.BeforeClass)

Aggregations

JPADynamicTypeBuilder (org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder)14 DynamicClassLoader (org.eclipse.persistence.dynamic.DynamicClassLoader)13 JPADynamicHelper (org.eclipse.persistence.jpa.dynamic.JPADynamicHelper)12 BeforeClass (org.junit.BeforeClass)11 DynamicTypeBuilder (org.eclipse.persistence.dynamic.DynamicTypeBuilder)10 TableSequence (org.eclipse.persistence.sequencing.TableSequence)2 EntityTransaction (jakarta.persistence.EntityTransaction)1 RollbackException (jakarta.persistence.RollbackException)1 DynamicEntity (org.eclipse.persistence.dynamic.DynamicEntity)1 DynamicHelper (org.eclipse.persistence.dynamic.DynamicHelper)1 DynamicType (org.eclipse.persistence.dynamic.DynamicType)1 SessionLog (org.eclipse.persistence.logging.SessionLog)1 DatabasePlatform (org.eclipse.persistence.platform.database.DatabasePlatform)1 NativeSequence (org.eclipse.persistence.sequencing.NativeSequence)1 UnaryTableSequence (org.eclipse.persistence.sequencing.UnaryTableSequence)1 Session (org.eclipse.persistence.sessions.Session)1 Test (org.junit.Test)1