Search in sources :

Example 26 with SelectQuery

use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.

the class CAY_115IT method testDistinctClobFetchWithToManyJoin.

@Test
public void testDistinctClobFetchWithToManyJoin() throws Exception {
    if (!accessStackAdapter.supportsLobInsertsAsStrings()) {
        return;
    }
    createDistinctClobFetchWithToManyJoin();
    Expression qual = ExpressionFactory.exp("details.name like 'cd%'");
    SelectQuery query = new SelectQuery(ClobMaster.class, qual);
    List<?> result = context.performQuery(query);
    assertEquals(3, result.size());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 27 with SelectQuery

use of org.apache.cayenne.query.SelectQuery 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 28 with SelectQuery

use of org.apache.cayenne.query.SelectQuery 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 29 with SelectQuery

use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.

the class SimpleIdIncrementalFaultListIT method testNewObject.

@Test
public void testNewObject() throws Exception {
    createArtistsDataSet();
    Artist newArtist = context.newObject(Artist.class);
    newArtist.setArtistName("x");
    context.commitChanges();
    SelectQuery<Artist> q = new SelectQuery<Artist>(Artist.class);
    q.setPageSize(6);
    q.addOrdering(Artist.ARTIST_NAME.asc());
    SimpleIdIncrementalFaultList<?> list = new SimpleIdIncrementalFaultList<Object>(context, q, 10000);
    assertSame(newArtist, list.get(25));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SelectQuery(org.apache.cayenne.query.SelectQuery) Test(org.junit.Test)

Example 30 with SelectQuery

use of org.apache.cayenne.query.SelectQuery 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

SelectQuery (org.apache.cayenne.query.SelectQuery)360 Test (org.junit.Test)348 Artist (org.apache.cayenne.testdo.testmap.Artist)128 Painting (org.apache.cayenne.testdo.testmap.Painting)75 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)64 Expression (org.apache.cayenne.exp.Expression)47 List (java.util.List)43 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)26 ValueHolder (org.apache.cayenne.ValueHolder)21 ReturnTypesMap1 (org.apache.cayenne.testdo.return_types.ReturnTypesMap1)18 ArrayList (java.util.ArrayList)16 Date (java.util.Date)13 DataRow (org.apache.cayenne.DataRow)12 ObjectContext (org.apache.cayenne.ObjectContext)12 DbEntity (org.apache.cayenne.map.DbEntity)12 SQLTemplate (org.apache.cayenne.query.SQLTemplate)11 ROArtist (org.apache.cayenne.testdo.testmap.ROArtist)11 HashMap (java.util.HashMap)10 ObjectId (org.apache.cayenne.ObjectId)10 Query (org.apache.cayenne.query.Query)10