use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class SingleTableInheritanceIT method testRelationshipAbstractToSuperPrefetchingDisjoint.
@Test
public void testRelationshipAbstractToSuperPrefetchingDisjoint() {
context.performGenericQuery(new SQLTemplate(AbstractPerson.class, "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (2, 'AA', 'EE')"));
context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (2, 'AA', 2)"));
context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (3, 'BB', 2)"));
SelectQuery query = new SelectQuery(PersonNotes.class);
query.addPrefetch(PersonNotes.PERSON.disjoint());
query.addOrdering(PersonNotes.NOTES.asc());
List<PersonNotes> notes = context.performQuery(query);
assertEquals(2, notes.size());
final PersonNotes note = notes.get(0);
queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals("AA", note.getPerson().getName());
}
});
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class SingleTableInheritanceIT method testEmployeeAddress.
/**
* Tests that to-one relationship produces correct subclass.
*/
@Test
public void testEmployeeAddress() throws Exception {
createEmployeeAddressDataSet();
List<?> addresses = context.performQuery(new SelectQuery(Address.class));
assertEquals(1, addresses.size());
Address address = (Address) addresses.get(0);
assertSame(Employee.class, address.getToEmployee().getClass());
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class SingleTableInheritanceIT method testSelectInheritanceResolving.
@Test
public void testSelectInheritanceResolving() throws Exception {
createSelectDataSet();
SelectQuery query = new SelectQuery(AbstractPerson.class);
List<?> abstractPpl = context.performQuery(query);
assertEquals(6, abstractPpl.size());
assertEquals(1, countObjectOfClass(abstractPpl, CustomerRepresentative.class));
assertEquals(5, countObjectOfClass(abstractPpl, Employee.class));
assertEquals(2, countObjectOfClass(abstractPpl, Manager.class));
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class SingleTableInheritanceIT method testManagerAddress.
/**
* Tests that to-one relationship produces correct subclass.
*/
@Test
public void testManagerAddress() throws Exception {
createManagerAddressDataSet();
List<?> addresses = context.performQuery(new SelectQuery(Address.class));
assertEquals(1, addresses.size());
Address address = (Address) addresses.get(0);
Employee e = address.getToEmployee();
assertSame(Manager.class, e.getClass());
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class UUIDIT method testUUID.
@Test
public void testUUID() throws Exception {
UuidTestEntity test = context.newObject(UuidTestEntity.class);
UUID id = UUID.randomUUID();
test.setUuid(id);
context.commitChanges();
SelectQuery<UuidTestEntity> q = new SelectQuery<>(UuidTestEntity.class);
UuidTestEntity testRead = (UuidTestEntity) context.performQuery(q).get(0);
assertNotNull(testRead.getUuid());
assertEquals(id, testRead.getUuid());
test.setUuid(null);
context.commitChanges();
}
Aggregations