use of org.apache.cayenne.DataRow in project cayenne by apache.
the class DataContextQueryCachingIT method testSharedCacheDataRowsRefresh.
@Test
public void testSharedCacheDataRowsRefresh() throws Exception {
ObjectSelect<DataRow> select = ObjectSelect.dataRowQuery(Artist.class).sharedCache();
MockDataNode engine = MockDataNode.interceptNode(domain, getNode());
try {
// first run, no cache yet
List<?> rows1 = mockupDataRows(2);
engine.reset();
engine.addExpectedResult(select, rows1);
List<?> resultRows = context.performQuery(select);
assertEquals(1, engine.getRunCount());
assertEquals(rows1, resultRows);
QueryMetadata cacheKey = select.getMetaData(context.getEntityResolver());
assertEquals(rows1, context.getParentDataDomain().getQueryCache().get(cacheKey));
assertNull(context.getQueryCache().get(cacheKey));
// second run, must refresh the cache
List<?> rows2 = mockupDataRows(5);
engine.reset();
engine.addExpectedResult(select, rows2);
select.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE_REFRESH);
List<?> freshResultRows = context.performQuery(select);
assertEquals(1, engine.getRunCount());
assertEquals(rows2, freshResultRows);
assertEquals(rows2, context.getParentDataDomain().getQueryCache().get(cacheKey));
assertNull(context.getQueryCache().get(cacheKey));
} finally {
engine.stopInterceptNode();
}
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class DataContextQueryCachingIT method testLocalCacheDataRowsRefresh.
@Test
public void testLocalCacheDataRowsRefresh() throws Exception {
ObjectSelect<DataRow> select = ObjectSelect.dataRowQuery(Artist.class).localCache();
MockDataNode engine = MockDataNode.interceptNode(domain, getNode());
try {
// first run, no cache yet
List<?> rows1 = mockupDataRows(2);
engine.reset();
engine.addExpectedResult(select, rows1);
List<?> resultRows = context.performQuery(select);
assertEquals(1, engine.getRunCount());
assertEquals(rows1, resultRows);
QueryMetadata cacheKey = select.getMetaData(context.getEntityResolver());
assertNull(context.getParentDataDomain().getQueryCache().get(cacheKey));
assertEquals(rows1, context.getQueryCache().get(cacheKey));
// second run, must refresh the cache
List<?> rows2 = mockupDataRows(4);
engine.reset();
engine.addExpectedResult(select, rows2);
select.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE_REFRESH);
List<?> freshResultRows = context.performQuery(select);
assertEquals(1, engine.getRunCount());
assertEquals(rows2, freshResultRows);
assertNull(context.getParentDataDomain().getQueryCache().get(cacheKey));
assertEquals(rows2, context.getQueryCache().get(cacheKey));
} finally {
engine.stopInterceptNode();
}
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class DataContextQueryCachingIT method mockupDataRows.
private List<?> mockupDataRows(int len) {
List<Object> rows = new ArrayList<>(len);
for (int i = 0; i < len; i++) {
DataRow a = new DataRow(3);
a.put("ARTIST_ID", i + 1);
a.put("ARTIST_NAME", "A-" + (i + 1));
rows.add(a);
}
return rows;
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class DataContextNoPkIT method testNoPkFetchDataRows.
@Test
public void testNoPkFetchDataRows() {
List<DataRow> rows = ObjectSelect.dataRowQuery(NoPkTestEntity.class).select(context);
assertNotNull(rows);
assertEquals(2, rows.size());
DataRow row1 = rows.get(0);
DataRow row2 = rows.get(1);
// assert that rows have different values
// (there was a bug earlier that fetched distinct rows for
// entities with no primary key.
assertTrue(!row1.get("ATTRIBUTE1").equals(row2.get("ATTRIBUTE1")));
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class ProcedureCallIT method testSelectWithRowDescriptor.
@Test
public void testSelectWithRowDescriptor() throws Exception {
if (!accessStackAdapter.supportsStoredProcedures()) {
return;
}
// create an artist with painting in the database
createArtist(1000.0);
// TESTING THIS ***
// A.ARTIST_ID, A.DATE_OF_BIRTH, A.ARTIST_NAME
ColumnDescriptor[] columns = new ColumnDescriptor[3];
// read ID as Long, and everything else as default types
columns[0] = new ColumnDescriptor("ARTIST_ID", Types.BIGINT);
columns[1] = new ColumnDescriptor("ARTIST_NAME", Types.CHAR);
columns[2] = new ColumnDescriptor("DATE_OF_BIRTH", Types.DATE);
List<?> rows = runProcedureSelect(ProcedureCall.dataRowQuery(SELECT_STORED_PROCEDURE).param("aName", "An Artist").param("paintingPrice", 3000).resultDescriptor(columns)).firstList();
// check the results
assertNotNull("Null result from StoredProcedure.", rows);
assertEquals(1, rows.size());
DataRow artistRow = (DataRow) rows.get(0);
assertEquals(3, artistRow.size());
artistRow = uppercaseConverter(artistRow);
Object id = artistRow.get("ARTIST_ID");
assertNotNull(id);
assertTrue("Expected Long, got: " + id.getClass().getName(), id instanceof Long);
}
Aggregations