use of org.eclipse.persistence.dynamic.DynamicType in project eclipselink by eclipse-ee4j.
the class SimpleTypes_OneToOne method createSimpleAwithSimpleB.
@Test
public void createSimpleAwithSimpleB() {
DynamicType simpleTypeA = dynamicHelper.getType("SimpleA");
Assert.assertNotNull(simpleTypeA);
DynamicType simpleTypeB = dynamicHelper.getType("SimpleB");
Assert.assertNotNull(simpleTypeB);
Assert.assertNotNull(session.getDescriptorForAlias("SimpleB"));
DynamicEntity simpleInstanceB = simpleTypeB.newDynamicEntity();
simpleInstanceB.set("id", 2);
simpleInstanceB.set("value1", "B2");
DynamicEntity simpleInstanceA = simpleTypeA.newDynamicEntity();
simpleInstanceA.set("id", 2);
simpleInstanceA.set("value1", "A2");
simpleInstanceA.set("b", simpleInstanceB);
UnitOfWork uow = session.acquireUnitOfWork();
uow.registerNewObject(simpleInstanceA);
uow.registerNewObject(simpleInstanceB);
uow.commit();
assertEquals(2, qTracker.getTotalSQLINSERTCalls());
// There is no reason for a shallow insert and an update in this mapping
assertEquals("No update expected for new objects with 1:1", 0, qTracker.getTotalSQLUPDATECalls());
ReportQuery countQuery = dynamicHelper.newReportQuery("SimpleB", new ExpressionBuilder());
countQuery.addCount();
countQuery.setShouldReturnSingleValue(true);
Assert.assertEquals(1, ((Number) session.executeQuery(countQuery)).intValue());
countQuery = dynamicHelper.newReportQuery("SimpleA", new ExpressionBuilder());
countQuery.addCount();
countQuery.setShouldReturnSingleValue(true);
Assert.assertEquals(1, ((Number) session.executeQuery(countQuery)).intValue());
}
use of org.eclipse.persistence.dynamic.DynamicType in project eclipselink by eclipse-ee4j.
the class EmployeeProjectTestSuite method readAll.
@SuppressWarnings("unchecked")
@Test
public void readAll() throws Exception {
createNewInstance();
DynamicType type = dynamicHelper.getType("Employee");
List<DynamicEntity> allObjects = session.readAllObjects(type.getJavaClass());
assertEquals(1, allObjects.size());
}
use of org.eclipse.persistence.dynamic.DynamicType in project eclipselink by eclipse-ee4j.
the class DynamicHelperTestSuite method setUp.
@BeforeClass
public static void setUp() {
session = createSession();
dynamicHelper = new DynamicHelper(session);
DynamicClassLoader dcl = dynamicHelper.getDynamicClassLoader();
Class<?> empClass = dcl.createDynamicClass(EMPLOYEE_CLASSNAME);
DynamicTypeBuilder typeBuilder = new DynamicTypeBuilder(empClass, null, "D_EMPLOYEE");
typeBuilder.setPrimaryKeyFields("EMP_ID");
typeBuilder.addDirectMapping("id", int.class, "EMP_ID");
typeBuilder.addDirectMapping("firstName", String.class, "F_NAME");
typeBuilder.addDirectMapping("lastName", String.class, "L_NAME");
dynamicHelper.addTypes(true, false, typeBuilder.getType());
DynamicType empType = new DynamicHelper(session).getType("Employee");
assertNotNull("No type found for Employee", empType);
// Populate table with a single Employee
DynamicEntity e1 = empType.newDynamicEntity();
e1.set("id", 1);
e1.set("firstName", "Mike");
e1.set("lastName", "Norman");
UnitOfWork uow = session.acquireUnitOfWork();
uow.registerNewObject(e1);
uow.commit();
session.getIdentityMapAccessor().initializeAllIdentityMaps();
}
use of org.eclipse.persistence.dynamic.DynamicType in project eclipselink by eclipse-ee4j.
the class EntityTypeFromScratch method entityTypeFromDescriptor.
@Test
public void entityTypeFromDescriptor() throws Exception {
DynamicType entityType = buildMyEntityType();
assertEquals(MyEntity.class, entityType.getJavaClass());
DatabaseSession session = createSession();
session.login();
session.addDescriptor(entityType.getDescriptor());
new SchemaManager(session).replaceDefaultTables();
DynamicEntity entity = entityType.newDynamicEntity();
entity.set("id", 1);
entity.set("name", "Name");
session.insertObject(entity);
session.logout();
}
use of org.eclipse.persistence.dynamic.DynamicType in project eclipselink by eclipse-ee4j.
the class SimpleTypes_ManyToMany method verifyConfig.
@Test
public void verifyConfig() throws Exception {
ClassDescriptor descriptorA = helper.getSession().getClassDescriptorForAlias("SimpleA");
assertNotNull("No descriptor found for alias='SimpleA'", descriptorA);
DynamicType simpleTypeA = helper.getType("SimpleA");
assertNotNull("'SimpleA' EntityType not found", simpleTypeA);
assertEquals(descriptorA, simpleTypeA.getDescriptor());
DirectToFieldMapping a_id = (DirectToFieldMapping) descriptorA.getMappingForAttributeName("id");
assertEquals(int.class, a_id.getAttributeClassification());
DirectToFieldMapping a_value1 = (DirectToFieldMapping) descriptorA.getMappingForAttributeName("value1");
assertEquals(String.class, a_value1.getAttributeClassification());
ClassDescriptor descriptorB = helper.getSession().getClassDescriptorForAlias("SimpleB");
assertNotNull("No descriptor found for alias='SimpleB'", descriptorB);
DynamicType simpleTypeB = helper.getType("SimpleB");
assertNotNull("'SimpleB' EntityType not found", simpleTypeB);
assertEquals(descriptorB, simpleTypeB.getDescriptor());
DirectToFieldMapping b_id = (DirectToFieldMapping) descriptorB.getMappingForAttributeName("id");
assertEquals(int.class, b_id.getAttributeClassification());
DirectToFieldMapping b_value1 = (DirectToFieldMapping) descriptorB.getMappingForAttributeName("value1");
assertEquals(String.class, b_value1.getAttributeClassification());
ManyToManyMapping a_b = (ManyToManyMapping) descriptorA.getMappingForAttributeName("b");
assertEquals(descriptorB, a_b.getReferenceDescriptor());
}
Aggregations