Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return primary key value to new entity #47

Open
yukiofera opened this issue Feb 26, 2012 · 3 comments
Open

return primary key value to new entity #47

yukiofera opened this issue Feb 26, 2012 · 3 comments

Comments

@yukiofera
Copy link

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

@jonatasdaniel
Copy link
Owner

Can you fork the project and push this feature?

@yukiofera
Copy link
Author

Yes I can. :)

@jonatasdaniel
Copy link
Owner

If possible, write the unit test ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants