use of org.apache.cayenne.DataRow in project cayenne by apache.
the class SQLTemplateActionIT method testExecuteSelect.
@Test
public void testExecuteSelect() throws Exception {
createFourArtists();
String templateString = "SELECT * FROM ARTIST WHERE ARTIST_ID = #bind($id)";
SQLTemplate template = new SQLTemplate(Object.class, templateString);
sqlTemplateCustomizer.updateSQLTemplate(template);
Map<String, Object> bindings = new HashMap<>();
bindings.put("id", 201L);
template.setParameters(bindings);
// must ensure the right SQLTemplateAction is created
SQLAction plan = adapter.getAction(template, node);
assertTrue(plan instanceof SQLTemplateAction);
MockOperationObserver observer = new MockOperationObserver();
try (Connection c = dataSourceFactory.getSharedDataSource().getConnection()) {
plan.performAction(c, observer);
}
List<DataRow> rows = observer.rowsForQuery(template);
assertNotNull(rows);
assertEquals(1, rows.size());
DataRow row = rows.get(0);
// In the absence of ObjEntity most DB's return a Long here, except for
// Oracle
// that has no BIGINT type and
// returns BigDecimal, so do a Number comparison
Number id = (Number) row.get("ARTIST_ID");
assertNotNull(id);
assertEquals(((Number) bindings.get("id")).longValue(), id.longValue());
assertEquals("artist4", row.get("ARTIST_NAME"));
assertTrue(row.containsKey("DATE_OF_BIRTH"));
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class SimpleIdIncrementalFaultListDataRowsIT method testLastIndexOf1.
@Test
public void testLastIndexOf1() {
// resolve first page
list.get(0);
List<DataRow> artists = ObjectSelect.dataRowQuery(Artist.class, Artist.ARTIST_NAME.eq("artist3")).select(context);
assertEquals(1, artists.size());
DataRow row = artists.get(0);
assertEquals(2, list.lastIndexOf(row));
row.remove("ARTIST_NAME");
assertEquals(-1, list.lastIndexOf(row));
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class SimpleIdIncrementalFaultListDataRowsIT method testIndexOf2.
@Test
public void testIndexOf2() {
// resolve first page
list.get(0);
List<DataRow> artists = ObjectSelect.dataRowQuery(Artist.class, Artist.ARTIST_NAME.eq("artist2")).select(context);
assertEquals(1, artists.size());
DataRow row = artists.get(0);
assertEquals(1, list.indexOf(row));
row.remove("ARTIST_NAME");
assertEquals(-1, list.indexOf(row));
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class PrefetchProcessorTreeBuilderIT method testBuildTreeWithPrefetches.
@Test
public void testBuildTreeWithPrefetches() {
final ClassDescriptor descriptor = resolver.getClassDescriptor("Artist");
ObjEntity e2 = resolver.getObjEntity("Painting");
ObjEntity e3 = resolver.getObjEntity("Gallery");
ObjEntity e4 = resolver.getObjEntity("Exhibit");
ObjEntity e5 = resolver.getObjEntity("ArtistExhibit");
List<DataRow> mainRows = new ArrayList<>();
Map<String, List<?>> extraRows = new HashMap<>();
PrefetchTreeNode tree = new PrefetchTreeNode();
tree.addPath(Artist.PAINTING_ARRAY.getName()).setPhantom(false);
tree.addPath(Artist.PAINTING_ARRAY.dot(Painting.TO_GALLERY).dot(Gallery.EXHIBIT_ARRAY).getName()).setPhantom(false);
tree.addPath(Artist.ARTIST_EXHIBIT_ARRAY.getName()).setPhantom(false);
QueryMetadata metadata = new MockQueryMetadata() {
@Override
public ClassDescriptor getClassDescriptor() {
return descriptor;
}
@Override
public ObjEntity getObjEntity() {
return descriptor.getEntity();
}
@Override
public DbEntity getDbEntity() {
return getObjEntity().getDbEntity();
}
@Override
public DataMap getDataMap() {
return getObjEntity().getDataMap();
}
@Override
public boolean isRefreshingObjects() {
return true;
}
@Override
public boolean isResolvingInherited() {
return true;
}
};
HierarchicalObjectResolver resolver = new HierarchicalObjectResolver(context, metadata);
PrefetchProcessorTreeBuilder builder = new PrefetchProcessorTreeBuilder(resolver, mainRows, extraRows);
PrefetchProcessorNode n1 = builder.buildTree(tree);
assertSame(mainRows, n1.getDataRows());
assertSame(descriptor.getEntity(), n1.getResolver().getEntity());
PrefetchProcessorNode n2 = (PrefetchProcessorNode) n1.getNode("paintingArray");
assertNotNull(n2);
assertSame(e2, n2.getResolver().getEntity());
assertFalse(n2.isPhantom());
assertTrue(n2.isPartitionedByParent());
PrefetchProcessorNode n3 = (PrefetchProcessorNode) n1.getNode("paintingArray.toGallery");
assertNotNull(n3);
assertSame(e3, n3.getResolver().getEntity());
assertTrue(n3.isPhantom());
assertTrue(n3.isPartitionedByParent());
PrefetchProcessorNode n4 = (PrefetchProcessorNode) n1.getNode("paintingArray.toGallery.exhibitArray");
assertNotNull(n4);
assertSame(e4, n4.getResolver().getEntity());
assertFalse(n4.isPhantom());
assertTrue(n4.isPartitionedByParent());
PrefetchProcessorNode n5 = (PrefetchProcessorNode) n1.getNode("artistExhibitArray");
assertNotNull(n5);
assertSame(e5, n5.getResolver().getEntity());
assertFalse(n5.isPhantom());
assertTrue(n5.isPartitionedByParent());
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class ReturnTypesMappingIT method testBINARY.
@Test
public void testBINARY() throws Exception {
if (unitDbAdapter.supportsLobs()) {
String columnName = "BINARY_COLUMN";
ReturnTypesMap2 test = context.newObject(ReturnTypesMap2.class);
byte[] binaryValue = { 3, 4, 5, -6, 7, 0, 2, 9, 45, 64, 3, 127, -128, -60 };
test.setBinaryColumn(binaryValue);
context.commitChanges();
DataRow testRead = (DataRow) context.performQuery(MappedSelect.query("SelectReturnTypesMap2")).get(0);
Object columnValue = testRead.get(columnName);
assertNotNull(columnValue);
assertEquals(byte[].class, columnValue.getClass());
assertTrue(Arrays.equals(binaryValue, (byte[]) columnValue));
}
}
Aggregations