cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Kienenberger <mkien...@gmail.com>
Subject Re: Sharing a database with EOF: Primary key generation
Date Fri, 22 May 2015 13:46:57 GMT
Hugi, it would be worthwhile to make this a customizable parameter in
the existing primary key generator rather than only creating your own
custom version.  I also haven't looked at that part of the code base
in a long while so I don't know how feasible this is.

On Fri, May 22, 2015 at 7:15 AM, Andrus Adamchik <andrus@objectstyle.org> wrote:
>> Cayenne and EOF use a similar method, i.e. a table for the primary keys, but there's
an implementation difference -- EOF stores the *last* primary key value provided while Cayenne
stores the *next* value to be used. This means they can't share a single table (by using a
view for the naming differences).
>>
>> Anyone have any brilliant ideas or workarounds for this? (before I start messing
around with triggers or other messy workarounds).
>
> Cayenne has PkGenerator interface that can be customized/reimplemented:
>
> http://cayenne.apache.org/docs/4.0/api/org/apache/cayenne/dba/PkGenerator.html
>
> Unfortunately it is not directly injectable via DI (this is a TODO), so initializing
it will require a bit of indirection. E.g. you may subclass of decorate DbAdapterFactory.
Here is a decoration example:
>
> new ServerRuntimeBuilder()
>    .addModule(binder -> binder
>         .decorate(DbAdapterFactory.class)
>         .after(MyDbAdapterFactory.class)).build();
>
>
> public class MyDbAdapterFactory implements DbAdapterFactory {
>    private DbAdapterFactory delegate;
>
>    public MyDbAdapterFactory(@Inject DbAdapterFactory delegate) {
>       this.delegate  = delegate;
>    }
>
>    @Override
>    public DbAdapter createAdapter(DataNodeDescriptor nodeDescriptor, DataSource dataSource)
throws Exception {
>       DbAdapter a = deletegate.createAdapter(nodeDescriptor, dataSource);
>       return .. // here decorate "a" to return a custom PkGenerator.
>    }
> }
>
>> On the subject of PK generation, there's one thing I really like in EOF; if the PK
table is missing a row for a table, EOF will automatically select the max() value of the table's
PK column and use it to populate the table. Quite useful. Any objections to this becoming
a feature in Cayenne as well? (via pull request)
>
> I am all +1 on this. I'd say PK generation has been neglected for some time, so we should
freshen it up, including auto-bootstrap that you mentioned, and DI integration, maybe smarter
categorization by generator strategy, etc.
>
> One of the reasons I personally haven't payed much attention to this lately, is cause
I am using DB autoincrement (something not supported by EOF) and never had to worry about
PK lookup tables, sequences, etc. :)
>
> Andrus
>
>> On May 22, 2015, at 1:33 PM, Hugi Thordarson <hugi@karlmenn.is> wrote:
>>
>> Hi again.
>>
>> I'm using EOF and Cayenne to talk to the same MySQL database. Works fine apart from
one problem: Primary key generation.
>>
>> Cayenne and EOF use a similar method, i.e. a table for the primary keys, but there's
an implementation difference -- EOF stores the *last* primary key value provided while Cayenne
stores the *next* value to be used. This means they can't share a single table (by using a
view for the naming differences).
>>
>> Anyone have any brilliant ideas or workarounds for this? (before I start messing
around with triggers or other messy workarounds).
>>
>> On the subject of PK generation, there's one thing I really like in EOF; if the PK
table is missing a row for a table, EOF will automatically select the max() value of the table's
PK column and use it to populate the table. Quite useful. Any objections to this becoming
a feature in Cayenne as well? (via pull request)
>>
>> Cheers,
>> - hugi
>>
>> PS: Sorry for spamming the list with my stupid questions these days: hopefully I'll
be able to contribute in a meaningful way soon, rather than just sucking at the teat of your
knowledge :).
>>
>> // Hugi Thordarson
>> // http://www.loftfar.is/ <http://www.loftfar.is/>
>> // s. 895-6688
>

Mime
View raw message