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());
}
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");
}
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());
}
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());
}
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());
}
Aggregations