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