Search in sources :

Example 81 with SelectQuery

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

the class ReturnTypesMappingIT method testNUMERIC2.

@Test
public void testNUMERIC2() throws Exception {
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    BigDecimal numericValue = new BigDecimal("578438.57843");
    test.setNumericColumn(numericValue);
    context.commitChanges();
    SelectQuery q = new SelectQuery(ReturnTypesMap1.class);
    ReturnTypesMap1 testRead = (ReturnTypesMap1) context.performQuery(q).get(0);
    BigDecimal columnValue = testRead.getNumericColumn();
    assertNotNull(columnValue);
    assertEquals(BigDecimal.class, columnValue.getClass());
    assertEquals(numericValue, columnValue);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 82 with SelectQuery

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

the class ReturnTypesMappingIT method testTINYINT2.

@Test
public void testTINYINT2() throws Exception {
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    Byte tinyintValue = 89;
    test.setTinyintColumn(tinyintValue);
    context.commitChanges();
    SelectQuery q = new SelectQuery(ReturnTypesMap1.class);
    ReturnTypesMap1 testRead = (ReturnTypesMap1) context.performQuery(q).get(0);
    Byte columnValue = testRead.getTinyintColumn();
    assertNotNull(columnValue);
    assertEquals(Byte.class, columnValue.getClass());
    assertEquals(tinyintValue, columnValue);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) Test(org.junit.Test)

Example 83 with SelectQuery

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

the class QueryCacheIT method testLocalCache.

@Test
public void testLocalCache() {
    Artist a = context1.newObject(Artist.class);
    a.setArtistName("artist");
    context1.commitChanges();
    SelectQuery q = new SelectQuery(Artist.class);
    q.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
    List<Artist> result1 = context1.performQuery(q);
    List<Artist> result2 = context2.performQuery(q);
    assertNotSame(result1.get(0).getObjectContext(), result2.get(0).getObjectContext());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SelectQuery(org.apache.cayenne.query.SelectQuery) Test(org.junit.Test)

Example 84 with SelectQuery

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

the class DataContextPrefetchQualifierOverlapIT method testToManyDisjointOverlappingQualifierWithInnerJoin.

@Test
public void testToManyDisjointOverlappingQualifierWithInnerJoin() throws Exception {
    createTwoArtistsThreePaintingsDataSet();
    SelectQuery query = new SelectQuery(Artist.class);
    query.andQualifier(ExpressionFactory.likeExp("paintingArray.paintingTitle", "AB%"));
    query.addPrefetch(Artist.PAINTING_ARRAY.disjoint());
    List<Artist> result = context.performQuery(query);
    assertEquals(1, result.size());
    Artist a = result.get(0);
    assertEquals(3, a.getPaintingArray().size());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Artist(org.apache.cayenne.testdo.testmap.Artist) Test(org.junit.Test)

Example 85 with SelectQuery

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

the class DataContextPrefetchQualifierOverlapIT method testToManyJointOverlappingQualifierWithOuterJoin.

@Test
public void testToManyJointOverlappingQualifierWithOuterJoin() throws Exception {
    createTwoArtistsThreePaintingsDataSet();
    SelectQuery query = new SelectQuery(Artist.class);
    query.andQualifier(ExpressionFactory.likeExp("paintingArray+.paintingTitle", "AB%"));
    query.addPrefetch(Artist.PAINTING_ARRAY.joint());
    query.orQualifier(ExpressionFactory.likeExp("artistName", "A%"));
    query.addOrdering(Artist.ARTIST_NAME.asc());
    List<Artist> result = context.performQuery(query);
    assertEquals(2, result.size());
    Artist a = result.get(0);
    assertEquals(3, a.getPaintingArray().size());
    Artist a1 = result.get(1);
    assertEquals(0, a1.getPaintingArray().size());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Artist(org.apache.cayenne.testdo.testmap.Artist) 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