Re: MySql AUTO_PK_SUPPORT

From: Borut Bolčin (bo..ajdi.si)
Date: Sun Apr 23 2006 - 05:21:54 EDT

  • Next message: Andrus Adamchik: "Re: MySql AUTO_PK_SUPPORT"

    Andrus Adamchik pravi:
    >
    > On Apr 21, 2006, at 12:33 PM, Borut Bolčina wrote:
    >> INFO QueryLogger: DELETE FROM AUTO_PK_SUPPORT WHERE TABLE_NAME IN
    >> ('source')
    >> INFO QueryLogger: INSERT INTO AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID)
    >> VALUES ('source', 200)
    >
    > An implementation of a smarter auto PK configuration mechanism has
    > been pending for some time, but I think this particular issue can be
    > addresses separately. You can try it on a custom PK generator and I
    > appreciate if you log this issue in Jira. Here is how the solution
    > might look like:
    >
    > 1. Override JdbcPkGenerator.createAutoPk(DataNode node, List
    > dbEntities) as follows -
    > 2. Do a select from AUTO_PK_SUPPORT to check which entities are
    > already present in the DB
    > 3. Subtract those entities from dbEntities list, getting a subset of
    > entities whose records are missing
    > 4. This line "runUpdate(node, pkDeleteString(dbEntities))" should only
    > use a subset obtained in (3)
    >
    >
    > Andrus
    >
    The above solution suggests selectively deleting from AUTO_PK_SUPPORT
    table which is even more then I want. In my case I have only two tables
    plus AUTO_PK_SUPPORT. Once they are created, no deletion in
    AUTO_PK_SUPPORT must occur.

    If I understand you correctly, the above algorithm would create a statement
    DELETE FROM AUTO_PK_SUPPORT WHERE TABLE_NAME IN ('tableA', 'tableB',
    'tableC')
    but not, say, tableD, as it is already present (created before).

    In my case this pkDeleteString would look like (empty table names)
    DELETE FROM AUTO_PK_SUPPORT WHERE TABLE_NAME IN ('')
    INSERT INTO AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('', 200)

    I think an error would occur with the above statement.

    One "workaround" I can think of is to do a SELECT on AUTO_PK_SUPPORT and
    if no error is thrown I must assume the table exists, so I skip
    generator.runGenerator(dataSource); altogether.

    What do you think?



    This archive was generated by hypermail 2.0.0 : Sun Apr 23 2006 - 05:22:21 EDT