37
37
import org .hibernate .boot .model .TruthValue ;
38
38
import org .hibernate .boot .model .naming .Identifier ;
39
39
import org .hibernate .boot .model .relational .QualifiedTableName ;
40
- import org .hibernate .boot .model .relational .Schema ;
41
40
import org .hibernate .cfg .AvailableSettings ;
42
41
import org .hibernate .engine .config .spi .ConfigurationService ;
43
42
import org .hibernate .engine .jdbc .env .spi .IdentifierHelper ;
@@ -140,7 +139,12 @@ public Collection<TableInformation> getTables(Identifier catalog, Identifier sch
140
139
);
141
140
try {
142
141
while ( resultSet .next () ) {
143
- final TableInformation tableInformation = extractTableInformation ( resultSet );
142
+ final TableInformation tableInformation = extractTableInformation (
143
+ catalog ,
144
+ schema ,
145
+ null ,
146
+ resultSet
147
+ );
144
148
results .add ( tableInformation );
145
149
}
146
150
}
@@ -177,20 +181,23 @@ private String determineSchemaFilter(Identifier schema) throws SQLException {
177
181
return extractionContext .getJdbcEnvironment ().getIdentifierHelper ().toMetaDataSchemaName ( identifierToUse );
178
182
}
179
183
180
- public TableInformation extractTableInformation (ResultSet resultSet ) throws SQLException {
181
- final Identifier catalogIdentifier = identifierHelper ().fromMetaDataCatalogName (
182
- resultSet .getString ( "TABLE_CAT" )
183
- );
184
- final Identifier schemaIdentifier = identifierHelper ().fromMetaDataSchemaName (
185
- resultSet .getString ( "TABLE_SCHEM" )
186
- );
187
- final Identifier tableIdentifier = identifierHelper ().fromMetaDataObjectName (
188
- resultSet .getString ( "TABLE_NAME" )
189
- );
190
- final QualifiedTableName tableName = new QualifiedTableName (
191
- new Schema .Name ( catalogIdentifier , schemaIdentifier ),
192
- tableIdentifier
193
- );
184
+ public TableInformation extractTableInformation (
185
+ Identifier catalog ,
186
+ Identifier schema ,
187
+ Identifier name ,
188
+ ResultSet resultSet ) throws SQLException {
189
+ if ( catalog == null ) {
190
+ catalog = identifierHelper ().fromMetaDataCatalogName ( resultSet .getString ( "TABLE_CAT" ) );
191
+ }
192
+ if ( schema == null ) {
193
+ schema = identifierHelper ().fromMetaDataSchemaName ( resultSet .getString ( "TABLE_SCHEM" ) );
194
+ }
195
+ if ( name == null ) {
196
+ name = identifierHelper ().fromMetaDataObjectName ( resultSet .getString ( "TABLE_NAME" ) );
197
+ }
198
+
199
+ final QualifiedTableName tableName = new QualifiedTableName ( catalog , schema , name );
200
+
194
201
return new TableInformationImpl (
195
202
this ,
196
203
tableName ,
@@ -218,7 +225,12 @@ public TableInformation getTable(Identifier catalog, Identifier schema, Identifi
218
225
return null ;
219
226
}
220
227
221
- final TableInformation tableInformation = extractTableInformation ( resultSet );
228
+ final TableInformation tableInformation = extractTableInformation (
229
+ catalog ,
230
+ schema ,
231
+ tableName ,
232
+ resultSet
233
+ );
222
234
223
235
if ( resultSet .next () ) {
224
236
log .multipleTablesFound ( tableName .render () );
@@ -265,7 +277,7 @@ public Iterable<ColumnInformation> getColumns(TableInformation tableInformation)
265
277
results .add (
266
278
new ColumnInformationImpl (
267
279
tableInformation ,
268
- Identifier . toIdentifier ( columnName ),
280
+ identifierHelper (). fromMetaDataObjectName ( columnName ),
269
281
resultSet .getInt ( "DATA_TYPE" ),
270
282
new StringTokenizer ( resultSet .getString ( "TYPE_NAME" ), "() " ).nextToken (),
271
283
resultSet .getInt ( "COLUMN_SIZE" ),
@@ -382,14 +394,18 @@ public Iterable<IndexInformation> getIndexes(TableInformation tableInformation)
382
394
continue ;
383
395
}
384
396
385
- final Identifier indexIdentifier = Identifier .toIdentifier ( resultSet .getString ( "INDEX_NAME" ) );
397
+ final Identifier indexIdentifier = identifierHelper ().fromMetaDataObjectName (
398
+ resultSet .getString (
399
+ "INDEX_NAME"
400
+ )
401
+ );
386
402
IndexInformationImpl .Builder builder = builders .get ( indexIdentifier );
387
403
if ( builder == null ) {
388
404
builder = IndexInformationImpl .builder ( indexIdentifier );
389
405
builders .put ( indexIdentifier , builder );
390
406
}
391
407
392
- final Identifier columnIdentifier = Identifier . toIdentifier ( resultSet .getString ( "COLUMN_NAME" ) );
408
+ final Identifier columnIdentifier = identifierHelper (). fromMetaDataObjectName ( resultSet .getString ( "COLUMN_NAME" ) );
393
409
final ColumnInformation columnInformation = tableInformation .getColumn ( columnIdentifier );
394
410
if ( columnInformation == null ) {
395
411
throw new SchemaManagementException (
@@ -434,7 +450,9 @@ public Iterable<ForeignKeyInformation> getForeignKeys(TableInformation tableInfo
434
450
try {
435
451
while ( resultSet .next () ) {
436
452
// IMPL NOTE : The builder is mainly used to collect the column reference mappings
437
- final Identifier fkIdentifier = Identifier .toIdentifier ( resultSet .getString ( "FK_NAME" ) );
453
+ final Identifier fkIdentifier = identifierHelper ().fromMetaDataObjectName (
454
+ resultSet .getString ( "FK_NAME" )
455
+ );
438
456
ForeignKeyBuilder fkBuilder = fkBuilders .get ( fkIdentifier );
439
457
if ( fkBuilder == null ) {
440
458
fkBuilder = generateForeignKeyBuilder ( fkIdentifier );
@@ -454,8 +472,12 @@ public Iterable<ForeignKeyInformation> getForeignKeys(TableInformation tableInfo
454
472
continue ;
455
473
}
456
474
457
- final Identifier fkColumnIdentifier = Identifier .toIdentifier ( resultSet .getString ( "FKCOLUMN_NAME" ) );
458
- final Identifier pkColumnIdentifier = Identifier .toIdentifier ( resultSet .getString ( "PKCOLUMN_NAME" ) );
475
+ final Identifier fkColumnIdentifier = identifierHelper ().fromMetaDataObjectName (
476
+ resultSet .getString ( "FKCOLUMN_NAME" )
477
+ );
478
+ final Identifier pkColumnIdentifier = identifierHelper ().fromMetaDataObjectName (
479
+ resultSet .getString ( "PKCOLUMN_NAME" )
480
+ );
459
481
460
482
fkBuilder .addColumnMapping (
461
483
tableInformation .getColumn ( fkColumnIdentifier ),
@@ -486,10 +508,10 @@ private ForeignKeyBuilder generateForeignKeyBuilder(Identifier fkIdentifier) {
486
508
return new ForeignKeyBuilderImpl ( fkIdentifier );
487
509
}
488
510
489
- protected static interface ForeignKeyBuilder {
490
- public ForeignKeyBuilder addColumnMapping (ColumnInformation referencing , ColumnInformation referenced );
511
+ protected interface ForeignKeyBuilder {
512
+ ForeignKeyBuilder addColumnMapping (ColumnInformation referencing , ColumnInformation referenced );
491
513
492
- public ForeignKeyInformation build ();
514
+ ForeignKeyInformation build ();
493
515
}
494
516
495
517
protected static class ForeignKeyBuilderImpl implements ForeignKeyBuilder {
@@ -524,11 +546,9 @@ private QualifiedTableName extractKeyTableName(ResultSet resultSet, String prefi
524
546
final String incomingTableName = resultSet .getString ( prefix + "TABLE_NAME" );
525
547
526
548
return new QualifiedTableName (
527
- new Schema .Name (
528
- Identifier .toIdentifier ( incomingCatalogName ),
529
- Identifier .toIdentifier ( incomingSchemaName )
530
- ),
531
- Identifier .toIdentifier ( incomingTableName )
549
+ identifierHelper ().fromMetaDataCatalogName ( incomingCatalogName ),
550
+ identifierHelper ().fromMetaDataSchemaName ( incomingSchemaName ),
551
+ identifierHelper ().fromMetaDataObjectName ( incomingTableName )
532
552
);
533
553
}
534
554
}
0 commit comments