Search in sources :

Example 26 with JPADynamicHelper

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

the class UnaryTableSequencingTestSuite method setUp.

@BeforeClass
public static void setUp() {
    emf = DynamicTestHelper.createEMF(DYNAMIC_PERSISTENCE_NAME);
    helper = new JPADynamicHelper(emf);
    DynamicClassLoader dcl = helper.getDynamicClassLoader();
    UnaryTableSequence sequence = new UnaryTableSequence(SEQ_TABLE_NAME);
    sequence.setCounterFieldName("SEQ_VALUE");
    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, SEQ_TABLE_NAME, "SID");
    helper.addTypes(true, true, typeBuilder.getType());
}
Also used : DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) JPADynamicTypeBuilder(org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder) UnaryTableSequence(org.eclipse.persistence.sequencing.UnaryTableSequence) 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 27 with JPADynamicHelper

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

the class SimpleTypeTestSuite 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("SID");
    typeBuilder.addDirectMapping("id", int.class, "SID");
    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)

Example 28 with JPADynamicHelper

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

the class SimpleTypes_MultiTable 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");
    JPADynamicTypeBuilder typeBuilder = new JPADynamicTypeBuilder(simpleTypeA, null, "SIMPLE_TYPE_A", "SIMPLE_TYPE_B", "SIMPLE_TYPE_C");
    typeBuilder.setPrimaryKeyFields("SIMPLE_TYPE_A.SID");
    typeBuilder.addDirectMapping("id", int.class, "SIMPLE_TYPE_A.SID");
    typeBuilder.addDirectMapping("value1", String.class, "SIMPLE_TYPE_A.VAL_1");
    typeBuilder.addDirectMapping("value2", boolean.class, "SIMPLE_TYPE_B.VAL_2");
    typeBuilder.addDirectMapping("value3", String.class, "SIMPLE_TYPE_B.VAL_3");
    typeBuilder.addDirectMapping("value4", double.class, "SIMPLE_TYPE_C.VAL_4");
    typeBuilder.addDirectMapping("value5", String.class, "SIMPLE_TYPE_C.VAL_5");
    helper.addTypes(true, true, typeBuilder.getType());
}
Also used : DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) JPADynamicTypeBuilder(org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder) JPADynamicHelper(org.eclipse.persistence.jpa.dynamic.JPADynamicHelper) BeforeClass(org.junit.BeforeClass)

Example 29 with JPADynamicHelper

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

the class SimpleTypes_OneToMany 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 aTypeBuilder = new JPADynamicTypeBuilder(simpleTypeA, null, "SIMPLE_TYPE_A");
    aTypeBuilder.setPrimaryKeyFields("SID");
    Class<?> simpleTypeB = dcl.createDynamicClass("model.SimpleB");
    DynamicTypeBuilder bTypeBuilder = new JPADynamicTypeBuilder(simpleTypeB, null, "SIMPLE_TYPE_B");
    bTypeBuilder.setPrimaryKeyFields("SID");
    bTypeBuilder.addDirectMapping("id", int.class, "SID");
    bTypeBuilder.addDirectMapping("value1", String.class, "VAL_1");
    bTypeBuilder.addOneToOneMapping("a", aTypeBuilder.getType(), "A_FK");
    aTypeBuilder.addDirectMapping("id", int.class, "SID");
    aTypeBuilder.addDirectMapping("value1", String.class, "VAL_1");
    aTypeBuilder.addOneToManyMapping("b", bTypeBuilder.getType(), "A_FK");
    helper.addTypes(true, true, aTypeBuilder.getType(), bTypeBuilder.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 30 with JPADynamicHelper

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

the class EmployeeSparseMergeTestSuite method mergeSparseDynamicEntityWithFetchGroup.

@Test
public void mergeSparseDynamicEntityWithFetchGroup() {
    EntityManager em = emf.createEntityManager();
    JPADynamicHelper helper = new JPADynamicHelper(em);
    DynamicType employeeType = helper.getType("Employee");
    // Create a new 'sparse' Employee
    DynamicEntity sparseEmployee = employeeType.newDynamicEntity();
    // and manually set an EntityFetchGroup
    EntityFetchGroup efg = new EntityFetchGroup(new String[0]);
    ((FetchGroupTracker) sparseEmployee)._persistence_setFetchGroup(efg);
    sparseEmployee.set("id", minimumEmployeeId(em));
    /* pretend sparseEmployee is read in from sparse XML document:
          <employee>
              <id>nnn</id>
              <firstname>Mike</firstname>
              <lastname>Norman</lastname>
              <salary>12345</salary>
          </employee>
        */
    sparseEmployee.set("firstName", "Mike");
    sparseEmployee.set("lastName", "Norman");
    sparseEmployee.set("salary", 12345);
    em.getTransaction().begin();
    em.merge(sparseEmployee);
    em.getTransaction().commit();
    assertEquals("Incorrect # of UPDATE calls", 2, qTracker.getTotalSQLUPDATECalls());
}
Also used : EntityFetchGroup(org.eclipse.persistence.internal.queries.EntityFetchGroup) FetchGroupTracker(org.eclipse.persistence.queries.FetchGroupTracker) EntityManager(jakarta.persistence.EntityManager) DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) DynamicType(org.eclipse.persistence.dynamic.DynamicType) JPADynamicHelper(org.eclipse.persistence.jpa.dynamic.JPADynamicHelper) Test(org.junit.Test)

Aggregations

JPADynamicHelper (org.eclipse.persistence.jpa.dynamic.JPADynamicHelper)34 DynamicEntity (org.eclipse.persistence.dynamic.DynamicEntity)17 EntityManager (jakarta.persistence.EntityManager)16 DynamicClassLoader (org.eclipse.persistence.dynamic.DynamicClassLoader)15 BeforeClass (org.junit.BeforeClass)15 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)13 JPADynamicTypeBuilder (org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder)12 DynamicTypeBuilder (org.eclipse.persistence.dynamic.DynamicTypeBuilder)10 MyDynamicEntity (org.eclipse.persistence.testing.models.jpa.xml.advanced.dynamic.MyDynamicEntity)10 DynamicType (org.eclipse.persistence.dynamic.DynamicType)8 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)3 Query (jakarta.persistence.Query)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 DoesExistQuery (org.eclipse.persistence.queries.DoesExistQuery)2 TableSequence (org.eclipse.persistence.sequencing.TableSequence)2 Test (org.junit.Test)2 EntityNotFoundException (jakarta.persistence.EntityNotFoundException)1 EntityTransaction (jakarta.persistence.EntityTransaction)1