Search in sources :

Example 6 with SQLTemplate

use of org.apache.cayenne.query.SQLTemplate 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 7 with SQLTemplate

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

the class SchemaUpdateStrategyIT method testNoStandardSchema.

@Test
public void testNoStandardSchema() throws Exception {
    String template = "SELECT #result('ARTIST_ID' 'int') FROM ARTIST ORDER BY ARTIST_ID";
    SQLTemplate query = new SQLTemplate(Object.class, template);
    MockOperationObserver observer = new MockOperationObserver();
    setStrategy(TstSchemaUpdateStrategy.class);
    node.performQueries(Collections.singletonList((Query) query), observer);
    assertTrue(node.getSchemaUpdateStrategy() instanceof TstSchemaUpdateStrategy);
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Query(org.apache.cayenne.query.Query) MockOperationObserver(org.apache.cayenne.access.MockOperationObserver) Test(org.junit.Test)

Example 8 with SQLTemplate

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

the class SchemaUpdateStrategyIT method testCreateIfNoSchemaStrategy.

@Test
public void testCreateIfNoSchemaStrategy() throws Exception {
    setStrategy(CreateIfNoSchemaStrategy.class);
    String template = "SELECT #result('id' 'int') FROM SUS1";
    SQLTemplate query = new SQLTemplate(Object.class, template);
    OperationObserver observer = new MockOperationObserver();
    node.performQueries(Collections.singletonList((Query) query), observer);
    Map<String, Boolean> nameTables = tablesMap();
    assertTrue(nameTables.get("SUS1"));
    assertEquals(2, existingTables().size());
    node.performQueries(Collections.singletonList(query), observer);
    assertEquals(2, existingTables().size());
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Query(org.apache.cayenne.query.Query) MockOperationObserver(org.apache.cayenne.access.MockOperationObserver) OperationObserver(org.apache.cayenne.access.OperationObserver) MockOperationObserver(org.apache.cayenne.access.MockOperationObserver) Test(org.junit.Test)

Example 9 with SQLTemplate

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

the class ThrowOnPartialOrCreateSchemaStrategyIT method testMixedStrategyWithOneTable.

@Test
public void testMixedStrategyWithOneTable() throws Exception {
    createOneTable("SUS1");
    setStrategy(ThrowOnPartialOrCreateSchemaStrategy.class);
    String template = "SELECT #result('ARTIST_ID' 'int') FROM ARTIST ORDER BY ARTIST_ID";
    SQLTemplate query = new SQLTemplate(Object.class, template);
    try {
        node.performQueries(Collections.singletonList(query), mock(OperationObserver.class));
        assertEquals(1, existingTables().size());
        fail("Must have thrown on partial schema");
    } catch (CayenneRuntimeException e) {
    // expected
    }
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) OperationObserver(org.apache.cayenne.access.OperationObserver) Test(org.junit.Test)

Example 10 with SQLTemplate

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

the class ThrowOnPartialOrCreateSchemaStrategyIT method testMixedStrategyTableNoExist.

@Test
public void testMixedStrategyTableNoExist() throws Exception {
    String template = "SELECT #result('id' 'int') FROM SUS1";
    SQLTemplate query = new SQLTemplate(Object.class, template);
    setStrategy(ThrowOnPartialOrCreateSchemaStrategy.class);
    node.performQueries(Collections.singletonList(query), mock(OperationObserver.class));
    Map<String, Boolean> nameTables = tablesMap();
    assertTrue(nameTables.get("SUS1"));
    assertEquals(2, existingTables().size());
    node.performQueries(Collections.singletonList(query), mock(OperationObserver.class));
    assertEquals(2, existingTables().size());
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) OperationObserver(org.apache.cayenne.access.OperationObserver) 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