Permalink
Browse files

SequenceStyleGenerator.cs: If a pooled optimizer is chosen, but the d…

…ialect doesn't support pooled sequences, force the use of a table instead. (Hibernate behavior.)
  • Loading branch information...
1 parent 51b7ccd commit d29cbe2e548aa7827a1479c40f3d8b200b8902a2 @oskarb oskarb committed with julian-maughan Nov 27, 2011
View
@@ -5,6 +5,7 @@ Build 3.2.1.GA
##### Possible Breaking Changes #####
* [NH-2950] - IAccessCallback.NextValue property renamed and changed to a method called IAccessCallback.GetNextValue()
+ * [NH-2953] - SequenceStyleGenerator now forces use of a table if a pooled optimizer is chosen and the dialect doesn't support pooled sequences.
Build 3.2.0.GA (rev6000)
=============================
@@ -44,7 +44,9 @@ public override bool SupportsPooledSequences
}
}
- // Test explicitly specifying both optimizer and increment
+ /// <summary>
+ /// Test explicitly specifying both optimizer and increment.
+ /// </summary>
[Test]
public void ExplicitOptimizerWithExplicitIncrementSize()
{
@@ -73,14 +75,16 @@ public void ExplicitOptimizerWithExplicitIncrementSize()
Assert.AreEqual(20, generator.Optimizer.IncrementSize);
Assert.AreEqual(20, generator.DatabaseStructure.IncrementSize);
- // optimizer=pooled w/ increment > 1 => hilo
+ // optimizer=pooled w/ increment > 1 => pooled+table
props = new Dictionary<string, string>();
props[SequenceStyleGenerator.OptimizerParam] = OptimizerFactory.Pool;
props[SequenceStyleGenerator.IncrementParam] = "20";
generator = new SequenceStyleGenerator();
generator.Configure(NHibernateUtil.Int64, props, dialect);
- Assert.That(generator.DatabaseStructure, Is.AssignableFrom(typeof (SequenceStructure)));
- Assert.That(generator.Optimizer, Is.AssignableFrom(typeof (OptimizerFactory.HiLoOptimizer)));
+ // because the dialect reports that it does not support pooled sequences, the expectation is that we will
+ // use a table for the backing structure...
+ Assert.That(generator.DatabaseStructure, Is.AssignableFrom(typeof (TableStructure)));
+ Assert.That(generator.Optimizer, Is.AssignableFrom(typeof (OptimizerFactory.PooledOptimizer)));
Assert.AreEqual(20, generator.Optimizer.IncrementSize);
Assert.AreEqual(20, generator.DatabaseStructure.IncrementSize);
}
@@ -113,24 +117,26 @@ public void DefaultedTableBackedConfiguration()
Assert.That(generator.DatabaseStructure.Name, Is.EqualTo(SequenceStyleGenerator.DefaultSequenceName));
}
- //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)
+ /// <summary>
+ /// 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)
+ /// </summary>
[Test]
public void DefaultOptimizerBasedOnIncrementBackedBySequence()
{
IDictionary<string, string> props = new Dictionary<string, string>();
props[SequenceStyleGenerator.IncrementParam] = "10";
- // for dialects which do not support pooled sequences, we default to hilo
+ // for dialects which do not support pooled sequences, we default to pooled+table
Dialect.Dialect dialect = new SequenceDialect();
SequenceStyleGenerator generator = new SequenceStyleGenerator();
generator.Configure(NHibernateUtil.Int64, props, dialect);
- Assert.That(generator.DatabaseStructure, Is.AssignableFrom(typeof (SequenceStructure)));
- Assert.That(generator.Optimizer, Is.AssignableFrom(typeof (OptimizerFactory.HiLoOptimizer)));
+ Assert.That(generator.DatabaseStructure, Is.AssignableFrom(typeof (TableStructure)));
+ Assert.That(generator.Optimizer, Is.AssignableFrom(typeof (OptimizerFactory.PooledOptimizer)));
Assert.That(generator.DatabaseStructure.Name, Is.EqualTo(SequenceStyleGenerator.DefaultSequenceName));
- // for dialects which do support pooled sequences, we default to pooled
+ // for dialects which do support pooled sequences, we default to pooled+sequence
dialect = new PooledSequenceDialect();
generator = new SequenceStyleGenerator();
generator.Configure(NHibernateUtil.Int64, props, dialect);
@@ -102,8 +102,8 @@ public virtual void Configure(IType type, IDictionary<string, string> parms, Dia
{
if (OptimizerFactory.Pool.Equals(optimizationStrategy) && !dialect.SupportsPooledSequences)
{
- // TODO : may even be better to fall back to a pooled table strategy here so that the db stored values remain consistent...
- optimizationStrategy = OptimizerFactory.HiLo;
+ forceTableUse = true;
+ Log.Info("Forcing table use for sequence-style generator due to pooled optimizer selection where db does not support pooled sequences.");
}
}

0 comments on commit d29cbe2

Please sign in to comment.