Search in sources :

Example 16 with Expression

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());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ReflexiveAndToOne(org.apache.cayenne.testdo.relationships.ReflexiveAndToOne) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 17 with Expression

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();
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ReflexiveAndToOne(org.apache.cayenne.testdo.relationships.ReflexiveAndToOne) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 18 with Expression

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));
}
Also used : Expression(org.apache.cayenne.exp.Expression) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 19 with Expression

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));
}
Also used : Expression(org.apache.cayenne.exp.Expression) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 20 with Expression

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")));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Aggregations

Expression (org.apache.cayenne.exp.Expression)298 Test (org.junit.Test)265 Artist (org.apache.cayenne.testdo.testmap.Artist)69 SelectQuery (org.apache.cayenne.query.SelectQuery)47 Painting (org.apache.cayenne.testdo.testmap.Painting)29 BigDecimal (java.math.BigDecimal)23 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)17 DateTestEntity (org.apache.cayenne.testdo.date_time.DateTestEntity)16 ObjEntity (org.apache.cayenne.map.ObjEntity)13 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)12 DbEntity (org.apache.cayenne.map.DbEntity)10 List (java.util.List)9 HashMap (java.util.HashMap)8 DataRow (org.apache.cayenne.DataRow)8 DbAttribute (org.apache.cayenne.map.DbAttribute)8 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)7 DbRelationship (org.apache.cayenne.map.DbRelationship)6 ObjAttribute (org.apache.cayenne.map.ObjAttribute)6 ObjRelationship (org.apache.cayenne.map.ObjRelationship)6 Gallery (org.apache.cayenne.testdo.testmap.Gallery)6