10
10
import java .sql .ResultSet ;
11
11
import java .sql .SQLException ;
12
12
import java .util .ArrayList ;
13
- import java .util .Collection ;
14
13
import java .util .HashMap ;
15
14
import java .util .List ;
16
15
import java .util .Map ;
@@ -106,46 +105,6 @@ public boolean schemaExists(Identifier catalog, Identifier schema) {
106
105
}
107
106
}
108
107
109
- @ Override
110
- public Collection <TableInformation > getTables (Identifier catalog , Identifier schema ) {
111
- try {
112
- final String catalogFilter = determineCatalogFilter ( catalog );
113
- final String schemaFilter = determineSchemaFilter ( schema );
114
-
115
- final List <TableInformation > results = new ArrayList <TableInformation >();
116
-
117
- ResultSet resultSet = extractionContext .getJdbcDatabaseMetaData ().getTables (
118
- catalogFilter ,
119
- schemaFilter ,
120
- null ,
121
- tableTypes
122
- );
123
- try {
124
- while ( resultSet .next () ) {
125
- final TableInformation tableInformation = extractTableInformation (
126
- catalog ,
127
- schema ,
128
- null ,
129
- resultSet
130
- );
131
- results .add ( tableInformation );
132
- }
133
- }
134
- finally {
135
- try {
136
- resultSet .close ();
137
- }
138
- catch (SQLException ignore ) {
139
- }
140
- }
141
-
142
- return results ;
143
- }
144
- catch (SQLException sqlException ) {
145
- throw convertSQLException ( sqlException , "Error accessing table metadata" );
146
- }
147
- }
148
-
149
108
private String determineCatalogFilter (Identifier catalog ) throws SQLException {
150
109
Identifier identifierToUse = catalog ;
151
110
if ( identifierToUse == null ) {
@@ -170,13 +129,13 @@ public TableInformation extractTableInformation(
170
129
Identifier name ,
171
130
ResultSet resultSet ) throws SQLException {
172
131
if ( catalog == null ) {
173
- catalog = identifierHelper ().fromMetaDataCatalogName ( resultSet .getString ( "TABLE_CAT" ) );
132
+ catalog = identifierHelper ().toIdentifier ( resultSet .getString ( "TABLE_CAT" ) );
174
133
}
175
134
if ( schema == null ) {
176
- schema = identifierHelper ().fromMetaDataSchemaName ( resultSet .getString ( "TABLE_SCHEM" ) );
135
+ schema = identifierHelper ().toIdentifier ( resultSet .getString ( "TABLE_SCHEM" ) );
177
136
}
178
137
if ( name == null ) {
179
- name = identifierHelper ().fromMetaDataObjectName ( resultSet .getString ( "TABLE_NAME" ) );
138
+ name = identifierHelper ().toIdentifier ( resultSet .getString ( "TABLE_NAME" ) );
180
139
}
181
140
182
141
final QualifiedTableName tableName = new QualifiedTableName ( catalog , schema , name );
@@ -239,36 +198,31 @@ protected boolean isPhysicalTableType(String tableType) {
239
198
}
240
199
241
200
@ Override
242
- public Iterable <ColumnInformation > getColumns (TableInformation tableInformation ) {
243
- final List <ColumnInformation > results = new ArrayList <ColumnInformation >();
244
-
201
+ public ColumnInformation getColumn (TableInformation tableInformation , Identifier columnIdentifier ) {
245
202
try {
246
203
ResultSet resultSet = extractionContext .getJdbcDatabaseMetaData ().getColumns (
247
204
identifierHelper ().toMetaDataCatalogName ( tableInformation .getName ().getCatalogName () ),
248
205
identifierHelper ().toMetaDataSchemaName ( tableInformation .getName ().getSchemaName () ),
249
206
identifierHelper ().toMetaDataObjectName ( tableInformation .getName ().getTableName () ),
250
- "%"
207
+ extractionContext .getJdbcEnvironment ()
208
+ .getIdentifierHelper ()
209
+ .toMetaDataObjectName ( columnIdentifier )
251
210
);
252
211
253
212
try {
254
- while ( resultSet .next () ) {
255
- final String columnName = resultSet .getString ( "COLUMN_NAME" );
256
- if ( columnName == null ) {
257
- continue ;
258
- }
259
-
260
- results .add (
261
- new ColumnInformationImpl (
262
- tableInformation ,
263
- identifierHelper ().fromMetaDataObjectName ( columnName ),
264
- resultSet .getInt ( "DATA_TYPE" ),
265
- new StringTokenizer ( resultSet .getString ( "TYPE_NAME" ), "() " ).nextToken (),
266
- resultSet .getInt ( "COLUMN_SIZE" ),
267
- resultSet .getInt ("DECIMAL_DIGITS" ),
268
- interpretTruthValue ( resultSet .getString ( "IS_NULLABLE" ) )
269
- )
270
- );
213
+ if ( !resultSet .next () ) {
214
+ return null ;
271
215
}
216
+ return new ColumnInformationImpl (
217
+ tableInformation ,
218
+ identifierHelper ().toIdentifier ( resultSet .getString ( "COLUMN_NAME" ) ),
219
+ resultSet .getInt ( "DATA_TYPE" ),
220
+ new StringTokenizer ( resultSet .getString ( "TYPE_NAME" ), "() " ).nextToken (),
221
+ resultSet .getInt ( "COLUMN_SIZE" ),
222
+ resultSet .getInt ( "DECIMAL_DIGITS" ),
223
+ interpretTruthValue ( resultSet .getString ( "IS_NULLABLE" ) )
224
+ );
225
+
272
226
}
273
227
finally {
274
228
resultSet .close ();
@@ -277,8 +231,6 @@ public Iterable<ColumnInformation> getColumns(TableInformation tableInformation)
277
231
catch (SQLException e ) {
278
232
throw convertSQLException ( e , "Error accessing column metadata: " + tableInformation .getName ().toString () );
279
233
}
280
-
281
- return results ;
282
234
}
283
235
284
236
private TruthValue interpretTruthValue (String nullable ) {
@@ -309,7 +261,7 @@ public PrimaryKeyInformation getPrimaryKey(TableInformationImpl tableInformation
309
261
final String currentPkName = resultSet .getString ( "PK_NAME" );
310
262
final Identifier currentPkIdentifier = currentPkName == null
311
263
? null
312
- : identifierHelper ().fromMetaDataObjectName ( currentPkName );
264
+ : identifierHelper ().toIdentifier ( currentPkName );
313
265
if ( firstPass ) {
314
266
pkIdentifier = currentPkIdentifier ;
315
267
firstPass = false ;
@@ -328,7 +280,7 @@ public PrimaryKeyInformation getPrimaryKey(TableInformationImpl tableInformation
328
280
final int columnPosition = resultSet .getInt ( "KEY_SEQ" );
329
281
final String columnName = resultSet .getString ( "COLUMN_NAME" );
330
282
331
- final Identifier columnIdentifier = identifierHelper ().fromMetaDataObjectName ( columnName );
283
+ final Identifier columnIdentifier = identifierHelper ().toIdentifier ( columnName );
332
284
final ColumnInformation column = tableInformation .getColumn ( columnIdentifier );
333
285
pkColumns .add ( columnPosition -1 , column );
334
286
}
@@ -377,7 +329,7 @@ public Iterable<IndexInformation> getIndexes(TableInformation tableInformation)
377
329
continue ;
378
330
}
379
331
380
- final Identifier indexIdentifier = identifierHelper ().fromMetaDataObjectName (
332
+ final Identifier indexIdentifier = identifierHelper ().toIdentifier (
381
333
resultSet .getString (
382
334
"INDEX_NAME"
383
335
)
@@ -388,7 +340,7 @@ public Iterable<IndexInformation> getIndexes(TableInformation tableInformation)
388
340
builders .put ( indexIdentifier , builder );
389
341
}
390
342
391
- final Identifier columnIdentifier = identifierHelper ().fromMetaDataObjectName ( resultSet .getString ( "COLUMN_NAME" ) );
343
+ final Identifier columnIdentifier = identifierHelper ().toIdentifier ( resultSet .getString ( "COLUMN_NAME" ) );
392
344
final ColumnInformation columnInformation = tableInformation .getColumn ( columnIdentifier );
393
345
if ( columnInformation == null ) {
394
346
throw new SchemaManagementException (
@@ -433,7 +385,7 @@ public Iterable<ForeignKeyInformation> getForeignKeys(TableInformation tableInfo
433
385
try {
434
386
while ( resultSet .next () ) {
435
387
// IMPL NOTE : The builder is mainly used to collect the column reference mappings
436
- final Identifier fkIdentifier = identifierHelper ().fromMetaDataObjectName (
388
+ final Identifier fkIdentifier = identifierHelper ().toIdentifier (
437
389
resultSet .getString ( "FK_NAME" )
438
390
);
439
391
ForeignKeyBuilder fkBuilder = fkBuilders .get ( fkIdentifier );
@@ -455,10 +407,10 @@ public Iterable<ForeignKeyInformation> getForeignKeys(TableInformation tableInfo
455
407
continue ;
456
408
}
457
409
458
- final Identifier fkColumnIdentifier = identifierHelper ().fromMetaDataObjectName (
410
+ final Identifier fkColumnIdentifier = identifierHelper ().toIdentifier (
459
411
resultSet .getString ( "FKCOLUMN_NAME" )
460
412
);
461
- final Identifier pkColumnIdentifier = identifierHelper ().fromMetaDataObjectName (
413
+ final Identifier pkColumnIdentifier = identifierHelper ().toIdentifier (
462
414
resultSet .getString ( "PKCOLUMN_NAME" )
463
415
);
464
416
@@ -529,9 +481,9 @@ private QualifiedTableName extractKeyTableName(ResultSet resultSet, String prefi
529
481
final String incomingTableName = resultSet .getString ( prefix + "TABLE_NAME" );
530
482
531
483
return new QualifiedTableName (
532
- identifierHelper ().fromMetaDataCatalogName ( incomingCatalogName ),
533
- identifierHelper ().fromMetaDataSchemaName ( incomingSchemaName ),
534
- identifierHelper ().fromMetaDataObjectName ( incomingTableName )
484
+ identifierHelper ().toIdentifier ( incomingCatalogName ),
485
+ identifierHelper ().toIdentifier ( incomingSchemaName ),
486
+ identifierHelper ().toIdentifier ( incomingTableName )
535
487
);
536
488
}
537
489
}
0 commit comments