Search in sources :

Example 6 with MockOperationObserver

use of org.apache.cayenne.access.MockOperationObserver in project cayenne by apache.

the class ThrowOnPartialSchemaStrategyIT method testThrowOnPartialStrategyTableNoExist.

@Test
public void testThrowOnPartialStrategyTableNoExist() 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(ThrowOnPartialSchemaStrategy.class);
    try {
        node.performQueries(Collections.singletonList((Query) query), observer);
    } catch (CayenneRuntimeException e) {
        assertNotNull(e);
    }
    try {
        node.performQueries(Collections.singletonList((Query) query), observer);
    } catch (CayenneRuntimeException e) {
        assertNotNull(e);
    }
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Query(org.apache.cayenne.query.Query) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) MockOperationObserver(org.apache.cayenne.access.MockOperationObserver) Test(org.junit.Test)

Example 7 with MockOperationObserver

use of org.apache.cayenne.access.MockOperationObserver in project cayenne by apache.

the class ThrowOnPartialSchemaStrategyIT method testThrowOnPartialStrategyTableExist.

@Test
public void testThrowOnPartialStrategyTableExist() 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();
    createOneTable("SUS1");
    createOneTable("SUS2");
    setStrategy(ThrowOnPartialSchemaStrategy.class);
    node.performQueries(Collections.singletonList(query), observer);
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) MockOperationObserver(org.apache.cayenne.access.MockOperationObserver) Test(org.junit.Test)

Example 8 with MockOperationObserver

use of org.apache.cayenne.access.MockOperationObserver in project cayenne by apache.

the class ThrowOnPartialSchemaStrategyIT method testThrowOnPartialStrategyWithOneTable.

@Test
public void testThrowOnPartialStrategyWithOneTable() throws Exception {
    createOneTable("SUS1");
    setStrategy(ThrowOnPartialSchemaStrategy.class);
    String template = "SELECT #result('ARTIST_ID' 'int') FROM ARTIST ORDER BY ARTIST_ID";
    SQLTemplate query = new SQLTemplate(Object.class, template);
    MockOperationObserver observer = new MockOperationObserver();
    try {
        node.performQueries(Collections.singletonList(query), observer);
        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) MockOperationObserver(org.apache.cayenne.access.MockOperationObserver) Test(org.junit.Test)

Example 9 with MockOperationObserver

use of org.apache.cayenne.access.MockOperationObserver in project cayenne by apache.

the class ResultDirectiveIT method selectForQuery.

private Map<String, Object> selectForQuery(String sql) {
    SQLTemplate template = new SQLTemplate(Artist.class, sql);
    template.setColumnNamesCapitalization(CapsStrategy.UPPER);
    MockOperationObserver observer = new MockOperationObserver();
    runtime.getDataDomain().performQueries(Collections.singletonList(template), observer);
    @SuppressWarnings("unchecked") List<Map<String, Object>> data = observer.rowsForQuery(template);
    assertEquals(1, data.size());
    Map<String, Object> row = data.get(0);
    return row;
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) MockOperationObserver(org.apache.cayenne.access.MockOperationObserver) Map(java.util.Map)

Example 10 with MockOperationObserver

use of org.apache.cayenne.access.MockOperationObserver in project cayenne by apache.

the class BindDirectiveIT method performInsertForParameters.

/**
 * Inserts row for given parameters
 *
 * @return inserted row
 */
private Map<String, ?> performInsertForParameters(Map<String, Object> parameters, String templateString) throws Exception {
    // TODO: do we really care if an inserting SQLTemplate is executed via
    // ObjectContext?
    SQLTemplate template = new SQLTemplate(Object.class, templateString);
    template.setParams(parameters);
    MockOperationObserver observer = new MockOperationObserver();
    node.performQueries(Collections.singletonList(template), observer);
    return ObjectSelect.dataRowQuery(Artist.class).selectOne(context);
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Artist(org.apache.cayenne.testdo.testmap.Artist) MockOperationObserver(org.apache.cayenne.access.MockOperationObserver)

Aggregations

MockOperationObserver (org.apache.cayenne.access.MockOperationObserver)16 SQLTemplate (org.apache.cayenne.query.SQLTemplate)14 Test (org.junit.Test)14 HashMap (java.util.HashMap)8 Connection (java.sql.Connection)7 SQLAction (org.apache.cayenne.query.SQLAction)7 DataRow (org.apache.cayenne.DataRow)5 Query (org.apache.cayenne.query.Query)3 PreparedStatementResultSetHandler (com.mockrunner.jdbc.PreparedStatementResultSetHandler)2 MockConnection (com.mockrunner.mock.jdbc.MockConnection)2 Date (java.sql.Date)2 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)2 DataNode (org.apache.cayenne.access.DataNode)2 RowReaderFactory (org.apache.cayenne.access.jdbc.reader.RowReaderFactory)2 DeleteBatchTranslator (org.apache.cayenne.access.translator.batch.DeleteBatchTranslator)2 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)2 DbAttribute (org.apache.cayenne.map.DbAttribute)2 DbEntity (org.apache.cayenne.map.DbEntity)2 EntityResolver (org.apache.cayenne.map.EntityResolver)2 DeleteBatchQuery (org.apache.cayenne.query.DeleteBatchQuery)2