+ query);
}
BatchQuery batch = (BatchQuery) query;
ObjectId id = batch.getObjectId();
if (id == null || !id.isTemporary()) {
// why would this happen?
return;
}
if (keys.size() != 1) {
throw new CayenneRuntimeException(
"One and only one PK row is expected, instead got " + keys.size());
}
DataRow key = keys.get(0);
// empty key?
if (key.size() == 0) {
throw new CayenneRuntimeException("Empty key generated.");
}
// determine DbAttribute name...
// As of now (01/2005) all tested drivers don't provide decent descriptors of
// identity result sets, so a data row will contain garbage labels. Also most
// DBs only support one autogenerated key per table... So here we will have to
// infer the key name and currently will only support a single column...
if (key.size() > 1) {
throw new CayenneRuntimeException(
"Only a single column autogenerated PK is supported. "
+ "Generated key: "
+ key);
}
for (DbAttribute attribute : batch.getDbEntity().getGeneratedAttributes()) {
// batch can have generated attributes that are not PKs, e.g. columns with
// DB DEFAULT values. Ignore those.
if (attribute.isPrimaryKey()) {
Object value = key.values().iterator().next();
// Log the generated PK
QueryLogger.logGeneratedKey(attribute, value);
// I guess we should override any existing value,
// as generated key is the latest thing that exists in the DB.
id.getReplacementIdMap().put(attribute.getName(), value);
break;
}
}
}