use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class EmbeddingIT method testUpdateEmbeddedProperties.
@Test
public void testUpdateEmbeddedProperties() throws Exception {
createUpdateDataSet();
SelectQuery query = new SelectQuery<>(EmbedEntity1.class);
query.addOrdering(EmbedEntity1.NAME.asc());
List<?> results = context.performQuery(query);
EmbedEntity1 o1 = (EmbedEntity1) results.get(0);
Embeddable1 e11 = o1.getEmbedded1();
e11.setEmbedded10("x1");
assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState());
context.commitChanges();
SelectQuery<DataRow> query1 = SelectQuery.dataRowQuery(EmbedEntity1.class);
DataRow row = (DataRow) Cayenne.objectForQuery(context, query1);
assertNotNull(row);
assertEquals("x1", row.get("EMBEDDED10"));
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class EmbeddingIT method testUpdateEmbedded.
@Test
public void testUpdateEmbedded() throws Exception {
createUpdateDataSet();
SelectQuery query = new SelectQuery<>(EmbedEntity1.class);
query.addOrdering(EmbedEntity1.NAME.asc());
List<?> results = context.performQuery(query);
EmbedEntity1 o1 = (EmbedEntity1) results.get(0);
Embeddable1 e11 = new Embeddable1();
e11.setEmbedded10("x1");
e11.setEmbedded20("x2");
o1.setEmbedded1(e11);
assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState());
context.commitChanges();
SelectQuery<DataRow> query1 = SelectQuery.dataRowQuery(EmbedEntity1.class);
DataRow row = query1.selectOne(context);
assertNotNull(row);
assertEquals("x1", row.get("EMBEDDED10"));
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class FlattenedPrefetchIT method testJointManyToMany.
@Test
public void testJointManyToMany() throws Exception {
createPrefetchDataSet1();
SelectQuery q = new SelectQuery(Artist.class);
q.addPrefetch(Artist.GROUP_ARRAY.joint());
final List<Artist> objects = context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(3, objects.size());
for (Artist a : objects) {
List<ArtGroup> list = a.getGroupArray();
assertNotNull(list);
assertFalse("artist's groups not resolved: " + a, ((ValueHolder) list).isFault());
assertTrue(list.size() > 0);
for (ArtGroup g : list) {
assertEquals(PersistenceState.COMMITTED, g.getPersistenceState());
}
// assert no duplicates
Set<ArtGroup> s = new HashSet<ArtGroup>(list);
assertEquals(s.size(), list.size());
}
}
});
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class FlattenedPrefetchIT method testJointMultiPrefetch.
@Test
public void testJointMultiPrefetch() throws Exception {
createPrefetchDataSet2();
SelectQuery q = new SelectQuery(Painting.class);
q.addPrefetch(Painting.TO_ARTIST.joint());
q.addPrefetch(Painting.TO_ARTIST.dot(Artist.GROUP_ARRAY).joint());
final List<Painting> objects = context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(3, objects.size());
for (Painting p : objects) {
Artist a = p.getToArtist();
assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
List<ArtGroup> list = a.getGroupArray();
assertNotNull(list);
assertFalse("artist's groups not resolved: " + a, ((ValueHolder) list).isFault());
assertTrue(list.size() > 0);
for (ArtGroup g : list) {
assertEquals(PersistenceState.COMMITTED, g.getPersistenceState());
}
// assert no duplicates
Set<ArtGroup> s = new HashSet<ArtGroup>(list);
assertEquals(s.size(), list.size());
}
}
});
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class FlattenedRelationshipInContextIT method testIsToOneTargetModifiedFlattenedFault1.
@Test
public void testIsToOneTargetModifiedFlattenedFault1() throws Exception {
createFlattenedTestDataSet();
// fetch
List<?> ft3s = context.performQuery(new SelectQuery(FlattenedTest3.class));
assertEquals(1, ft3s.size());
FlattenedTest3 ft3 = (FlattenedTest3) ft3s.get(0);
// mark as dirty for the purpose of the test...
ft3.setPersistenceState(PersistenceState.MODIFIED);
assertTrue(ft3.readPropertyDirectly("toFT1") instanceof Fault);
// test that checking for modifications does not trigger a fault, and generally
// works well
ClassDescriptor d = context.getEntityResolver().getClassDescriptor("FlattenedTest3");
ArcProperty flattenedRel = (ArcProperty) d.getProperty("toFT1");
ObjectDiff diff = context.getObjectStore().registerDiff(ft3.getObjectId(), null);
assertFalse(DataRowUtils.isToOneTargetModified(flattenedRel, ft3, diff));
assertTrue(ft3.readPropertyDirectly("toFT1") instanceof Fault);
}
Aggregations