use of org.apache.cayenne.DataRow in project cayenne by apache.
the class DataDomainQueryAction method polymorphicRowFromCache.
private DataRow polymorphicRowFromCache(EntityInheritanceTree superNode, Map<String, ?> idSnapshot) {
for (EntityInheritanceTree child : superNode.getChildren()) {
ObjectId id = new ObjectId(child.getEntity().getName(), idSnapshot);
DataRow row = cache.getCachedSnapshot(id);
if (row != null) {
return row;
}
row = polymorphicRowFromCache(child, idSnapshot);
if (row != null) {
return row;
}
}
return null;
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class SelectActionIT method testFetchLimit_DistinctResultIterator.
@Test
public void testFetchLimit_DistinctResultIterator() throws Exception {
if (accessStackAdapter.supportsLobs()) {
insertClobDb();
Expression qual = ExpressionFactory.exp("clobValue.value = 100");
SelectQuery select = new SelectQuery(ClobTestEntity.class, qual);
select.setFetchLimit(25);
List<DataRow> resultRows = context.performQuery(select);
assertNotNull(resultRows);
assertEquals(25, resultRows.size());
}
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class DataRowDeserializer method readMap.
@Override
public Object readMap(AbstractHessianInput in) throws IOException {
int size = in.readInt();
DataRow row = new DataRow(size);
try {
versionField.set(row, Long.valueOf(in.readLong()));
} catch (Exception e) {
throw new IOException("Error reading 'version' field");
}
row.setReplacesVersion(in.readLong());
in.addRef(row);
while (!in.isEnd()) {
row.put((String) in.readObject(), in.readObject());
}
in.readEnd();
return row;
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class DataDomainFlushObserver method nextGeneratedRows.
/**
* Processes generated keys.
*
* @since 1.2
*/
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void nextGeneratedRows(Query query, ResultIterator<?> keysIterator, List<ObjectId> idsToUpdate) {
// read and close the iterator before doing anything else
List<DataRow> keys;
try {
keys = (List<DataRow>) keysIterator.allRows();
} finally {
keysIterator.close();
}
if (!(query instanceof InsertBatchQuery)) {
throw new CayenneRuntimeException("Generated keys only supported for InsertBatchQuery, instead got %s", query);
}
if (keys.size() != idsToUpdate.size()) {
throw new CayenneRuntimeException("Mismatching number of generated PKs: expected %d, instead got %d", idsToUpdate.size(), keys.size());
}
for (int i = 0; i < keys.size(); i++) {
DataRow key = keys.get(i);
// empty key?
if (key.size() == 0) {
throw new CayenneRuntimeException("Empty key generated.");
}
ObjectId idToUpdate = idsToUpdate.get(i);
if (idToUpdate == null || !idToUpdate.isTemporary()) {
// why would this happen?
return;
}
BatchQuery batch = (BatchQuery) query;
for (DbAttribute attribute : batch.getDbEntity().getGeneratedAttributes()) {
// DB DEFAULT values. Ignore those.
if (attribute.isPrimaryKey()) {
Object value = key.get(attribute.getName());
// identity result sets, so a data row may contain garbage labels.
if (value == null) {
value = key.values().iterator().next();
}
// Log the generated PK
logger.logGeneratedKey(attribute, value);
// I guess we should override any existing value,
// as generated key is the latest thing that exists in the DB.
idToUpdate.getReplacementIdMap().put(attribute.getName(), value);
break;
}
}
}
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class DataRowUtilsIT method testMerge.
@Test
public void testMerge() throws Exception {
createOneArtist();
String n1 = "changed";
String n2 = "changed again";
Artist a1 = ObjectSelect.query(Artist.class).select(context).get(0);
a1.setArtistName(n1);
DataRow s2 = new DataRow(2);
s2.put("ARTIST_NAME", n2);
s2.put("DATE_OF_BIRTH", new java.util.Date());
ClassDescriptor d = context.getEntityResolver().getClassDescriptor("Artist");
DataRowUtils.mergeObjectWithSnapshot(context, d, a1, s2);
// name was modified, so it should not change during merge
assertEquals(n1, a1.getArtistName());
// date of birth came from database, it should be updated during merge
assertEquals(s2.get("DATE_OF_BIRTH"), a1.getDateOfBirth());
}
Aggregations