From 863369c08e5ea2ac4847e852ab50fbcb273deae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Wed, 27 Apr 2022 10:52:46 +0200 Subject: [PATCH] HHH-15212 Test placeholders in auxiliary object SQL strings --- .../DefaultCatalogAndSchemaTest.java | 14 +++++++-- ...e-object-using-catalog-placeholder.hbm.xml | 30 +++++++++++++++++++ ...se-object-using-schema-placeholder.hbm.xml | 30 +++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 hibernate-core/src/test/resources/org/hibernate/test/boot/database/qualfiedTableNaming/database-object-using-catalog-placeholder.hbm.xml create mode 100644 hibernate-core/src/test/resources/org/hibernate/test/boot/database/qualfiedTableNaming/database-object-using-schema-placeholder.hbm.xml diff --git a/hibernate-core/src/test/java/org/hibernate/test/boot/database/qualfiedTableNaming/DefaultCatalogAndSchemaTest.java b/hibernate-core/src/test/java/org/hibernate/test/boot/database/qualfiedTableNaming/DefaultCatalogAndSchemaTest.java index b5ae33c259..9c7c2113a8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/boot/database/qualfiedTableNaming/DefaultCatalogAndSchemaTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/boot/database/qualfiedTableNaming/DefaultCatalogAndSchemaTest.java @@ -65,7 +65,6 @@ import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy; import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy; import org.hibernate.id.IdentifierGenerator; import org.hibernate.persister.entity.AbstractEntityPersister; -import org.hibernate.persister.entity.EntityPersister; import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.tool.hbm2ddl.SchemaExport; import org.hibernate.tool.schema.TargetType; @@ -86,7 +85,7 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @RunWith(CustomParameterized.class) -@TestForIssue(jiraKey = { "HHH-14921", "HHH-14922" }) +@TestForIssue(jiraKey = { "HHH-14921", "HHH-14922", "HHH-15212" }) @SkipForDialect(value = SybaseDialect.class, comment = "Sybase doesn't support sequences") @SkipForDialect(value = MySQLDialect.class, comment = "MySQL doesn't support sequences") @SkipForDialect(value = MariaDB53Dialect.class, strictMatching = true, @@ -217,6 +216,8 @@ public class DefaultCatalogAndSchemaTest { final MetadataSources metadataSources = new MetadataSources( serviceRegistry ); metadataSources.addInputStream( getClass().getResourceAsStream( "implicit-file-level-catalog-and-schema.orm.xml" ) ); metadataSources.addInputStream( getClass().getResourceAsStream( "implicit-file-level-catalog-and-schema.hbm.xml" ) ); + metadataSources.addInputStream( getClass().getResourceAsStream( "database-object-using-catalog-placeholder.hbm.xml" ) ); + metadataSources.addInputStream( getClass().getResourceAsStream( "database-object-using-schema-placeholder.hbm.xml" ) ); if ( configuredXmlMappingPath != null ) { metadataSources.addInputStream( getClass().getResourceAsStream( configuredXmlMappingPath ) ); } @@ -585,6 +586,15 @@ public class DefaultCatalogAndSchemaTest { verifyOnlyQualifier( sql, SqlType.DDL, EntityWithExplicitQualifiersWithEnhancedSequenceGenerator.NAME, expectedExplicitQualifier() ); verifyOnlyQualifier( sql, SqlType.DDL, EntityWithDefaultQualifiersWithLegacySequenceGenerator.NAME, expectedDefaultQualifier() ); verifyOnlyQualifier( sql, SqlType.DDL, EntityWithExplicitQualifiersWithLegacySequenceGenerator.NAME, expectedExplicitQualifier() ); + + if ( dbSupportsCatalogs && expectedDefaultCatalog != null ) { + verifyOnlyQualifier( sql, SqlType.DDL, "catalogPrefixedAuxObject", + expectedQualifier( expectedDefaultCatalog, null ) ); + } + if ( dbSupportsSchemas && expectedDefaultSchema != null ) { + verifyOnlyQualifier( sql, SqlType.DDL, "schemaPrefixedAuxObject", + expectedQualifier( null, expectedDefaultSchema ) ); + } } private enum SqlType { diff --git a/hibernate-core/src/test/resources/org/hibernate/test/boot/database/qualfiedTableNaming/database-object-using-catalog-placeholder.hbm.xml b/hibernate-core/src/test/resources/org/hibernate/test/boot/database/qualfiedTableNaming/database-object-using-catalog-placeholder.hbm.xml new file mode 100644 index 0000000000..ee1e9f593d --- /dev/null +++ b/hibernate-core/src/test/resources/org/hibernate/test/boot/database/qualfiedTableNaming/database-object-using-catalog-placeholder.hbm.xml @@ -0,0 +1,30 @@ + + + + + + + CREATE OR REPLACE FUNCTION ${catalog}.catalogPrefixedAuxObject() + RETURNS varchar AS + $BODY$ + BEGIN + SELECT 'test'; + END; + $BODY$ + LANGUAGE plpgsql + + DROP FUNCTION ${catalog}.catalogPrefixedAuxObject() + + diff --git a/hibernate-core/src/test/resources/org/hibernate/test/boot/database/qualfiedTableNaming/database-object-using-schema-placeholder.hbm.xml b/hibernate-core/src/test/resources/org/hibernate/test/boot/database/qualfiedTableNaming/database-object-using-schema-placeholder.hbm.xml new file mode 100644 index 0000000000..b9e36a015e --- /dev/null +++ b/hibernate-core/src/test/resources/org/hibernate/test/boot/database/qualfiedTableNaming/database-object-using-schema-placeholder.hbm.xml @@ -0,0 +1,30 @@ + + + + + + + CREATE OR REPLACE FUNCTION ${schema}.schemaPrefixedAuxObject() + RETURNS varchar AS + $BODY$ + BEGIN + SELECT 'test'; + END; + $BODY$ + LANGUAGE plpgsql + + DROP FUNCTION ${schema}.schemaPrefixedAuxObject() + +