use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class CAY_194IT method testQualifyOnToMany.
@Test
public void testQualifyOnToMany() {
ReflexiveAndToOne ox = context.newObject(ReflexiveAndToOne.class);
ox.setName("ox");
ReflexiveAndToOne o1 = context.newObject(ReflexiveAndToOne.class);
o1.setName("o1");
ReflexiveAndToOne o2 = context.newObject(ReflexiveAndToOne.class);
o2.setName("o2");
o2.setToParent(o1);
context.commitChanges();
Expression qualifier = ExpressionFactory.matchExp("children", o2);
List<?> parents = context.performQuery(new SelectQuery(ReflexiveAndToOne.class, qualifier));
assertEquals(1, parents.size());
assertSame(o1, parents.get(0));
qualifier = ExpressionFactory.matchExp("children", o1);
parents = context.performQuery(new SelectQuery(ReflexiveAndToOne.class, qualifier));
assertEquals(0, parents.size());
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class CAY_194IT method testQualifyOnToOne.
@Test
public void testQualifyOnToOne() {
ReflexiveAndToOne ox = context.newObject(ReflexiveAndToOne.class);
ox.setName("ox");
ReflexiveAndToOne o1 = context.newObject(ReflexiveAndToOne.class);
o1.setName("o1");
ReflexiveAndToOne o2 = context.newObject(ReflexiveAndToOne.class);
o2.setName("o2");
o2.setToParent(o1);
context.commitChanges();
Expression qualifier = ExpressionFactory.matchExp("toParent", o1);
List<?> children = context.performQuery(new SelectQuery(ReflexiveAndToOne.class, qualifier));
assertEquals(1, children.size());
assertSame(o2, children.get(0));
o2.setToParent(null);
context.commitChanges();
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class SimpleIdIncrementalFaultListDataRowsIT method testLastIndexOf1.
@Test
public void testLastIndexOf1() throws Exception {
// resolve first page
list.get(0);
Expression qual = ExpressionFactory.matchExp("artistName", "artist3");
SelectQuery<DataRow> query = SelectQuery.dataRowQuery(Artist.class, qual);
List<?> artists = context1.performQuery(query);
assertEquals(1, artists.size());
DataRow row = (DataRow) artists.get(0);
assertEquals(2, list.lastIndexOf(row));
row.remove("ARTIST_NAME");
assertEquals(-1, list.lastIndexOf(row));
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class SimpleIdIncrementalFaultListDataRowsIT method testIndexOf2.
@Test
public void testIndexOf2() throws Exception {
// resolve first page
list.get(0);
Expression qual = ExpressionFactory.matchExp("artistName", "artist2");
SelectQuery<DataRow> query = SelectQuery.dataRowQuery(Artist.class, qual);
List<?> artists = context1.performQuery(query);
assertEquals(1, artists.size());
DataRow row = (DataRow) artists.get(0);
assertEquals(1, list.indexOf(row));
row.remove("ARTIST_NAME");
assertEquals(-1, list.indexOf(row));
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class SimpleIdIncrementalFaultListIT method testLastIndexOf.
@Test
public void testLastIndexOf() throws Exception {
SimpleIdIncrementalFaultList<?> list = prepareList(6);
Expression qual = ExpressionFactory.matchExp("artistName", "artist20");
SelectQuery query = new SelectQuery(Artist.class, qual);
List<?> artists = list.dataContext.performQuery(query);
assertEquals(1, artists.size());
Artist row = (Artist) artists.get(0);
assertEquals(19, list.lastIndexOf(row));
assertEquals(-1, list.lastIndexOf(list.dataContext.newObject("Artist")));
}
Aggregations