jonatasdaniel/andorm — Issue #47: return primary key value to new entity
Author: yukiofera
Created: 2012-02-26 19:08:55+00:00
State: open

class AndroidPersistenceManager

public long save(Object o) {
{ ... }

Long primaryKey = 0L;
String tableName = cache.getTableName();
try {
primaryKey = database.insert(tableName, null, values);
} catch(SQLException e) {
throw new AndOrmPersistenceException(MessageFormat.format(bundle.getString("save_error"), o.getClass().getCanonicalName(), e.getMessage()));
}

PrimaryKeyProperty primaryKeyProperty = cache.getPk();
if (primaryKeyProperty.isAutoInc()) {
if (primaryKeyProperty.getDatabaseFieldType().equals(Integer.class)) {
primaryKeyProperty.set(o, primaryKey.intValue());
} else if (primaryKeyProperty.getDatabaseFieldType().equals(Long.class)) {
primaryKeyProperty.set(o, primaryKey);
}
}

if (cache.getAfterSaveMethod() != null) {
invoke(o, cache.getAfterSaveMethod()).withoutParams();
}

return primaryKey;
}

Would be interesting to return the primary key value.

[]'s