@@ -171,7 +171,6 @@ public Object[] getQueryArguments(String table)
171
171
* The CREATE TABLE statement.
172
172
* @throws java.sql.SQLException
173
173
* @throws SQLException
174
- * @throws IllegalArgumentException
175
174
* @throws WrappedTargetException
176
175
* @throws IndexOutOfBoundsException
177
176
* @throws UnknownPropertyException
@@ -181,7 +180,7 @@ public static List<String> getCreateTableQueries(DriverProvider provider,
181
180
String table ,
182
181
ComposeRule rule ,
183
182
boolean sensitive )
184
- throws java .sql .SQLException , SQLException , IllegalArgumentException , WrappedTargetException , IndexOutOfBoundsException , UnknownPropertyException
183
+ throws java .sql .SQLException , SQLException , WrappedTargetException , IndexOutOfBoundsException , UnknownPropertyException
185
184
{
186
185
String separator = ", " ;
187
186
boolean hasAutoIncrement = false ;
@@ -217,7 +216,7 @@ public static List<String> getCreateTableQueries(DriverProvider provider,
217
216
// XXX: If the underlying driver allows it, we create the primary key in a DDL command
218
217
// XXX: separate from the one that creates the table. But there are specific cases!!!
219
218
boolean autopk = provider .isAutoIncrementIsPrimaryKey ();
220
- boolean alterpk = provider .isPrimaryKeyAlterable ();
219
+ boolean alterpk = provider .supportsAlterPrimaryKey ();
221
220
// XXX: MariaDB only permit to create auto increment if the PK is created while the table creation (second test)
222
221
if ((alterpk && !autopk ) || (alterpk && autopk && !hasAutoIncrement )) {
223
222
queries .addAll (0 , getCreateConstraintQueries (provider , property , property , "" , rule , sensitive ));
@@ -270,10 +269,6 @@ private static String getColumnDescriptionQuery(DriverProvider provider,
270
269
* The binary result (ie: 1 -> renamed, 2 -> type changed ...)
271
270
* @throws java.sql.SQLException
272
271
* @throws SQLException
273
- * @throws IllegalArgumentException
274
- * @throws WrappedTargetException
275
- * @throws IndexOutOfBoundsException
276
- * @throws UnknownPropertyException
277
272
*/
278
273
// XXX: This method is called from 2 places:
279
274
// XXX: - ColumnContainerBase.createColumn() for any new column.
@@ -321,9 +316,13 @@ public static byte getAlterColumnQueries(List<String> queries,
321
316
boolean autochanged = auto1 != auto2 && provider .supportsAlterIdentity ();
322
317
323
318
// XXX: Type have been changed
324
- String type1 = DBTools .getDescriptorStringValue (descriptor1 , PropertyIds .TYPENAME );
325
- String type2 = DBTools .getDescriptorStringValue (descriptor2 , PropertyIds .TYPENAME );
326
- boolean typechanged = !type2 .equals (type1 );
319
+ boolean typechanged = false ;
320
+ // XXX: Changing column type is only allowed if the underlying driver supports it.
321
+ if (provider .supportsAlterColumnType ()) {
322
+ String type1 = DBTools .getDescriptorStringValue (descriptor1 , PropertyIds .TYPENAME );
323
+ String type2 = DBTools .getDescriptorStringValue (descriptor2 , PropertyIds .TYPENAME );
324
+ typechanged = !type2 .equals (type1 );
325
+ }
327
326
328
327
boolean alldone = false ;
329
328
List <String > parts = new ArrayList <String >();
@@ -372,35 +371,36 @@ public static byte getAlterColumnQueries(List<String> queries,
372
371
}
373
372
queries .addAll (parts );
374
373
375
- boolean altercolumn = provider .isColumnPropertyAlterable ();
376
- String default1 = DBTools .getDescriptorStringValue (descriptor1 , PropertyIds .DEFAULTVALUE );
377
- String default2 = DBTools .getDescriptorStringValue (descriptor2 , PropertyIds .DEFAULTVALUE );
378
- boolean defaultchanged = !default2 .equals (default1 );
379
- //FIXME: Primary key & auto-increment column don't have to handle Default property
380
- if (altercolumn && !alterpk && !alldone && defaultchanged ) {
381
- if (default2 .isBlank ()) {
382
- query = provider .getColumnResetDefaultQuery ();
383
- }
384
- else {
385
- query = DBDefaultQuery .STR_QUERY_ALTER_COLUMN_SET_DEFAULT ;
374
+ // XXX: Primary key & auto-increment column don't have to handle Default and Not Null property,
375
+ // XXX: and some underlying driver doesn't support alteration of column.
376
+ if (!alldone && !alterpk && !auto2 && provider .supportsAlterColumnProperty ()) {
377
+ String default1 = DBTools .getDescriptorStringValue (descriptor1 , PropertyIds .DEFAULTVALUE );
378
+ String default2 = DBTools .getDescriptorStringValue (descriptor2 , PropertyIds .DEFAULTVALUE );
379
+ boolean defaultchanged = !default2 .equals (default1 );
380
+ if (defaultchanged ) {
381
+ if (default2 .isBlank ()) {
382
+ query = provider .getColumnResetDefaultQuery ();
383
+ }
384
+ else {
385
+ query = DBDefaultQuery .STR_QUERY_ALTER_COLUMN_SET_DEFAULT ;
386
+ }
387
+ queries .add (MessageFormat .format (query , arguments ));
388
+ result |= 8 ;
386
389
}
387
- queries .add (MessageFormat .format (query , arguments ));
388
- result |= 8 ;
389
- }
390
390
391
- int nullable1 = DBTools .getDescriptorIntegerValue (descriptor1 , PropertyIds .ISNULLABLE );
392
- int nullable2 = DBTools .getDescriptorIntegerValue (descriptor2 , PropertyIds .ISNULLABLE );
393
- boolean nullablechanged = nullable2 != nullable1 ;
394
- //FIXME: Primary key & auto-increment column don't have to handle Not Null property
395
- if (altercolumn && !alterpk && !alldone && nullablechanged ) {
396
- if (nullable2 == ColumnValue .NO_NULLS ) {
397
- query = DBDefaultQuery .STR_QUERY_ALTER_COLUMN_SET_NOT_NULL ;
398
- }
399
- else {
400
- query = DBDefaultQuery .STR_QUERY_ALTER_COLUMN_DROP_NOT_NULL ;
391
+ int nullable1 = DBTools .getDescriptorIntegerValue (descriptor1 , PropertyIds .ISNULLABLE );
392
+ int nullable2 = DBTools .getDescriptorIntegerValue (descriptor2 , PropertyIds .ISNULLABLE );
393
+ boolean nullablechanged = nullable2 != nullable1 ;
394
+ if (nullablechanged ) {
395
+ if (nullable2 == ColumnValue .NO_NULLS ) {
396
+ query = DBDefaultQuery .STR_QUERY_ALTER_COLUMN_SET_NOT_NULL ;
397
+ }
398
+ else {
399
+ query = DBDefaultQuery .STR_QUERY_ALTER_COLUMN_DROP_NOT_NULL ;
400
+ }
401
+ queries .add (MessageFormat .format (query , arguments ));
402
+ result |= 16 ;
401
403
}
402
- queries .add (MessageFormat .format (query , arguments ));
403
- result |= 16 ;
404
404
}
405
405
}
406
406
0 commit comments