HHH-15212 Test placeholders in auxiliary object SQL strings

This commit is contained in:
Yoann Rodière 2022-04-27 10:52:46 +02:00
parent d28e300013
commit a057a045d4
3 changed files with 72 additions and 1 deletions

View File

@ -80,7 +80,7 @@ import jakarta.persistence.TableGenerator;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(CustomParameterized.class)
@TestForIssue(jiraKey = { "HHH-14921", "HHH-14922" })
@TestForIssue(jiraKey = { "HHH-14921", "HHH-14922", "HHH-15212" })
public class DefaultCatalogAndSchemaTest {
private static final String SQL_QUOTE_CHARACTER_CLASS = "([`\"]|\\[|\\])";
@ -197,6 +197,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 ) );
}
@ -512,6 +514,15 @@ public class DefaultCatalogAndSchemaTest {
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithExplicitQualifiersWithIncrementGenerator.NAME, expectedExplicitQualifier() );
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithDefaultQualifiersWithEnhancedSequenceGenerator.NAME, expectedDefaultQualifier() );
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithExplicitQualifiersWithEnhancedSequenceGenerator.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 {

View File

@ -0,0 +1,30 @@
<?xml version="1.0"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping http://www.hibernate.org/xsd/hibernate-mapping/hibernate-mapping-4.0.xsd"
package="org.hibernate.test.boot.database.qualfiedTableNaming"
default-access="field">
<database-object>
<!-- Note this code does not actually get executed.
We just generate the script and check that ${catalog} gets replaced correctly.
So the actual language used here does not need to be compatible with the DB dialect under test.
-->
<create>
CREATE OR REPLACE FUNCTION ${catalog}.catalogPrefixedAuxObject()
RETURNS varchar AS
$BODY$
BEGIN
SELECT 'test';
END;
$BODY$
LANGUAGE plpgsql
</create>
<drop>DROP FUNCTION ${catalog}.catalogPrefixedAuxObject()</drop>
</database-object>
</hibernate-mapping>

View File

@ -0,0 +1,30 @@
<?xml version="1.0"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping http://www.hibernate.org/xsd/hibernate-mapping/hibernate-mapping-4.0.xsd"
package="org.hibernate.test.boot.database.qualfiedTableNaming"
default-access="field">
<database-object>
<!-- Note this code does not actually get executed.
We just generate the script and check that ${schema} gets replaced correctly.
So the actual language used here does not need to be compatible with the DB dialect under test.
-->
<create>
CREATE OR REPLACE FUNCTION ${schema}.schemaPrefixedAuxObject()
RETURNS varchar AS
$BODY$
BEGIN
SELECT 'test';
END;
$BODY$
LANGUAGE plpgsql
</create>
<drop>DROP FUNCTION ${schema}.schemaPrefixedAuxObject()</drop>
</database-object>
</hibernate-mapping>