Skip to content

Commit 86ec26c

Browse files
committed
HHH-14270
HHH-14270 GroupedSchemaValidatorImpl / NameSpaceTablesInformation does not find different-case table information in case insensitive environment
1 parent 0cab17a commit 86ec26c

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/NameSpaceTablesInformation.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,11 @@ public NameSpaceTablesInformation(IdentifierHelper identifierHelper) {
2222
}
2323

2424
public void addTableInformation(TableInformation tableInformation) {
25-
tables.put( tableInformation.getName().getTableName().getText(), tableInformation );
25+
tables.put(identifierHelper.toMetaDataObjectName( tableInformation.getName().getTableName()), tableInformation);
2626
}
2727

2828
public TableInformation getTableInformation(Table table) {
29-
String tableName = identifierHelper.toMetaDataObjectName( table.getQualifiedTableName().getTableName() );
30-
if ( tables.containsKey( tableName.toLowerCase() )) {
31-
return tables.get( tableName.toLowerCase() );
32-
}
33-
else if ( tables.containsKey( tableName.toUpperCase() ) ) {
34-
return tables.get( tableName.toUpperCase() );
35-
}
36-
37-
return null;
29+
return tables.get( identifierHelper.toMetaDataObjectName( table.getQualifiedTableName().getTableName() ) );
3830
}
3931

4032
public TableInformation getTableInformation(String tableName) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.tool.schema.extract.spi;
6+
7+
import org.hibernate.boot.model.relational.QualifiedTableName;
8+
import org.hibernate.boot.registry.StandardServiceRegistry;
9+
import org.hibernate.mapping.Table;
10+
import org.hibernate.testing.orm.junit.JiraKey;
11+
import org.hibernate.testing.util.ServiceRegistryUtil;
12+
import org.junit.Assert;
13+
import org.junit.jupiter.api.Test;
14+
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
15+
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
16+
import org.hibernate.tool.schema.extract.internal.TableInformationImpl;
17+
import org.hibernate.boot.model.relational.Namespace.Name;
18+
import org.hibernate.boot.model.naming.Identifier;
19+
import org.mockito.Mockito;
20+
21+
22+
public class NameSpaceTablesInformationTest {
23+
24+
@Test
25+
@JiraKey(value = "HHH-14270")
26+
public void testNameSpaceTablesInformation() {
27+
StandardServiceRegistry ssr = ServiceRegistryUtil.serviceRegistry();
28+
JdbcEnvironment jdbcEnvironment = ssr.getService( JdbcEnvironment.class );
29+
IdentifierHelper identifierHelper = jdbcEnvironment.getIdentifierHelper();
30+
31+
NameSpaceTablesInformation nameSpaceTablesInformation = new NameSpaceTablesInformation(identifierHelper);
32+
Name schemaName = new Name( new Identifier( "-", false ), new Identifier( "-", false ) );
33+
InformationExtractor informationExtractor = Mockito.mock( InformationExtractor.class );
34+
QualifiedTableName tableName = new QualifiedTableName( schemaName, new Identifier( "-", false ) );
35+
36+
TableInformation tableInformation = new TableInformationImpl( informationExtractor, identifierHelper, tableName, false, null );
37+
nameSpaceTablesInformation.addTableInformation( tableInformation );
38+
final Table table = new Table( "orm", tableName.getTableName().getText() );
39+
nameSpaceTablesInformation.getTableInformation( table );
40+
boolean tableMatched = tableInformation.getName().getTableName().getText().equals( tableName.getTableName().getText() );
41+
Assert.assertTrue("Table matched: ", tableMatched);
42+
}
43+
}

0 commit comments

Comments
 (0)