FileDocCategorySizeDatePackage
SequenceStyleConfigUnitTest.javaAPI DocHibernate 3.2.58208Tue Mar 20 20:22:44 GMT 2007org.hibernate.test.idgen.enhanced

SequenceStyleConfigUnitTest

public class SequenceStyleConfigUnitTest extends org.hibernate.junit.UnitTestCase
Tests that SequenceStyleGenerator configures itself as expected in various scenarios
author
Steve Ebersole

Fields Summary
Constructors Summary
public SequenceStyleConfigUnitTest(String string)

		super( string );
	
Methods Summary
public static junit.framework.Testsuite()

		return new TestSuite( SequenceStyleConfigUnitTest.class );
	
public voidtestDefaultOptimizerBasedOnIncrementBackedBySequence()
Test default optimizer selection for sequence backed generators based on the configured increment size; both in the case of the dialect supporting pooled sequences (pooled) and not (hilo)

		Properties props = new Properties();
		props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );

		// for dialects which do not support pooled sequences, we default to hilo
		Dialect dialect = new SequenceDialect();
		SequenceStyleGenerator generator = new SequenceStyleGenerator();
		generator.configure( Hibernate.LONG, props, dialect );
		assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
		assertClassAssignability( OptimizerFactory.HiLoOptimizer.class, generator.getOptimizer().getClass() );
		assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );

		// for dialects which do support pooled sequences, we default to pooled
		dialect = new PooledSequenceDialect();
		generator = new SequenceStyleGenerator();
		generator.configure( Hibernate.LONG, props, dialect );
		assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
		assertClassAssignability( OptimizerFactory.PooledOptimizer.class, generator.getOptimizer().getClass() );
		assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
	
public voidtestDefaultOptimizerBasedOnIncrementBackedByTable()
Test default optimizer selection for table backed generators based on the configured increment size. Here we always prefer pooled.

		Properties props = new Properties();
		props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );
		Dialect dialect = new TableDialect();
		SequenceStyleGenerator generator = new SequenceStyleGenerator();
		generator.configure( Hibernate.LONG, props, dialect );
		assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
		assertClassAssignability( OptimizerFactory.PooledOptimizer.class, generator.getOptimizer().getClass() );
		assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
	
public voidtestDefaultedSequenceBackedConfiguration()
Test all params defaulted with a dialect supporting sequences

		Dialect dialect = new SequenceDialect();
		Properties props = new Properties();
		SequenceStyleGenerator generator = new SequenceStyleGenerator();
		generator.configure( Hibernate.LONG, props, dialect );

		assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
		assertClassAssignability( OptimizerFactory.NoopOptimizer.class, generator.getOptimizer().getClass() );
		assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
	
public voidtestDefaultedTableBackedConfiguration()
Test all params defaulted with a dialect which does not support sequences

		Dialect dialect = new TableDialect();
		Properties props = new Properties();
		SequenceStyleGenerator generator = new SequenceStyleGenerator();
		generator.configure( Hibernate.LONG, props, dialect );

		assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
		assertClassAssignability( OptimizerFactory.NoopOptimizer.class, generator.getOptimizer().getClass() );
		assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
	
public voidtestExplicitOptimizerWithExplicitIncrementSize()
Test explicitly specifying both optimizer and increment

		// with sequence ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		Dialect dialect = new SequenceDialect();

		// optimizer=none w/ increment > 1 => should honor optimizer
		Properties props = new Properties();
		props.setProperty( SequenceStyleGenerator.OPT_PARAM, OptimizerFactory.NONE );
		props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
		SequenceStyleGenerator generator = new SequenceStyleGenerator();
		generator.configure( Hibernate.LONG, props, dialect );
		assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
		assertClassAssignability( OptimizerFactory.NoopOptimizer.class, generator.getOptimizer().getClass() );
		assertEquals( 1, generator.getOptimizer().getIncrementSize() );
		assertEquals( 1, generator.getDatabaseStructure().getIncrementSize() );

		// optimizer=hilo w/ increment > 1 => hilo
		props = new Properties();
		props.setProperty( SequenceStyleGenerator.OPT_PARAM, OptimizerFactory.HILO );
		props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );generator = new SequenceStyleGenerator();
		generator.configure( Hibernate.LONG, props, dialect );
		assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
		assertClassAssignability( OptimizerFactory.HiLoOptimizer.class, generator.getOptimizer().getClass() );
		assertEquals( 20, generator.getOptimizer().getIncrementSize() );
		assertEquals( 20, generator.getDatabaseStructure().getIncrementSize() );

		// optimizer=pooled w/ increment > 1 => hilo
		props = new Properties();
		props.setProperty( SequenceStyleGenerator.OPT_PARAM, OptimizerFactory.POOL );
		props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
		generator = new SequenceStyleGenerator();
		generator.configure( Hibernate.LONG, props, dialect );
		assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
		assertClassAssignability( OptimizerFactory.HiLoOptimizer.class, generator.getOptimizer().getClass() );
		assertEquals( 20, generator.getOptimizer().getIncrementSize() );
		assertEquals( 20, generator.getDatabaseStructure().getIncrementSize() );
	
public voidtestForceTableUse()
Test forcing of table as backing strucuture with dialect supporting sequences

		Dialect dialect = new SequenceDialect();
		Properties props = new Properties();
		props.setProperty( SequenceStyleGenerator.FORCE_TBL_PARAM, "true" );
		SequenceStyleGenerator generator = new SequenceStyleGenerator();
		generator.configure( Hibernate.LONG, props, dialect );
		assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
		assertClassAssignability( OptimizerFactory.NoopOptimizer.class, generator.getOptimizer().getClass() );
		assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );