|
@@ -13,8 +13,7 @@ |
13 |
13 |
|
protected static final String[] TYPES_TABLE = new String[]{"TABLE"}; |
14 |
14 |
|
protected static final String[] TYPES_TABLE_AND_VIEW = new String[]{"TABLE", "VIEW"}; |
15 |
15 |
|
|
16 |
|
- |
public static String createAlterColumnRenameSQL( String table, String oldColumnName, |
17 |
|
- |
String newColumnName ) |
|
16 |
+ |
public static String createAlterColumnRenameSQL( String table, String oldColumnName, String newColumnName ) |
18 |
17 |
|
{ |
19 |
18 |
|
return String.format( "ALTER TABLE %s RENAME COLUMN %s TO %s", table, oldColumnName, newColumnName ); |
20 |
19 |
|
} |
|
@@ -29,12 +28,10 @@ |
29 |
28 |
|
return String.format( "ALTER TABLE %s DROP COLUMN %s", pOldTableName, pDropColumnName ); |
30 |
29 |
|
} |
31 |
30 |
|
|
32 |
|
- |
public static String createAlterColumnTypeSQL( String pTableName, String pColumnName, String pNewTypeName, |
33 |
|
- |
String pLength, String pPrecision ) |
|
31 |
+ |
public static String createAlterColumnTypeSQL( String pTableName, String pColumnName, String pNewTypeName, String pLength, String pPrecision ) |
34 |
32 |
|
{ |
35 |
33 |
|
String scaleClause = createScaleClause( pLength, pPrecision ); |
36 |
|
- |
return String.format( "ALTER TABLE %s ALTER COLUMN %s TYPE %s%s", pTableName, pColumnName, |
37 |
|
- |
pNewTypeName, scaleClause ); |
|
34 |
+ |
return String.format( "ALTER TABLE %s ALTER COLUMN %s TYPE %s%s", pTableName, pColumnName, pNewTypeName, scaleClause ); |
38 |
35 |
|
} |
39 |
36 |
|
|
40 |
37 |
|
private static String createScaleClause( String pLength, String pPrecision ) |
|
@@ -69,8 +66,7 @@ |
69 |
66 |
|
|
70 |
67 |
|
public static String createAddDefaultSQL( String pTableName, String pColumnName, String pNewDefaultValue ) |
71 |
68 |
|
{ |
72 |
|
- |
return String.format( "ALTER TABLE %s ALTER COLUMN %s SET DEFAULT '%s'", pTableName, pColumnName, |
73 |
|
- |
pNewDefaultValue ); |
|
69 |
+ |
return String.format( "ALTER TABLE %s ALTER COLUMN %s SET DEFAULT '%s'", pTableName, pColumnName, pNewDefaultValue ); |
74 |
70 |
|
} |
75 |
71 |
|
|
76 |
72 |
|
public static String createDropDefaultSQL( String pTableName, String pColumnName ) |
|
@@ -92,8 +88,7 @@ |
92 |
88 |
|
* creates only a partial clause for use both in an ALTER TABLE statemtent or in a CREATE TABLE statement |
93 |
89 |
|
* <br>Of particular note is that there are no tokens 'CREATE' 'ALTER' or 'COLUMN' |
94 |
90 |
|
*/ |
95 |
|
- |
static String createColumnDefClause( String pName, String pType, String pLength, String pPrecision, |
96 |
|
- |
String pDefaultValue, boolean notNull ) |
|
91 |
+ |
static String createColumnDefClause( String pName, String pType, String pLength, String pPrecision, String pDefaultValue, boolean notNull ) |
97 |
92 |
|
{ |
98 |
93 |
|
String zScaleClause = createScaleClause( pLength, pPrecision ); |
99 |
94 |
|
String zNotNullClause = notNull ? "NOT NULL" : "NULL"; |
|
@@ -106,14 +101,10 @@ |
106 |
101 |
|
return String.format( "%s %s not null primary key", pColumnName, pType ); |
107 |
102 |
|
} |
108 |
103 |
|
|
109 |
|
- |
public static String createAddColumnToExistingTableSQL( String tableName, String pColumnName, |
110 |
|
- |
String pType, String pDefaultValue, |
111 |
|
- |
boolean pNotNull, String pLength, |
112 |
|
- |
String pPrecision ) |
|
104 |
+ |
public static String createAddColumnToExistingTableSQL( String tableName, String pColumnName, String pType, String pDefaultValue, boolean pNotNull, String pLength, String pPrecision ) |
113 |
105 |
|
{ |
114 |
106 |
|
|
115 |
|
- |
String zDefClause = |
116 |
|
- |
createColumnDefClause( pColumnName, pType, pLength, pPrecision, pDefaultValue, pNotNull ); |
|
107 |
+ |
String zDefClause = createColumnDefClause( pColumnName, pType, pLength, pPrecision, pDefaultValue, pNotNull ); |
117 |
108 |
|
return String.format( "ALTER TABLE %s ADD COLUMN %s", tableName, zDefClause ); |
118 |
109 |
|
} |
119 |
110 |
|
|
|
@@ -122,21 +113,17 @@ |
122 |
113 |
|
return String.format( "DROP INDEX IF EXISTS %s ", pIndexName ); |
123 |
114 |
|
} |
124 |
115 |
|
|
125 |
|
- |
public static String createAddIndexSQL( String pTableName, String pIndexName, boolean pUnique, |
126 |
|
- |
String pColumns ) |
|
116 |
+ |
public static String createAddIndexSQL( String pTableName, String pIndexName, boolean pUnique, String pColumns ) |
127 |
117 |
|
{ |
128 |
118 |
|
String zUnique = pUnique ? "UNIQUE" : ""; |
129 |
119 |
|
return String.format( "CREATE %s INDEX %s ON %s ( %s )", zUnique, pIndexName, pTableName, pColumns ); |
130 |
120 |
|
} |
131 |
121 |
|
|
132 |
|
- |
public static String createAddForeignKeySQL( String pTableName, String pColumnName, String pType, |
133 |
|
- |
String pReferenceTable, String pReferenceColumn, |
134 |
|
- |
boolean pRequired ) |
|
122 |
+ |
public static String createAddForeignKeySQL( String pTableName, String pColumnName, String pType, String pReferenceTable, String pReferenceColumn, boolean pRequired ) |
135 |
123 |
|
{ |
136 |
124 |
|
String zColumnRef = null == pReferenceColumn ? "" : "(" + pReferenceColumn + ")"; |
137 |
125 |
|
String zRequired = pRequired ? "NOT NULL" : "NULL"; |
138 |
|
- |
return String.format( "ALTER TABLE %s ADD COLUMN %s %s REFERENCES %s %s %s", pTableName, pColumnName, |
139 |
|
- |
pType, pReferenceTable, zColumnRef, zRequired ); |
|
126 |
+ |
return String.format( "ALTER TABLE %s ADD COLUMN %s %s REFERENCES %s %s %s", pTableName, pColumnName, pType, pReferenceTable, zColumnRef, zRequired ); |
140 |
127 |
|
} |
141 |
128 |
|
|
142 |
129 |
|
public static String escapePercent( String pString ) |
|
@@ -202,8 +189,7 @@ |
202 |
189 |
|
/** |
203 |
190 |
|
* @return !null list of "Tables" for the Connection's Catalog, which will be "character cased" per the DB Vendor's "Table Character Case Stretegy" |
204 |
191 |
|
*/ |
205 |
|
- |
public static List<String> getAllTableNamesOfTypes( Connection pConnection, String pTableNamePattern, |
206 |
|
- |
String[] pTypes ) |
|
192 |
+ |
public static List<String> getAllTableNamesOfTypes( Connection pConnection, String pTableNamePattern, String[] pTypes ) |
207 |
193 |
|
throws SQLException |
208 |
194 |
|
{ |
209 |
195 |
|
DatabaseMetaData zMetaData = pConnection.getMetaData(); |
|
@@ -218,8 +204,7 @@ |
218 |
204 |
|
return names; |
219 |
205 |
|
} |
220 |
206 |
|
|
221 |
|
- |
public static Map<String, DBtableColumn[]> getAllTableColumns( Connection pConnection, |
222 |
|
- |
String pTableNamePattern ) |
|
207 |
+ |
public static Map<String, DBtableColumn[]> getAllTableColumns( Connection pConnection, String pTableNamePattern ) |
223 |
208 |
|
throws SQLException |
224 |
209 |
|
{ |
225 |
210 |
|
DatabaseMetaData zMetaData = pConnection.getMetaData(); |
|
@@ -352,8 +337,7 @@ |
352 |
337 |
|
{ |
353 |
338 |
|
if ( (mName != null) && !zColumnNames.isEmpty() ) |
354 |
339 |
|
{ |
355 |
|
- |
mCollector.add( new DBtableIndex( mName, mUnique, |
356 |
|
- |
zColumnNames.toArray( new String[zColumnNames.size()] ) ) ); |
|
340 |
+ |
mCollector.add( new DBtableIndex( mName, mUnique, zColumnNames.toArray( new String[zColumnNames.size()] ) ) ); |
357 |
341 |
|
} |
358 |
342 |
|
} |
359 |
343 |
|
} |
|
@@ -374,8 +358,7 @@ |
374 |
358 |
|
// columnNoNulls - might not allow NULL values |
375 |
359 |
|
// columnNullable - definitely allows NULL values |
376 |
360 |
|
// columnNullableUnknown - nullability unknown |
377 |
|
- |
public void apply( String pTableName, String pColumnName, int pSqlTypesType, int pColumnSize, |
378 |
|
- |
int pDecimalDigits, int pNullable ) |
|
361 |
+ |
public void apply( String pTableName, String pColumnName, int pSqlTypesType, int pColumnSize, int pDecimalDigits, int pNullable ) |
379 |
362 |
|
{ |
380 |
363 |
|
if ( !pTableName.equals( mTableName ) ) |
381 |
364 |
|
{ |
|
@@ -418,8 +401,7 @@ |
418 |
401 |
|
break; |
419 |
402 |
|
} |
420 |
403 |
|
|
421 |
|
- |
zColumns.add( |
422 |
|
- |
new DBtableColumn( pColumnName, pSqlTypesType, zColumnSize, zDecimalDigits, zNullable ) ); |
|
404 |
+ |
zColumns.add( new DBtableColumn( pColumnName, pSqlTypesType, zColumnSize, zDecimalDigits, zNullable ) ); |
423 |
405 |
|
} |
424 |
406 |
|
|
425 |
407 |
|
public Map<String, DBtableColumn[]> getReturnValue() |