Search in sources :

Example 1 with ContributableMatcher

use of org.hibernate.tool.schema.spi.ContributableMatcher in project hibernate-orm by hibernate.

the class AbstractSchemaMigratorTest method testForeignKeyPreExistenceDetectionIgnoresCaseForTableAndColumnName.

@Test
@TestForIssue(jiraKey = "HHH-13779")
public void testForeignKeyPreExistenceDetectionIgnoresCaseForTableAndColumnName() {
    final AbstractSchemaMigrator schemaMigrator = new AbstractSchemaMigrator(null, null) {

        @Override
        protected NameSpaceTablesInformation performTablesMigration(Metadata metadata, DatabaseInformation existingDatabase, ExecutionOptions options, ContributableMatcher contributableInclusionFilter, Dialect dialect, Formatter formatter, Set<String> exportIdentifiers, boolean tryToCreateCatalogs, boolean tryToCreateSchemas, Set<Identifier> exportedCatalogs, Namespace namespace, SqlStringGenerationContext sqlStringGenerationContext, GenerationTarget[] targets) {
            return null;
        }
    };
    final TableInformation existingTableInformation = mock(TableInformation.class);
    final ArrayList<ForeignKeyInformation.ColumnReferenceMapping> columnReferenceMappings = new ArrayList<>();
    final TableInformation destinationTableInformation = mock(TableInformation.class);
    doReturn(new QualifiedTableName(toIdentifier("catalog"), toIdentifier("schema"), // Table name is lower case
    toIdentifier("referenced_table"))).when(destinationTableInformation).getName();
    columnReferenceMappings.add(new ForeignKeyInformationImpl.ColumnReferenceMappingImpl(new // column name is lower case
    ColumnInformationImpl(// column name is lower case
    null, // column name is lower case
    toIdentifier("referencing_column"), 0, "typeName", 255, 0, TruthValue.TRUE), new ColumnInformationImpl(destinationTableInformation, null, 1, "typeName", 0, 0, TruthValue.TRUE)));
    doReturn(singletonList(new ForeignKeyInformationImpl(toIdentifier("FKp8mpamfw2inhj88hwhty1eipm"), columnReferenceMappings))).when(existingTableInformation).getForeignKeys();
    final boolean existInDatabase = schemaMigrator.equivalentForeignKeyExistsInDatabase(existingTableInformation, "REFERENCING_COLUMN", // Table and column names are UPPER-case here, to prove the test
    "REFERENCED_TABLE");
    assertThat("Expected ForeignKey pre-existence check to be case-insensitive", existInDatabase, is(true));
}
Also used : QualifiedTableName(org.hibernate.boot.model.relational.QualifiedTableName) Set(java.util.Set) SqlStringGenerationContext(org.hibernate.boot.model.relational.SqlStringGenerationContext) Formatter(org.hibernate.engine.jdbc.internal.Formatter) Metadata(org.hibernate.boot.Metadata) ArrayList(java.util.ArrayList) Namespace(org.hibernate.boot.model.relational.Namespace) ColumnInformationImpl(org.hibernate.tool.schema.extract.internal.ColumnInformationImpl) ContributableMatcher(org.hibernate.tool.schema.spi.ContributableMatcher) DatabaseInformation(org.hibernate.tool.schema.extract.spi.DatabaseInformation) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) ForeignKeyInformationImpl(org.hibernate.tool.schema.extract.internal.ForeignKeyInformationImpl) Dialect(org.hibernate.dialect.Dialect) TableInformation(org.hibernate.tool.schema.extract.spi.TableInformation) Test(org.junit.jupiter.api.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Metadata (org.hibernate.boot.Metadata)1 Namespace (org.hibernate.boot.model.relational.Namespace)1 QualifiedTableName (org.hibernate.boot.model.relational.QualifiedTableName)1 SqlStringGenerationContext (org.hibernate.boot.model.relational.SqlStringGenerationContext)1 Dialect (org.hibernate.dialect.Dialect)1 Formatter (org.hibernate.engine.jdbc.internal.Formatter)1 TestForIssue (org.hibernate.testing.TestForIssue)1 ColumnInformationImpl (org.hibernate.tool.schema.extract.internal.ColumnInformationImpl)1 ForeignKeyInformationImpl (org.hibernate.tool.schema.extract.internal.ForeignKeyInformationImpl)1 DatabaseInformation (org.hibernate.tool.schema.extract.spi.DatabaseInformation)1 TableInformation (org.hibernate.tool.schema.extract.spi.TableInformation)1 ContributableMatcher (org.hibernate.tool.schema.spi.ContributableMatcher)1 ExecutionOptions (org.hibernate.tool.schema.spi.ExecutionOptions)1 Test (org.junit.jupiter.api.Test)1