persistence@glassfish.java.net

Re: Code review for Issue 1179 unique-constraint used in <table> element of mapping file throws exception on creation of the entity manager

From: Wonseok Kim <guruwons_at_gmail.com>
Date: Fri, 10 Nov 2006 02:07:29 +0900

Actually my name is "Wonseok", is it confusing to spell? ;-)

Sorry for import statements, my IDE went crazy at that time so those are
messed up. Maybe I worked too hard. :-)
I fixed it and added CDDL to the new files which I added.

Also I confirmed that EPT tests run OK on Derby.

Please check in.
Thanks
-Wonseok

On 11/9/06, Tom Ware <tom.ware_at_oracle.com> wrote:
>
> Hi Wonsoek,
>
> Looks good. Just two comments
>
> - XMLTableHelper appears to have two imports on the same line
> - Please ensure your newly added files include the CDDL license comment
> at the top. You can get that information from the existing files.
>
> -Tom
>
> Wonseok Kim wrote:
>
> > Hi, Tom
> >
> > Here is the another fix for DDL generation.
> > https://glassfish.dev.java.net/issues/show_bug.cgi?id=1179
> >
> > Please review.
> >
> > Situation:
> > 1. @UniqueConstraint.columNames()(or its equivalent xml element)
> > should be mapped to one unique constraint. However, some codes had
> > handled each column of @UniqueConstraint.columnNames () as a separate
> > unique constraint. This is the first error.
> > Then, it calls DatabaseTable.addUniqueConstraint(String columnName)
> > which just add the columnName to underlying uniqueConstraints Vector.
> > There is also addUniqueConstraints(String[] columnNames) method.
> > Therefore the Vector object holds String or String[] types.
> >
> > 2. DefaultTableGenerator just set the elements from
> > DatabaseTable.uniqueConstraints() Vector to TableDefinition.uniqueKeys
> > Vector.
> >
> > 3. Therefore TableDefinition.uniqueKeys Vector can have String[] and
> > String type elements. Futhermore, UniqueKeyConstraint type object can
> > be the element of the Vector due to
> > TableDefinition.addUniqueConstraint(UniqueKeyConstraint) method.
> > But TableDefinition.buildUniqueFieldTypes() assumes the element type
> > of the Vector as String[] so ClassCastException can be thrown.
> >
> > Summary of the fix:
> > * Fixed metadata processors to handle columnNames properly and use
> > DatabaseTable.addUniqueConstraints(String[]).
> > * DatabaseTable
> > - Fixed the element type of unqueConstraints to be always String[].
> > - Removed addUniqueConstraint(String columnName) method, because it
> > can used carelessly and addUniqueConstraints(String[] columnNames) is
> > enough.
> > * TableDefinition
> > - Fixed the element type of uniqueKeys to be always
> > UniqueKeyConstraint object.
> > - buildUniqueFieldTypes() is removed and now DefaultTableGenerator add
> > UniqueKeyConstraint object to TableDefinition from
> > DatabaseTable.uniqueConstraints Vector(whose element is now always
> > String[] columnNames).
> >
> > Tests:
> > - Confirmed that the correct unique constraints are generated with
> > newly added models and tests.
> >
> > Thanks
> > -Wonseok
> >
>
> --
> Tom Ware
> Principal Software Engineer
> Oracle Canada Inc.
>
> Direct: (613) 783-4598
> Email: tom.ware_at_oracle.com
>