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.uniqueKeysVector.
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