Search in sources :

Example 91 with SQLTemplate

use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.

the class CDOMany2OneIT method testMultipleToOneDeletion.

@Test
public void testMultipleToOneDeletion() throws Exception {
    // was a problem per CAY-901
    Painting p = context.newObject(Painting.class);
    p.setPaintingTitle("P1");
    Artist a = context.newObject(Artist.class);
    a.setArtistName("A1");
    Gallery g = context.newObject(Gallery.class);
    g.setGalleryName("G1");
    p.setToArtist(a);
    p.setToGallery(g);
    context.commitChanges();
    p.setToArtist(null);
    p.setToGallery(null);
    context.commitChanges();
    SQLTemplate q = new SQLTemplate(Painting.class, "SELECT * from PAINTING");
    q.setColumnNamesCapitalization(CapsStrategy.UPPER);
    q.setFetchingDataRows(true);
    Map<String, ?> row = (Map<String, ?>) Cayenne.objectForQuery(context, q);
    assertEquals("P1", row.get("PAINTING_TITLE"));
    assertEquals(null, row.get("ARTIST_ID"));
    assertEquals(null, row.get("GALLERY_ID"));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SQLTemplate(org.apache.cayenne.query.SQLTemplate) Gallery(org.apache.cayenne.testdo.testmap.Gallery) Map(java.util.Map) ROPainting(org.apache.cayenne.testdo.testmap.ROPainting) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 92 with SQLTemplate

use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.

the class SingleTableInheritanceIT method testRelationshipAbstractFromSuperPrefetchingJoint.

@Test
public void testRelationshipAbstractFromSuperPrefetchingJoint() {
    context.performGenericQuery(new SQLTemplate(AbstractPerson.class, "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (3, 'AA', 'EE')"));
    context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (3, 'AA', 3)"));
    context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (4, 'BB', 3)"));
    SelectQuery query = new SelectQuery(AbstractPerson.class);
    query.addPrefetch(AbstractPerson.NOTES.joint());
    final AbstractPerson person = (AbstractPerson) Cayenne.objectForQuery(context, query);
    assertTrue(person instanceof Employee);
    queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(2, person.getNotes().size());
            String[] names = new String[2];
            names[0] = person.getNotes().get(0).getNotes();
            names[1] = person.getNotes().get(1).getNotes();
            List<String> nameSet = Arrays.asList(names);
            assertTrue(nameSet.contains("AA"));
            assertTrue(nameSet.contains("BB"));
        }
    });
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) SelectQuery(org.apache.cayenne.query.SelectQuery) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) PersonNotes(org.apache.cayenne.testdo.inheritance_people.PersonNotes) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) List(java.util.List) AbstractPerson(org.apache.cayenne.testdo.inheritance_people.AbstractPerson) Test(org.junit.Test)

Example 93 with SQLTemplate

use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.

the class SingleTableInheritanceIT method testRelationshipToAbstractSuper.

@Test
public void testRelationshipToAbstractSuper() {
    context.performGenericQuery(new SQLTemplate(AbstractPerson.class, "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (1, 'AA', 'EE')"));
    context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (1, 'AA', 1)"));
    PersonNotes note = Cayenne.objectForPK(context, PersonNotes.class, 1);
    assertNotNull(note);
    assertNotNull(note.getPerson());
    assertTrue(note.getPerson() instanceof Employee);
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) PersonNotes(org.apache.cayenne.testdo.inheritance_people.PersonNotes) AbstractPerson(org.apache.cayenne.testdo.inheritance_people.AbstractPerson) Test(org.junit.Test)

Example 94 with SQLTemplate

use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.

the class SingleTableInheritanceIT method testRelationshipAbstractToSuperPrefetchingJoint.

@Test
public void testRelationshipAbstractToSuperPrefetchingJoint() {
    context.performGenericQuery(new SQLTemplate(AbstractPerson.class, "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (3, 'AA', 'EE')"));
    context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (3, 'AA', 3)"));
    SelectQuery query = new SelectQuery(PersonNotes.class);
    query.addPrefetch(PersonNotes.PERSON.joint());
    final PersonNotes note = (PersonNotes) Cayenne.objectForQuery(context, query);
    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 95 with SQLTemplate

use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.

the class SingleTableInheritanceIT method testRelationshipAbstractFromSuperPrefetchingDisjoint.

@Test
public void testRelationshipAbstractFromSuperPrefetchingDisjoint() {
    context.performGenericQuery(new SQLTemplate(AbstractPerson.class, "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (3, 'AA', 'EE')"));
    context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (3, 'AA', 3)"));
    context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (4, 'BB', 3)"));
    SelectQuery query = new SelectQuery(AbstractPerson.class);
    query.addPrefetch(AbstractPerson.NOTES.disjoint());
    final AbstractPerson person = (AbstractPerson) Cayenne.objectForQuery(context, query);
    assertTrue(person instanceof Employee);
    queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(2, person.getNotes().size());
            String[] names = new String[2];
            names[0] = person.getNotes().get(0).getNotes();
            names[1] = person.getNotes().get(1).getNotes();
            List<String> nameSet = Arrays.asList(names);
            assertTrue(nameSet.contains("AA"));
            assertTrue(nameSet.contains("BB"));
        }
    });
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) SelectQuery(org.apache.cayenne.query.SelectQuery) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) PersonNotes(org.apache.cayenne.testdo.inheritance_people.PersonNotes) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) List(java.util.List) AbstractPerson(org.apache.cayenne.testdo.inheritance_people.AbstractPerson) Test(org.junit.Test)

Aggregations

SQLTemplate (org.apache.cayenne.query.SQLTemplate)118 Test (org.junit.Test)108 Artist (org.apache.cayenne.testdo.testmap.Artist)27 DataRow (org.apache.cayenne.DataRow)18 HashMap (java.util.HashMap)16 MockOperationObserver (org.apache.cayenne.access.MockOperationObserver)14 Query (org.apache.cayenne.query.Query)14 SelectQuery (org.apache.cayenne.query.SelectQuery)11 Painting (org.apache.cayenne.testdo.testmap.Painting)11 List (java.util.List)8 Connection (java.sql.Connection)7 SQLAction (org.apache.cayenne.query.SQLAction)7 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)6 Map (java.util.Map)5 OperationObserver (org.apache.cayenne.access.OperationObserver)5 DataMap (org.apache.cayenne.map.DataMap)5 AbstractPerson (org.apache.cayenne.testdo.inheritance_people.AbstractPerson)5 PersonNotes (org.apache.cayenne.testdo.inheritance_people.PersonNotes)5 Date (java.sql.Date)4 FrontBaseAdapter (org.apache.cayenne.dba.frontbase.FrontBaseAdapter)4