From cfd5414321530fa11e50a44fbb02d095b7daa542 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Sat, 18 Jul 2015 17:44:11 -0500 Subject: [PATCH] HHH-9948 - SequenceStyleGenerator uses potentially incorrect name for table/sequence in DML statements --- .../enhanced/SequenceStyleConfigUnitTest.java | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/test/java/org/hibernate/id/enhanced/SequenceStyleConfigUnitTest.java b/hibernate-core/src/test/java/org/hibernate/id/enhanced/SequenceStyleConfigUnitTest.java index f084dd2ea8..1504fa0b79 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/enhanced/SequenceStyleConfigUnitTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/enhanced/SequenceStyleConfigUnitTest.java @@ -9,6 +9,8 @@ package org.hibernate.id.enhanced; import java.util.Properties; import org.hibernate.MappingException; +import org.hibernate.boot.internal.MetadataBuilderImpl; +import org.hibernate.boot.model.relational.Database; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.AvailableSettings; @@ -17,8 +19,8 @@ import org.hibernate.dialect.Dialect; import org.hibernate.id.PersistentIdentifierGenerator; import org.hibernate.type.StandardBasicTypes; -import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.boot.MetadataBuildingContextTestingImpl; +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Test; import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability; @@ -45,6 +47,10 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase { SequenceStyleGenerator generator = new SequenceStyleGenerator(); generator.configure( StandardBasicTypes.LONG, props, serviceRegistry ); + generator.registerExportables( + new Database( new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ) + ); + assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() ); assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() ); assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() ); @@ -77,6 +83,10 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase { SequenceStyleGenerator generator = new SequenceStyleGenerator(); generator.configure( StandardBasicTypes.LONG, props, serviceRegistry ); + generator.registerExportables( + new Database( new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ) + ); + assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() ); assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() ); assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() ); @@ -104,6 +114,11 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase { SequenceStyleGenerator generator = new SequenceStyleGenerator(); generator.configure( StandardBasicTypes.LONG, props, serviceRegistry ); + + generator.registerExportables( + new Database( new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ) + ); + assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() ); assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() ); assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() ); @@ -123,6 +138,10 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase { SequenceStyleGenerator generator = new SequenceStyleGenerator(); generator.configure( StandardBasicTypes.LONG, props, serviceRegistry ); + generator.registerExportables( + new Database( new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ) + ); + assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() ); assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() ); assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() ); @@ -149,6 +168,10 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase { SequenceStyleGenerator generator = new SequenceStyleGenerator(); generator.configure( StandardBasicTypes.LONG, props, serviceRegistry ); + generator.registerExportables( + new Database( new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ) + ); + assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() ); assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() ); assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() ); @@ -173,6 +196,10 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase { SequenceStyleGenerator generator = new SequenceStyleGenerator(); generator.configure( StandardBasicTypes.LONG, props, serviceRegistry ); + generator.registerExportables( + new Database( new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ) + ); + assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() ); assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() ); assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() ); @@ -198,6 +225,10 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase { props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" ); SequenceStyleGenerator generator = new SequenceStyleGenerator(); generator.configure( StandardBasicTypes.LONG, props, serviceRegistry ); + generator.registerExportables( + new Database( new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ) + ); + assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() ); assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() ); assertEquals( 1, generator.getOptimizer().getIncrementSize() ); @@ -209,6 +240,9 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase { props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" ); generator = new SequenceStyleGenerator(); generator.configure( StandardBasicTypes.LONG, props, serviceRegistry ); + generator.registerExportables( + new Database( new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ) + ); assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() ); assertClassAssignability( HiLoOptimizer.class, generator.getOptimizer().getClass() ); assertEquals( 20, generator.getOptimizer().getIncrementSize() ); @@ -220,6 +254,9 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase { props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" ); generator = new SequenceStyleGenerator(); generator.configure( StandardBasicTypes.LONG, props, serviceRegistry ); + generator.registerExportables( + new Database( new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ) + ); // because the dialect reports to not support pooled seqyences, the expectation is that we will // use a table for the backing structure... assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() ); @@ -243,12 +280,18 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase { props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" ); SequenceStyleGenerator generator = new SequenceStyleGenerator(); generator.configure( StandardBasicTypes.LONG, props, serviceRegistry ); + generator.registerExportables( + new Database( new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ) + ); assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() ); assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() ); props.setProperty( Environment.PREFER_POOLED_VALUES_LO, "true" ); generator = new SequenceStyleGenerator(); generator.configure( StandardBasicTypes.LONG, props, serviceRegistry ); + generator.registerExportables( + new Database( new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ) + ); assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() ); assertClassAssignability( PooledLoOptimizer.class, generator.getOptimizer().getClass() ); }