Re: Entities whose pk values come from a value in another mysql table

From: Mike Kienenberger (mkienen..laska.net)
Date: Mon Apr 05 2004 - 22:05:27 EDT

  • Next message: Andrus Adamchik: "Re: Entities whose pk values come from a value in another mysql table"

    Scott Ellsworth <scot..lodar.com> wrote:
    > There are several hundred tables created with sql like:
    >
    > CREATE TABLE Resource (
    > id INTEGER NOT NULL,
    > resource_type INTEGER,
    > max_reads INTEGER,
    > reads_reserved INTEGER,
    > is_reserved_for_modify CHAR(2),
    > state INTEGER,
    > barcode VARCHAR(255)
    > );
    > ALTER TABLE Resource ADD PRIMARY KEY
    > (id);
    > CREATE TABLE Resource_Seq (
    > nextval INTEGER NOT NULL
    > );
    > INSERT INTO Resource_Seq (nextval) values (1);
    >
    > Each new entry into Resource gets an id equal to Resource_Seq.nextval,
    > which is incremented as soon as it is read. (This thus emulates an
    > Oracle sequence, with a bit more effort because of the key management.)
    >
    > Is there a way to tell Cayenne to do this kind of key management?
    > Pointers to examples like this would work. I am targeting Cayenne 1.1.

    Make a subclass of MySQLAdaptor with a custom MySQLPkGenerator, and use it
    instead of the MySQLAdaptor class in your model.

    You can take a look at
    org.objectstyle.cayenne.dba.openbase.OpenBasePkGenerator since it also uses
    a custom "one-query-for-each-primary-key-retrieved" PK generator, and is
    probably easier to start from than Oracle's PkGenerator (I've never looked
    at the MySQLPkGenerator so I can't comment on that).



    This archive was generated by hypermail 2.0.0 : Mon Apr 05 2004 - 22:04:34 EDT