Skip to content

Commit

Permalink
Fix test failure after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 committed Sep 24, 2021
1 parent 0b9a470 commit 70c09df
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
Expand Up @@ -9,6 +9,7 @@
import org.hibernate.*;
import org.hibernate.boot.Metadata;
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.SQLServerFormatEmulation;
import org.hibernate.dialect.identity.IdentityColumnSupport;
Expand Down Expand Up @@ -42,6 +43,7 @@
import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.tool.schema.internal.StandardSequenceExporter;
import org.hibernate.tool.schema.spi.Exporter;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.SmallIntTypeDescriptor;
Expand All @@ -66,6 +68,8 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {

private final int version;

private StandardSequenceExporter exporter;

public SQLServerDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() );
}
Expand All @@ -89,8 +93,8 @@ public SQLServerDialect(int version) {
registerColumnType( Types.TIMESTAMP_WITH_TIMEZONE, "datetimeoffset($p)" );
}

if(getVersion() >= 11) {
sequenceExporter = new SqlServerSequenceExporter( this );
if ( getVersion() >= 11 ) {
exporter = new SqlServerSequenceExporter( this );
}

registerColumnType( Types.VARCHAR, 8000, "varchar($l)" );
Expand Down Expand Up @@ -787,6 +791,13 @@ public NameQualifierSupport getNameQualifierSupport() {
return NameQualifierSupport.BOTH;
}

public Exporter<Sequence> getSequenceExporter() {
if ( exporter == null ) {
return super.getSequenceExporter();
}
return exporter;
}

private class SqlServerSequenceExporter extends StandardSequenceExporter {

public SqlServerSequenceExporter(Dialect dialect) {
Expand Down
Expand Up @@ -25,7 +25,7 @@ public StandardSequenceExporter(Dialect dialect) {

@Override
public String[] getSqlCreateStrings(Sequence sequence, Metadata metadata) {
return dialect.getCreateSequenceStrings(
return dialect.getSequenceSupport().getCreateSequenceStrings(
getFormattedSequenceName( sequence.getName(), metadata ),
sequence.getInitialValue(),
sequence.getIncrementSize()
Expand All @@ -34,7 +34,7 @@ public String[] getSqlCreateStrings(Sequence sequence, Metadata metadata) {

@Override
public String[] getSqlDropStrings(Sequence sequence, Metadata metadata) {
return dialect.getDropSequenceStrings(
return dialect.getSequenceSupport().getDropSequenceStrings(
getFormattedSequenceName( sequence.getName(), metadata )
);
}
Expand Down
Expand Up @@ -4,7 +4,7 @@
* 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>.
*/
package org.hibernate.test.schemaupdate;
package org.hibernate.orm.test.schemaupdate;

import java.util.EnumSet;
import javax.persistence.Entity;
Expand All @@ -17,27 +17,28 @@
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.SQLServer2012Dialect;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;

import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.CustomRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.hibernate.testing.orm.junit.BaseUnitTest;
import org.hibernate.testing.orm.junit.RequiresDialect;

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.junit.Assert.assertThat;

/**
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-14835")
@RunWith(CustomRunner.class)
@RequiresDialect(SQLServer2012Dialect.class)
@BaseUnitTest
@RequiresDialect(value = SQLServerDialect.class, version = 12)
public class SchemaExportSqlServerWithSequenceDefaultSchemaCatalog {
protected ServiceRegistry serviceRegistry;
protected MetadataImplementor metadata;
Expand All @@ -49,7 +50,7 @@ public void shouldCreateIndex() {
assertThat( schemaExport.getExceptions().size(), is( 0 ) );
}

@Before
@BeforeEach
public void setUp() {
serviceRegistry = new StandardServiceRegistryBuilder()
.applySetting( Environment.DEFAULT_SCHEMA, "dbo" )
Expand All @@ -65,7 +66,7 @@ public void setUp() {
}


@After
@AfterEach
public void tearDown() {
System.out.println( "********* Starting SchemaExport (drop) for TEAR-DOWN *************************" );
new SchemaExport().drop( EnumSet.of( TargetType.DATABASE, TargetType.STDOUT ), metadata );
Expand Down

0 comments on commit 70c09df

Please sign in to comment.