Search in sources :

Example 36 with SelectQuery

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());
        }
    });
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) SelectQuery(org.apache.cayenne.query.SelectQuery) PersonNotes(org.apache.cayenne.testdo.inheritance_people.PersonNotes) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) AbstractPerson(org.apache.cayenne.testdo.inheritance_people.AbstractPerson) Test(org.junit.Test)

Example 37 with SelectQuery

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());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Address(org.apache.cayenne.testdo.inheritance_people.Address) Test(org.junit.Test)

Example 38 with SelectQuery

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));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) CustomerRepresentative(org.apache.cayenne.testdo.inheritance_people.CustomerRepresentative) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) Test(org.junit.Test)

Example 39 with SelectQuery

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());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) Address(org.apache.cayenne.testdo.inheritance_people.Address) Test(org.junit.Test)

Example 40 with SelectQuery

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();
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UUID(java.util.UUID) UuidTestEntity(org.apache.cayenne.testdo.uuid.UuidTestEntity) Test(org.junit.Test)

Aggregations

SelectQuery (org.apache.cayenne.query.SelectQuery)360 Test (org.junit.Test)348 Artist (org.apache.cayenne.testdo.testmap.Artist)128 Painting (org.apache.cayenne.testdo.testmap.Painting)75 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)64 Expression (org.apache.cayenne.exp.Expression)47 List (java.util.List)43 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)26 ValueHolder (org.apache.cayenne.ValueHolder)21 ReturnTypesMap1 (org.apache.cayenne.testdo.return_types.ReturnTypesMap1)18 ArrayList (java.util.ArrayList)16 Date (java.util.Date)13 DataRow (org.apache.cayenne.DataRow)12 ObjectContext (org.apache.cayenne.ObjectContext)12 DbEntity (org.apache.cayenne.map.DbEntity)12 SQLTemplate (org.apache.cayenne.query.SQLTemplate)11 ROArtist (org.apache.cayenne.testdo.testmap.ROArtist)11 HashMap (java.util.HashMap)10 ObjectId (org.apache.cayenne.ObjectId)10 Query (org.apache.cayenne.query.Query)10