Search in sources :

Example 1 with SelectQuery

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

the class OptimisticLockException method getFreshSnapshot.

/**
 * Retrieves fresh snapshot for the failed row. Null row indicates that it was
 * deleted.
 *
 * @since 3.0
 */
public Map<?, ?> getFreshSnapshot(ObjectContext context) {
    Expression qualifier = null;
    for (DbAttribute attribute : rootEntity.getPrimaryKeys()) {
        Expression attributeQualifier = ExpressionFactory.matchDbExp(attribute.getName(), qualifierSnapshot.get(attribute.getName()));
        qualifier = (qualifier != null) ? qualifier.andExp(attributeQualifier) : attributeQualifier;
    }
    SelectQuery<DataRow> query = new SelectQuery<DataRow>(rootEntity, qualifier);
    query.setFetchingDataRows(true);
    return (Map<?, ?>) Cayenne.objectForQuery(context, query);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Expression(org.apache.cayenne.exp.Expression) DbAttribute(org.apache.cayenne.map.DbAttribute) DataRow(org.apache.cayenne.DataRow) Map(java.util.Map)

Example 2 with SelectQuery

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

the class CayenneContextMeaningfulPKIT method testMeaningfulPK.

@Test
public void testMeaningfulPK() throws Exception {
    deleteAndCreateTwoMeaningfulPKsDataSet();
    SelectQuery query = new SelectQuery(ClientMeaningfulPk.class);
    query.addOrdering(ClientMeaningfulPk.PK_PROPERTY, SortOrder.DESCENDING);
    List<?> results = clientContext.performQuery(query);
    assertEquals(2, results.size());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Test(org.junit.Test)

Example 3 with SelectQuery

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

the class CayenneContextPaginatedListCachingIT method testLocalCache.

@Test
public void testLocalCache() throws Exception {
    createSevenMtTable1sDataSet();
    SelectQuery query = new SelectQuery(ClientMtTable1.class);
    query.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
    query.setPageSize(3);
    query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
    List<ClientMtTable1> result1 = context.performQuery(query);
    assertEquals(7, result1.size());
    // ensure we can resolve all objects without a failure...
    for (ClientMtTable1 x : result1) {
        x.getGlobalAttribute1();
    }
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 4 with SelectQuery

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

the class CayenneContextPrimitiveIT method testSelectPrimitives.

@Test
public void testSelectPrimitives() throws Exception {
    createTwoPrimitivesDataSet();
    SelectQuery query = new SelectQuery(ClientTablePrimitives.class);
    query.addOrdering("db:" + TablePrimitives.ID_PK_COLUMN, SortOrder.ASCENDING);
    List<ClientTablePrimitives> results = context.performQuery(query);
    assertTrue(results.get(0).isBooleanColumn());
    assertFalse(results.get(1).isBooleanColumn());
    assertEquals(0, results.get(0).getIntColumn());
    assertEquals(5, results.get(1).getIntColumn());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientTablePrimitives(org.apache.cayenne.testdo.table_primitives.ClientTablePrimitives) Test(org.junit.Test)

Example 5 with SelectQuery

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

the class CayenneContextWithDataContextIT method testLocalCacheStaysLocal.

@SuppressWarnings("deprecation")
@Test
public void testLocalCacheStaysLocal() {
    DataContext serverContext = (DataContext) clientServerChannel.getParentChannel();
    SelectQuery query = new SelectQuery(ClientMtTable1.class);
    query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
    List<?> results = clientContext.performQuery(query);
    assertSame(results, clientContext.getQueryCache().get(query.getMetaData(clientContext.getEntityResolver())));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) DataContext(org.apache.cayenne.access.DataContext) 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