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());
}
});
}
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);
}
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());
}
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
}
}
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());
}
Aggregations