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);
}
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());
}
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();
}
}
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());
}
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())));
}
Aggregations