Hi,

Just for those that want to know how to get the generated key of an INSERT
with empire-db:

For MySQL I implemented the interface DBDatabaseDriver.DBSetGenKeys

private static class GeneratedKey implements DBDatabaseDriver.DBSetGenKeys {
    public int id;

    @Override
    public void set(Object obj) {
        this.id = ((Long) obj).intValue();
    }
}

En then you can call the executeSQL like:

public int insert(DBCommand cmd) {

    GeneratedKey genKey = new GeneratedKey();
    this.db.executeSQL(cmd.getInsert(), null, this.conn, genKey);

    return genKey.id;
}

Where "genKey.id" is the generated key.

Please to the authors of empire-db to correct me if I'm wrong with this
implementation?
(Or give us the correct way to achive it?)

Regards,
exxos.







On Mon, Aug 16, 2010 at 11:36 PM, Francis De Brabandere <[email protected]
> wrote:

> On Mon, Aug 16, 2010 at 7:47 PM, exxos <[email protected]> wrote:
> > Ok, this has changed with the version 2.0.5.
> > The Javadoc is OK with the package. (Only the online javadoc is
> > unsynchronized)
> >
> > Sorry for the spam.
>
> I Don't see this as spam. Created a JIRA issue and added a section in
> our release guide about updating the docs.
>
> https://issues.apache.org/jira/browse/EMPIREDB-83
>
>
> Thanks for reporting!
>
> >
> > Regards,
> > exxos.
> >
> >
> > On Mon, Aug 16, 2010 at 7:42 PM, exxos <[email protected]> wrote:
> >>
> >> I'm talking about the Javadoc there:
> >> http://incubator.apache.org/empire-db/javadocs/empire-db/index.html
> >>
> >>
> >>
> >> On Mon, Aug 16, 2010 at 7:35 PM, exxos <[email protected]> wrote:
> >>>
> >>> Hello,
> >>>
> >>> There is a mismatch between the Javadoc (empire-db API documentation)
> and
> >>> the current implementation of empire-db v2.0.6.
> >>>
> >>> org.apache.empire.db.DBDatabaseDriver
> >>>
> >>>  java.lang.Object   getPostInsertAutoIncValue(DBDatabase db,
> >>> java.sql.Connection conn)
> >>>           Returns the value of an AutoIncrement field for the last
> >>> inserted record.
> >>>
> >>> But the current implementation of this class, does not support it. The
> >>> method is missing, why?
> >>>
> >>> Could you please advise?
> >>>
> >>> Regards,
> >>> exxos
> >>>
> >>>
> >>>
> >>>
> >>
> >
> >
>
>
>
> --
> http://www.somatik.be
> Microsoft gives you windows, Linux gives you the whole house.
>

Reply via email to