@ Override // from DatabaseLiaison public boolean createTableIfMissing ( Connection conn , String table , List < String > columns , List < ColumnDefinition > defns , List < List < String > > uniqueColumns , List < String > pkColumns ) throws SQLException { if ( columns . size ( ) != defns . size ( ) ) { throw new IllegalArgumentException ( "Column name and definition number mismatch" ) ; } // note the set of single column unique constraints already provided (see method comment) Set < String > seenUniques = new HashSet < String > ( ) ; if ( uniqueColumns != null ) { for ( List < String > udef : uniqueColumns ) { if ( udef . size ( ) == 1 ) { seenUniques . addAll ( udef ) ; } } } // primary key columns are also considered implicitly unique as of HSQL 2.2.4, and it will // freak out if we also try to include them in the UNIQUE clause, so add those too seenUniques . addAll ( pkColumns ) ; // lazily create a copy of uniqueColumns, if needed List < List < String > > newUniques = uniqueColumns ; // go through the columns and find any that are unique; these we replace with a non-unique // variant, and instead add a new entry to the table unique constraint List < ColumnDefinition > newDefns = new ArrayList < ColumnDefinition > ( defns . size ( ) ) ; for ( int ii = 0 ; ii < defns . size ( ) ; ii ++ ) { ColumnDefinition def = defns . get ( ii ) ; if ( ! def . unique ) { newDefns . add ( def ) ; continue ; } // let's be nice and not mutate the caller's object newDefns . add ( new ColumnDefinition ( def . type , def . nullable , false , def . defaultValue ) ) ; // if a uniqueness constraint for this column was not in the primaryKeys or // uniqueColumns parameters, add the column to uniqueCsts if ( ! seenUniques . contains ( columns . get ( ii ) ) ) { if ( newUniques == uniqueColumns ) { newUniques = new ArrayList < List < String > > ( uniqueColumns ) ; } newUniques . add ( Collections . singletonList ( columns . get ( ii ) ) ) ; } } // now call the real implementation with our modified data return super . createTableIfMissing ( conn , table , columns , newDefns , newUniques , pkColumns ) ; }
it may be that uniqueness should be removed from ColumnDefinition .