HHH-12861 SchemaUpdate doesn't work with Sybase
This commit is contained in:
parent
dc42deafcb
commit
7da105be0a
|
@ -43,4 +43,9 @@ public class SybaseDialect extends AbstractTransactSQLDialect {
|
||||||
public String getNullColumnString() {
|
public String getNullColumnString() {
|
||||||
return " null";
|
return " null";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCurrentSchemaCommand() {
|
||||||
|
return "select db_name()";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,16 +6,15 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.schemaupdate.foreignkeys;
|
package org.hibernate.test.schemaupdate.foreignkeys;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
import javax.persistence.CollectionTable;
|
import javax.persistence.CollectionTable;
|
||||||
import javax.persistence.ElementCollection;
|
import javax.persistence.ElementCollection;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.FetchType;
|
import javax.persistence.FetchType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
|
@ -25,13 +24,12 @@ import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||||
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
|
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
|
||||||
import org.hibernate.tool.schema.TargetType;
|
import org.hibernate.tool.schema.TargetType;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Boriero
|
* @author Andrea Boriero
|
||||||
*/
|
*/
|
||||||
|
@ -41,36 +39,36 @@ public class SchemaUpdateWithKeywordAutoQuotingEnabledTest extends BaseUnitTestC
|
||||||
private MetadataImplementor metadata;
|
private MetadataImplementor metadata;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws IOException {
|
public void setUp() {
|
||||||
final StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder();
|
final StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder();
|
||||||
standardServiceRegistryBuilder.applySetting(
|
standardServiceRegistryBuilder.applySetting(
|
||||||
org.hibernate.cfg.AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED,
|
org.hibernate.cfg.AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED,
|
||||||
"true"
|
"true"
|
||||||
);
|
);
|
||||||
ssr = standardServiceRegistryBuilder.build();
|
ssr = standardServiceRegistryBuilder.build();
|
||||||
final MetadataSources metadataSources = new MetadataSources( ssr );
|
|
||||||
|
|
||||||
|
final MetadataSources metadataSources = new MetadataSources( ssr );
|
||||||
metadataSources.addAnnotatedClass( Match.class );
|
metadataSources.addAnnotatedClass( Match.class );
|
||||||
metadata = (MetadataImplementor) metadataSources.buildMetadata();
|
metadata = (MetadataImplementor) metadataSources.buildMetadata();
|
||||||
metadata.validate();
|
metadata.validate();
|
||||||
|
try {
|
||||||
new SchemaExport().setHaltOnError( true )
|
createSchema();
|
||||||
.setFormat( false )
|
}
|
||||||
.createOnly( EnumSet.of( TargetType.DATABASE ), metadata );
|
catch (Exception e) {
|
||||||
|
tearDown();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearsDown() {
|
public void tearDown() {
|
||||||
new SchemaExport().setHaltOnError( true )
|
dropSchema();
|
||||||
.setFormat( false )
|
|
||||||
.drop( EnumSet.of( TargetType.DATABASE ), metadata );
|
|
||||||
StandardServiceRegistryBuilder.destroy( ssr );
|
StandardServiceRegistryBuilder.destroy( ssr );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdate() {
|
public void testUpdate() {
|
||||||
new SchemaUpdate().setHaltOnError( true )
|
new SchemaUpdate().setHaltOnError( true )
|
||||||
.setFormat( false )
|
|
||||||
.execute( EnumSet.of( TargetType.DATABASE ), metadata );
|
.execute( EnumSet.of( TargetType.DATABASE ), metadata );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,4 +82,15 @@ public class SchemaUpdateWithKeywordAutoQuotingEnabledTest extends BaseUnitTestC
|
||||||
@CollectionTable
|
@CollectionTable
|
||||||
private Map<Integer, Integer> timeline = new TreeMap<>();
|
private Map<Integer, Integer> timeline = new TreeMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createSchema() {
|
||||||
|
dropSchema();
|
||||||
|
new SchemaExport().setHaltOnError( true )
|
||||||
|
.createOnly( EnumSet.of( TargetType.DATABASE ), metadata );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dropSchema() {
|
||||||
|
new SchemaExport()
|
||||||
|
.drop( EnumSet.of( TargetType.DATABASE ), metadata );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import java.util.Map;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
|
@ -22,6 +21,7 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.boot.spi.MetadataImplementor;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||||
|
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||||
import org.hibernate.tool.schema.JdbcMetadaAccessStrategy;
|
import org.hibernate.tool.schema.JdbcMetadaAccessStrategy;
|
||||||
import org.hibernate.tool.schema.SourceType;
|
import org.hibernate.tool.schema.SourceType;
|
||||||
import org.hibernate.tool.schema.TargetType;
|
import org.hibernate.tool.schema.TargetType;
|
||||||
|
@ -50,7 +50,10 @@ public class NumericValidationTest implements ExecutionOptions {
|
||||||
@Parameterized.Parameters
|
@Parameterized.Parameters
|
||||||
public static Collection<String> parameters() {
|
public static Collection<String> parameters() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
new String[] {JdbcMetadaAccessStrategy.GROUPED.toString(), JdbcMetadaAccessStrategy.INDIVIDUALLY.toString()}
|
new String[] {
|
||||||
|
JdbcMetadaAccessStrategy.GROUPED.toString(),
|
||||||
|
JdbcMetadaAccessStrategy.INDIVIDUALLY.toString()
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,16 +61,35 @@ public class NumericValidationTest implements ExecutionOptions {
|
||||||
public String jdbcMetadataExtractorStrategy;
|
public String jdbcMetadataExtractorStrategy;
|
||||||
|
|
||||||
private StandardServiceRegistry ssr;
|
private StandardServiceRegistry ssr;
|
||||||
|
private MetadataImplementor metadata;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void beforeTest() {
|
public void beforeTest() {
|
||||||
ssr = new StandardServiceRegistryBuilder()
|
ssr = new StandardServiceRegistryBuilder()
|
||||||
.applySetting( AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY, jdbcMetadataExtractorStrategy )
|
.applySetting(
|
||||||
|
AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY,
|
||||||
|
jdbcMetadataExtractorStrategy
|
||||||
|
)
|
||||||
.build();
|
.build();
|
||||||
|
metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||||
|
.addAnnotatedClass( TestEntity.class )
|
||||||
|
.buildMetadata();
|
||||||
|
metadata.validate();
|
||||||
|
|
||||||
|
try {
|
||||||
|
dropSchema();
|
||||||
|
// create the schema
|
||||||
|
createSchema();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
tearDown();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void afterTest() {
|
public void tearDown() {
|
||||||
|
dropSchema();
|
||||||
if ( ssr != null ) {
|
if ( ssr != null ) {
|
||||||
StandardServiceRegistryBuilder.destroy( ssr );
|
StandardServiceRegistryBuilder.destroy( ssr );
|
||||||
}
|
}
|
||||||
|
@ -75,31 +97,15 @@ public class NumericValidationTest implements ExecutionOptions {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidation() {
|
public void testValidation() {
|
||||||
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
doValidation();
|
||||||
.addAnnotatedClass( TestEntity.class )
|
|
||||||
.buildMetadata();
|
|
||||||
metadata.validate();
|
|
||||||
|
|
||||||
|
|
||||||
// create the schema
|
|
||||||
createSchema( metadata );
|
|
||||||
|
|
||||||
try {
|
|
||||||
doValidation( metadata );
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
dropSchema( metadata );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doValidation(MetadataImplementor metadata) {
|
private void doValidation() {
|
||||||
ssr.getService( SchemaManagementTool.class ).getSchemaValidator( null ).doValidation(
|
ssr.getService( SchemaManagementTool.class ).getSchemaValidator( null )
|
||||||
metadata,
|
.doValidation( metadata, this );
|
||||||
this
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createSchema(MetadataImplementor metadata) {
|
private void createSchema() {
|
||||||
ssr.getService( SchemaManagementTool.class ).getSchemaCreator( null ).doCreation(
|
ssr.getService( SchemaManagementTool.class ).getSchemaCreator( null ).doCreation(
|
||||||
metadata,
|
metadata,
|
||||||
this,
|
this,
|
||||||
|
@ -128,43 +134,19 @@ public class NumericValidationTest implements ExecutionOptions {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dropSchema(MetadataImplementor metadata) {
|
private void dropSchema() {
|
||||||
ssr.getService( SchemaManagementTool.class ).getSchemaDropper( null ).doDrop(
|
new SchemaExport()
|
||||||
metadata,
|
.drop( EnumSet.of( TargetType.DATABASE ), metadata );
|
||||||
this,
|
|
||||||
new SourceDescriptor() {
|
|
||||||
@Override
|
|
||||||
public SourceType getSourceType() {
|
|
||||||
return SourceType.METADATA;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ScriptSourceInput getScriptSourceInput() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new TargetDescriptor() {
|
|
||||||
@Override
|
|
||||||
public EnumSet<TargetType> getTargetTypes() {
|
|
||||||
return EnumSet.of( TargetType.DATABASE );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ScriptTargetOutput getScriptTargetOutput() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(name = "TestEntity")
|
@Entity(name = "TestEntity")
|
||||||
public static class TestEntity {
|
public static class TestEntity {
|
||||||
@Id
|
@Id
|
||||||
public Integer id;
|
public Integer id;
|
||||||
|
|
||||||
@Column(name = "numberValue")
|
@Column(name = "numberValue")
|
||||||
BigDecimal number;
|
BigDecimal number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map getConfigurationValues() {
|
public Map getConfigurationValues() {
|
||||||
|
|
Loading…
Reference in New Issue