Fix test failure after merge

This commit is contained in:
Andrea Boriero 2021-09-24 13:17:25 +02:00
parent 0b9a470685
commit 70c09dfb54
3 changed files with 28 additions and 16 deletions

View File

@ -9,6 +9,7 @@ package org.hibernate.dialect;
import org.hibernate.*; import org.hibernate.*;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
import org.hibernate.boot.model.relational.QualifiedSequenceName; import org.hibernate.boot.model.relational.QualifiedSequenceName;
import org.hibernate.boot.model.relational.Sequence;
import org.hibernate.dialect.function.CommonFunctionFactory; import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.function.SQLServerFormatEmulation; import org.hibernate.dialect.function.SQLServerFormatEmulation;
import org.hibernate.dialect.identity.IdentityColumnSupport; import org.hibernate.dialect.identity.IdentityColumnSupport;
@ -42,6 +43,7 @@ import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
import org.hibernate.sql.ast.tree.Statement; import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.tool.schema.internal.StandardSequenceExporter; import org.hibernate.tool.schema.internal.StandardSequenceExporter;
import org.hibernate.tool.schema.spi.Exporter;
import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.SmallIntTypeDescriptor; import org.hibernate.type.descriptor.jdbc.SmallIntTypeDescriptor;
@ -66,6 +68,8 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
private final int version; private final int version;
private StandardSequenceExporter exporter;
public SQLServerDialect(DialectResolutionInfo info) { public SQLServerDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() ); this( info.getDatabaseMajorVersion() );
} }
@ -89,8 +93,8 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
registerColumnType( Types.TIMESTAMP_WITH_TIMEZONE, "datetimeoffset($p)" ); registerColumnType( Types.TIMESTAMP_WITH_TIMEZONE, "datetimeoffset($p)" );
} }
if(getVersion() >= 11) { if ( getVersion() >= 11 ) {
sequenceExporter = new SqlServerSequenceExporter( this ); exporter = new SqlServerSequenceExporter( this );
} }
registerColumnType( Types.VARCHAR, 8000, "varchar($l)" ); registerColumnType( Types.VARCHAR, 8000, "varchar($l)" );
@ -787,6 +791,13 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
return NameQualifierSupport.BOTH; return NameQualifierSupport.BOTH;
} }
public Exporter<Sequence> getSequenceExporter() {
if ( exporter == null ) {
return super.getSequenceExporter();
}
return exporter;
}
private class SqlServerSequenceExporter extends StandardSequenceExporter { private class SqlServerSequenceExporter extends StandardSequenceExporter {
public SqlServerSequenceExporter(Dialect dialect) { public SqlServerSequenceExporter(Dialect dialect) {

View File

@ -25,7 +25,7 @@ public class StandardSequenceExporter implements Exporter<Sequence> {
@Override @Override
public String[] getSqlCreateStrings(Sequence sequence, Metadata metadata) { public String[] getSqlCreateStrings(Sequence sequence, Metadata metadata) {
return dialect.getCreateSequenceStrings( return dialect.getSequenceSupport().getCreateSequenceStrings(
getFormattedSequenceName( sequence.getName(), metadata ), getFormattedSequenceName( sequence.getName(), metadata ),
sequence.getInitialValue(), sequence.getInitialValue(),
sequence.getIncrementSize() sequence.getIncrementSize()
@ -34,7 +34,7 @@ public class StandardSequenceExporter implements Exporter<Sequence> {
@Override @Override
public String[] getSqlDropStrings(Sequence sequence, Metadata metadata) { public String[] getSqlDropStrings(Sequence sequence, Metadata metadata) {
return dialect.getDropSequenceStrings( return dialect.getSequenceSupport().getDropSequenceStrings(
getFormattedSequenceName( sequence.getName(), metadata ) getFormattedSequenceName( sequence.getName(), metadata )
); );
} }

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.schemaupdate; package org.hibernate.orm.test.schemaupdate;
import java.util.EnumSet; import java.util.EnumSet;
import javax.persistence.Entity; import javax.persistence.Entity;
@ -17,27 +17,28 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.dialect.SQLServer2012Dialect; import org.hibernate.dialect.SQLServer2012Dialect;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport; import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType; import org.hibernate.tool.schema.TargetType;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.CustomRunner; import org.hibernate.testing.orm.junit.BaseUnitTest;
import org.junit.After; import org.hibernate.testing.orm.junit.RequiresDialect;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
/** /**
* @author Andrea Boriero * @author Andrea Boriero
*/ */
@TestForIssue(jiraKey = "HHH-14835") @TestForIssue(jiraKey = "HHH-14835")
@RunWith(CustomRunner.class) @BaseUnitTest
@RequiresDialect(SQLServer2012Dialect.class) @RequiresDialect(value = SQLServerDialect.class, version = 12)
public class SchemaExportSqlServerWithSequenceDefaultSchemaCatalog { public class SchemaExportSqlServerWithSequenceDefaultSchemaCatalog {
protected ServiceRegistry serviceRegistry; protected ServiceRegistry serviceRegistry;
protected MetadataImplementor metadata; protected MetadataImplementor metadata;
@ -49,7 +50,7 @@ public class SchemaExportSqlServerWithSequenceDefaultSchemaCatalog {
assertThat( schemaExport.getExceptions().size(), is( 0 ) ); assertThat( schemaExport.getExceptions().size(), is( 0 ) );
} }
@Before @BeforeEach
public void setUp() { public void setUp() {
serviceRegistry = new StandardServiceRegistryBuilder() serviceRegistry = new StandardServiceRegistryBuilder()
.applySetting( Environment.DEFAULT_SCHEMA, "dbo" ) .applySetting( Environment.DEFAULT_SCHEMA, "dbo" )
@ -65,7 +66,7 @@ public class SchemaExportSqlServerWithSequenceDefaultSchemaCatalog {
} }
@After @AfterEach
public void tearDown() { public void tearDown() {
System.out.println( "********* Starting SchemaExport (drop) for TEAR-DOWN *************************" ); System.out.println( "********* Starting SchemaExport (drop) for TEAR-DOWN *************************" );
new SchemaExport().drop( EnumSet.of( TargetType.DATABASE, TargetType.STDOUT ), metadata ); new SchemaExport().drop( EnumSet.of( TargetType.DATABASE, TargetType.STDOUT ), metadata );