if (ded == null) {
throw new DbOomException("Not an entity: " + type);
}
if (isPersistent(ded, entity) == false) {
DbQuery q;
if (keysGeneratedByDatabase == true) {
q = query(insert(entity));
q.setGeneratedKey();
q.executeUpdate();
long nextId = q.getGeneratedKey();
setEntityId(ded, entity, nextId);
} else {
long nextId = generateNextId(ded);
setEntityId(ded, entity, nextId);
q = query(insert(entity));
q.executeUpdate();
}
q.close();
} else {
query(DbEntitySql.updateAll(entity)).autoClose().executeUpdate();
}
return entity;
}