use of org.apache.cayenne.access.util.DoNothingOperationObserver in project cayenne by apache.
the class FrontBasePkGenerator method longPkFromDatabase.
/**
* @since 3.0
*/
@Override
protected long longPkFromDatabase(DataNode node, DbEntity entity) throws Exception {
String template = "SELECT #result('UNIQUE' 'long') FROM " + entity.getName();
final long[] pkHolder = new long[1];
SQLTemplate query = new SQLTemplate(entity, template);
OperationObserver observer = new DoNothingOperationObserver() {
@Override
public void nextRows(Query query, List<?> dataRows) {
if (dataRows.size() != 1) {
throw new CayenneRuntimeException("Error fetching PK. Expected one row, got %d", dataRows.size());
}
DataRow row = (DataRow) dataRows.get(0);
Number pk = (Number) row.get("UNIQUE");
pkHolder[0] = pk.longValue();
}
};
node.performQueries(Collections.singleton((Query) query), observer);
return pkHolder[0];
}
Aggregations