Hibernate SVN: r20892 - in core/branches/Branch_3_2_4_SP1_CP: test/org/hibernate/test/id and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2011-02-09 05:54:31 -0500 (Wed, 09 Feb 2011)
New Revision: 20892
Added:
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/id/enhanced/
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/id/enhanced/OptimizerUnitTest.java
Modified:
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/OptimizerFactory.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/SequenceStyleGenerator.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/TableGenerator.java
Log:
JBPAPP-5762 HHH-5217 Minimize double sequence value reads in PooledOptimizer
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/OptimizerFactory.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/OptimizerFactory.java 2011-02-09 04:51:08 UTC (rev 20891)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/OptimizerFactory.java 2011-02-09 10:54:31 UTC (rev 20892)
@@ -23,7 +23,25 @@
public static final String POOL = "pooled";
private static Class[] CTOR_SIG = new Class[] { Class.class, int.class };
-
+
+ /**
+ * Marker interface for optimizer which wish to know the user-specified initial value.
+ * <p/>
+ * Used instead of constructor injection since that is already a public understanding and
+ * because not all optimizers care.
+ */
+ public static interface InitialValueAwareOptimizer {
+ /**
+ * Reports the user specified initial value to the optimizer.
+ * <p/>
+ * <tt>-1</tt> is used to indicate that the user did not specify.
+ *
+ * @param initialValue The initial value specified by the user, or <tt>-1</tt> to indicate that the
+ * user did not specify.
+ */
+ public void injectInitialValue(long initialValue);
+ }
+
public static Optimizer buildOptimizer(String type, Class returnClass, int incrementSize) {
String optimizerClassName;
if ( NONE.equals( type ) ) {
@@ -51,6 +69,25 @@
// the default...
return new NoopOptimizer( returnClass, incrementSize );
}
+
+ /**
+ * Builds an optimizer
+ *
+ * @param type The optimizer type, either a short-hand name or the {@link Optimizer} class name.
+ * @param returnClass The generated value java type
+ * @param incrementSize The increment size.
+ * @param explicitInitialValue The user supplied initial-value (-1 indicates the user did not specify).
+ *
+ * @return The built optimizer
+ */
+ @SuppressWarnings({ "UnnecessaryBoxing", "deprecation" })
+ public static Optimizer buildOptimizer(String type, Class returnClass, int incrementSize, long explicitInitialValue) {
+ final Optimizer optimizer = buildOptimizer( type, returnClass, incrementSize );
+ if ( InitialValueAwareOptimizer.class.isInstance( optimizer ) ) {
+ ( (InitialValueAwareOptimizer) optimizer ).injectInitialValue( explicitInitialValue );
+ }
+ return optimizer;
+ }
public static abstract class OptimizerSupport implements Optimizer {
protected final Class returnClass;
@@ -154,10 +191,14 @@
}
}
- public static class PooledOptimizer extends OptimizerSupport {
+ /**
+ * Optimizer which uses a pool of values, storing the next low value of the
+ * range in the database.
+ */
+ public static class PooledOptimizer extends OptimizerSupport implements InitialValueAwareOptimizer{
private long value;
private long hiValue = -1;
-
+ private long initialValue = -1;
public PooledOptimizer(Class returnClass, int incrementSize) {
super( returnClass, incrementSize );
if ( incrementSize < 1 ) {
@@ -168,7 +209,10 @@
}
}
- public Serializable generate(AccessCallback callback) {
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized Serializable generate(AccessCallback callback) {
if ( hiValue < 0 ) {
value = callback.getNextValue();
if ( value < 1 ) {
@@ -178,7 +222,14 @@
// we are using a sequence...
log.info( "pooled optimizer source reported [" + value + "] as the initial value; use of 1 or greater highly recommended" );
}
- hiValue = callback.getNextValue();
+ if ( ( initialValue == -1 && value < incrementSize ) || ( value == initialValue ) ) {
+ // the call to obtain next-value just gave us the initialValue
+ hiValue = callback.getNextValue();
+ }
+ else {
+ hiValue = value;
+ value = hiValue - incrementSize;
+ }
}
else if ( value >= hiValue ) {
hiValue = callback.getNextValue();
@@ -187,16 +238,31 @@
return make( value++ );
}
+ /**
+ * {@inheritDoc}
+ */
public long getLastSourceValue() {
return hiValue;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean applyIncrementSizeToSourceValues() {
return true;
}
+ /**
+ * Getter for property 'lastValue'.
+ *
+ * @return Value for property 'lastValue'.
+ */
public long getLastValue() {
return value - 1;
}
+
+ public void injectInitialValue( long initialValue ) {
+ this.initialValue = initialValue;
+ }
}
}
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/SequenceStyleGenerator.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/SequenceStyleGenerator.java 2011-02-09 04:51:08 UTC (rev 20891)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/SequenceStyleGenerator.java 2011-02-09 10:54:31 UTC (rev 20892)
@@ -146,7 +146,7 @@
databaseStructure = new TableStructure( dialect, sequenceName, valueColumnName, initialValue, incrementSize );
}
- optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize );
+ optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize, -1 );
databaseStructure.prepare( optimizer );
}
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/TableGenerator.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/TableGenerator.java 2011-02-09 04:51:08 UTC (rev 20891)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/TableGenerator.java 2011-02-09 10:54:31 UTC (rev 20892)
@@ -272,7 +272,7 @@
String defOptStrategy = incrementSize <= 1 ? OptimizerFactory.NONE : OptimizerFactory.POOL;
String optimizationStrategy = PropertiesHelper.getString( OPT_PARAM, params, defOptStrategy );
- optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize );
+ optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize, -1 );
}
/**
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/id/enhanced/OptimizerUnitTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/id/enhanced/OptimizerUnitTest.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/id/enhanced/OptimizerUnitTest.java 2011-02-09 10:54:31 UTC (rev 20892)
@@ -0,0 +1,338 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.id.enhanced;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.hibernate.id.enhanced.AccessCallback;
+import org.hibernate.id.enhanced.Optimizer;
+import org.hibernate.id.enhanced.OptimizerFactory;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+@SuppressWarnings({ "deprecation" })
+public class OptimizerUnitTest extends TestCase {
+ public OptimizerUnitTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new TestSuite( OptimizerUnitTest.class );
+ }
+
+ public void testBasicNoOptimizerUsage() {
+ // test historic sequence behavior, where the initial values start at 1...
+ SourceMock sequence = new SourceMock( 1 );
+ Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.NONE, Long.class, 1 );
+ for ( int i = 1; i < 11; i++ ) {
+ final Long next = ( Long ) optimizer.generate( sequence );
+ assertEquals( i, next.intValue() );
+ }
+ assertEquals( 10, sequence.getTimesCalled() );
+ assertEquals( 10, sequence.getCurrentValue() );
+
+ // test historic table behavior, where the initial values started at 0 (we now force 1 to be the first used id value)
+ sequence = new SourceMock( 0 );
+ optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.NONE, Long.class, 1 );
+ for ( int i = 1; i < 11; i++ ) {
+ final Long next = ( Long ) optimizer.generate( sequence );
+ assertEquals( i, next.intValue() );
+ }
+ assertEquals( 11, sequence.getTimesCalled() ); // an extra time to get to 1 initially
+ assertEquals( 10, sequence.getCurrentValue() );
+ }
+
+ public void testBasicHiLoOptimizerUsage() {
+ int increment = 10;
+ Long next;
+
+ // test historic sequence behavior, where the initial values start at 1...
+ SourceMock sequence = new SourceMock( 1 );
+ Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.HILO, Long.class, increment );
+ for ( int i = 1; i <= increment; i++ ) {
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( i, next.intValue() );
+ }
+ assertEquals( 1, sequence.getTimesCalled() ); // once to initialze state
+ assertEquals( 1, sequence.getCurrentValue() );
+ // force a "clock over"
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( 11, next.intValue() );
+ assertEquals( 2, sequence.getTimesCalled() );
+ assertEquals( 2, sequence.getCurrentValue() );
+
+ // test historic table behavior, where the initial values started at 0 (we now force 1 to be the first used id value)
+ sequence = new SourceMock( 0 );
+ optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.HILO, Long.class, increment );
+ for ( int i = 1; i <= increment; i++ ) {
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( i, next.intValue() );
+ }
+ assertEquals( 2, sequence.getTimesCalled() ); // here have have an extra call to get to 1 initially
+ assertEquals( 1, sequence.getCurrentValue() );
+ // force a "clock over"
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( 11, next.intValue() );
+ assertEquals( 3, sequence.getTimesCalled() );
+ assertEquals( 2, sequence.getCurrentValue() );
+ }
+
+ public void testBasicPooledOptimizerUsage() {
+ Long next;
+ // test historic sequence behavior, where the initial values start at 1...
+ SourceMock sequence = new SourceMock( 1, 10 );
+ Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 10 );
+ for ( int i = 1; i < 11; i++ ) {
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( i, next.intValue() );
+ }
+ assertEquals( 2, sequence.getTimesCalled() ); // twice to initialize state
+ assertEquals( 11, sequence.getCurrentValue() );
+ // force a "clock over"
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( 11, next.intValue() );
+ assertEquals( 3, sequence.getTimesCalled() );
+ assertEquals( 21, sequence.getCurrentValue() );
+ }
+
+ public void testSubsequentPooledOptimizerUsage() {
+ // test the pooled optimizer in situation where the sequence is already beyond its initial value on init.
+ // cheat by telling the sequence to start with 1000
+ final SourceMock sequence = new SourceMock( 1001, 3, 5 );
+ // but tell the optimizer the start-with is 1
+ final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 );
+
+ assertEquals( 5, sequence.getTimesCalled() );
+ assertEquals( 1001, sequence.getCurrentValue() );
+
+ Long next = (Long) optimizer.generate( sequence );
+ assertEquals( 1001, next.intValue() );
+ assertEquals( (5+1), sequence.getTimesCalled() );
+ assertEquals( (1001+3), sequence.getCurrentValue() );
+
+ next = (Long) optimizer.generate( sequence );
+ assertEquals( (1001+1), next.intValue() );
+ assertEquals( (5+1), sequence.getTimesCalled() );
+ assertEquals( (1001+3), sequence.getCurrentValue() );
+
+ next = (Long) optimizer.generate( sequence );
+ assertEquals( (1001+2), next.intValue() );
+ assertEquals( (5+1), sequence.getTimesCalled() );
+ assertEquals( (1001+3), sequence.getCurrentValue() );
+
+ // force a "clock over"
+ next = (Long) optimizer.generate( sequence );
+ assertEquals( (1001+3), next.intValue() );
+ assertEquals( (5+2), sequence.getTimesCalled() );
+ assertEquals( (1001+6), sequence.getCurrentValue() );
+ }
+
+// public void testBasicPooledLoOptimizerUsage() {
+// final SourceMock sequence = new SourceMock( 1, 3 );
+// final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL_LO, Long.class, 3 );
+//
+// assertEquals( 0, sequence.getTimesCalled() );
+// assertEquals( -1, sequence.getCurrentValue() );
+//
+// Long next = ( Long ) optimizer.generate( sequence );
+// assertEquals( 1, next.intValue() );
+// assertEquals( 1, sequence.getTimesCalled() );
+// assertEquals( 1, sequence.getCurrentValue() );
+//
+// next = ( Long ) optimizer.generate( sequence );
+// assertEquals( 2, next.intValue() );
+// assertEquals( 1, sequence.getTimesCalled() );
+// assertEquals( 1, sequence.getCurrentValue() );
+//
+// next = ( Long ) optimizer.generate( sequence );
+// assertEquals( 3, next.intValue() );
+// assertEquals( 1, sequence.getTimesCalled() );
+// assertEquals( 1, sequence.getCurrentValue() );
+//
+//// // force a "clock over"
+// next = ( Long ) optimizer.generate( sequence );
+// assertEquals( 4, next.intValue() );
+// assertEquals( 2, sequence.getTimesCalled() );
+// assertEquals( (1+3), sequence.getCurrentValue() );
+// }
+
+ public void testSubsequentPooledLoOptimizerUsage() {
+ // test the pooled optimizer in situation where the sequence is already beyond its initial value on init.
+ // cheat by telling the sequence to start with 1000
+ final SourceMock sequence = new SourceMock( 1001, 3, 5 );
+ // but tell the optimizer the start-with is 1
+ final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 );
+
+ assertEquals( 5, sequence.getTimesCalled() );
+ assertEquals( 1001, sequence.getCurrentValue() );
+
+ Long next = ( Long ) optimizer.generate( sequence );
+ assertEquals( (1001), next.intValue() );
+ assertEquals( (5+1), sequence.getTimesCalled() );
+ assertEquals( (1001+3), sequence.getCurrentValue() );
+
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( (1001+1), next.intValue() );
+ assertEquals( (5+1), sequence.getTimesCalled() );
+ assertEquals( (1001+3), sequence.getCurrentValue() );
+
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( (1001+2), next.intValue() );
+ assertEquals( (5+1), sequence.getTimesCalled() );
+ assertEquals( (1001+3), sequence.getCurrentValue() );
+
+// // force a "clock over"
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( (1001+3), next.intValue() );
+ assertEquals( (5+2), sequence.getTimesCalled() );
+ assertEquals( (1001+6), sequence.getCurrentValue() );
+ }
+
+ public void testRecoveredPooledOptimizerUsage() {
+ final SourceMock sequence = new SourceMock( 1, 3 );
+ final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 );
+
+ assertEquals( 0, sequence.getTimesCalled() );
+ assertEquals( -1, sequence.getCurrentValue() );
+
+ Long next = ( Long ) optimizer.generate( sequence );
+ assertEquals( 1, next.intValue() );
+ assertEquals( 2, sequence.getTimesCalled() );
+ assertEquals( 4, sequence.getCurrentValue() );
+
+ // app ends, and starts back up (we should "lose" only 2 and 3 as id values)
+ final Optimizer optimizer2 = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 );
+ next = ( Long ) optimizer2.generate( sequence );
+ assertEquals( 4, next.intValue() );
+ assertEquals( 3, sequence.getTimesCalled() );
+ assertEquals( 7, sequence.getCurrentValue() );
+ }
+
+// public void testRecoveredPooledLoOptimizerUsage() {
+// final SourceMock sequence = new SourceMock( 1, 3 );
+// final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL_LO, Long.class, 3, 1 );
+//
+// assertEquals( 0, sequence.getTimesCalled() );
+// assertEquals( -1, sequence.getCurrentValue() );
+//
+// Long next = ( Long ) optimizer.generate( sequence );
+// assertEquals( 1, next.intValue() );
+// assertEquals( 1, sequence.getTimesCalled() );
+// assertEquals( 1, sequence.getCurrentValue() );
+//
+// // app ends, and starts back up (we should "lose" only 2 and 3 as id values)
+// final Optimizer optimizer2 = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL_LO, Long.class, 3, 1 );
+// next = ( Long ) optimizer2.generate( sequence );
+// assertEquals( 4, next.intValue() );
+// assertEquals( 2, sequence.getTimesCalled() );
+// assertEquals( 4, sequence.getCurrentValue() );
+// }
+
+ private static class SourceMock implements AccessCallback {
+ private long value;
+ private long initialValue;
+ private int increment;
+ private int timesCalled = 0;
+
+ public SourceMock(long initialValue) {
+ this( initialValue, 1 );
+ }
+
+ public SourceMock(long initialValue, int increment) {
+ this( initialValue, increment, 0 );
+ }
+
+ public SourceMock(long initialValue, int increment, int timesCalled) {
+ this.increment = increment;
+ this.timesCalled = timesCalled;
+ if ( timesCalled != 0 ) {
+ this.value=initialValue;
+ this.initialValue = 1;
+ }
+ else {
+ this.value=-1;
+ this.initialValue = initialValue;
+ }
+ }
+
+ public long getNextValue() {
+ try {
+ if ( timesCalled == 0 ) {
+ initValue();
+ return value;
+ }
+ else {
+ return value+=increment;
+ }
+ }
+ finally {
+ timesCalled++;
+ }
+ }
+
+ private void initValue() {
+ this.value = initialValue;
+ }
+
+ public int getTimesCalled() {
+ return timesCalled;
+ }
+
+ public long getCurrentValue() {
+ return value;
+ }
+ }
+
+// public void testNoopDumping() {
+// SourceMock sequence = new SourceMock( 1 );
+// Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.NONE, Long.class, 1 );
+// for ( int i = 1; i <= 41; i++ ) {
+// System.out.println( i + " => " + optimizer.generate( sequence ) + " (" + sequence.getCurrentValue() + ")" );
+// }
+// }
+//
+// public void testHiLoDumping() {
+// int increment = 10;
+// SourceMock sequence = new SourceMock( 1 );
+// Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.HILO, Long.class, increment );
+// for ( int i = 1; i <= 41; i++ ) {
+// System.out.println( i + " => " + optimizer.generate( sequence ) + " (" + sequence.getCurrentValue() + ")" );
+// }
+// }
+//
+// public void testPooledDumping() {
+// int increment = 10;
+// SourceMock sequence = new SourceMock( 1, increment );
+// Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, increment );
+// for ( int i = 1; i <= 41; i++ ) {
+// System.out.println( i + " => " + optimizer.generate( sequence ) + " (" + sequence.getCurrentValue() + ")" );
+// }
+// }
+
+}
13 years, 9 months
Hibernate SVN: r20891 - in core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine: loading and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2011-02-08 23:51:08 -0500 (Tue, 08 Feb 2011)
New Revision: 20891
Modified:
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/StatefulPersistenceContext.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/loading/LoadContexts.java
Log:
correct typo in javadoc
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/StatefulPersistenceContext.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/StatefulPersistenceContext.java 2011-02-09 04:48:50 UTC (rev 20890)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/StatefulPersistenceContext.java 2011-02-09 04:51:08 UTC (rev 20891)
@@ -291,7 +291,7 @@
* <p/>
* This differs from {@link #getDatabaseSnapshot} is two important respects:<ol>
* <li>no snapshot is obtained from the database if not already cached</li>
- * <li>an entry of {@link #NO_ROW} here is interpretet as an exception</li>
+ * <li>an entry of {@link #NO_ROW} here is interpreted as an exception</li>
* </ol>
* @param key The entity key for which to retrieve the cached snapshot
* @return The cached snapshot
@@ -359,7 +359,7 @@
}
/**
- * Retreive the EntityEntry representation of the given entity.
+ * Retrieve the EntityEntry representation of the given entity.
*
* @param entity The entity for which to locate the EntityEntry.
* @return The EntityEntry for the given entity.
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/loading/LoadContexts.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/loading/LoadContexts.java 2011-02-09 04:48:50 UTC (rev 20890)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/loading/LoadContexts.java 2011-02-09 04:51:08 UTC (rev 20891)
@@ -29,7 +29,7 @@
* implementations.
* <p/>
* Considering the JDBC-redesign work, would further like this contextual info
- * not mapped seperately, but available based on the result set being processed.
+ * not mapped separately, but available based on the result set being processed.
* This would also allow maintaining a single mapping as we could reliably get
* notification of the result-set closing...
*
13 years, 9 months
Hibernate SVN: r20890 - entitymanager/branches/v3_3_2_GA_CP.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2011-02-08 23:48:50 -0500 (Tue, 08 Feb 2011)
New Revision: 20890
Modified:
entitymanager/branches/v3_3_2_GA_CP/
Log:
ignore eclipse metadata files from svn
Property changes on: entitymanager/branches/v3_3_2_GA_CP
___________________________________________________________________
Name: svn:ignore
- .classpath
.project
build
+ .classpath
.project
build
.settings
13 years, 9 months
[hibernate/hibernate-core] 011d7e: HHH-5903 - Rename ServicesRegistry to ServiceRegis...
by noreply@github.com
Branch: refs/heads/master
Home: https://github.com/hibernate/hibernate-core
Commit: 011d7e1114adfceca6e54e340ed814f414fb4ce6
https://github.com/hibernate/hibernate-core/commit/011d7e1114adfceca6e54e...
Author: Steve Ebersole <steve(a)hibernate.org>
Date: 2011-02-08 (Tue, 08 Feb 2011)
Changed paths:
M hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java
M hibernate-core/src/main/java/org/hibernate/cfg/internal/ServicesRegistryBootstrap.java
M hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcServicesInitiator.java
M hibernate-core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java
M hibernate-core/src/main/java/org/hibernate/jmx/HibernateService.java
M hibernate-core/src/main/java/org/hibernate/service/classloading/internal/ClassLoaderServiceInitiator.java
A hibernate-core/src/main/java/org/hibernate/service/internal/ServiceRegistryImpl.java
M hibernate-core/src/main/java/org/hibernate/service/internal/ServicesInitializer.java
R hibernate-core/src/main/java/org/hibernate/service/internal/ServicesRegistryImpl.java
M hibernate-core/src/main/java/org/hibernate/service/jdbc/connections/internal/ConnectionProviderInitiator.java
M hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/DialectFactoryInitiator.java
M hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/DialectResolverInitiator.java
M hibernate-core/src/main/java/org/hibernate/service/jmx/internal/JmxServiceInitiator.java
M hibernate-core/src/main/java/org/hibernate/service/jndi/internal/JndiServiceInitiator.java
M hibernate-core/src/main/java/org/hibernate/service/jta/platform/internal/JtaPlatformInitiator.java
M hibernate-core/src/main/java/org/hibernate/service/spi/ServiceInitiator.java
A hibernate-core/src/main/java/org/hibernate/service/spi/ServiceRegistry.java
A hibernate-core/src/main/java/org/hibernate/service/spi/ServiceRegistryAwareService.java
R hibernate-core/src/main/java/org/hibernate/service/spi/ServicesRegistry.java
R hibernate-core/src/main/java/org/hibernate/service/spi/ServicesRegistryAwareService.java
M hibernate-core/src/test/java/org/hibernate/test/cfg/internal/ServiceBootstrappingTest.java
M hibernate-core/src/test/java/org/hibernate/test/cfg/internal/TestServicesRegistryBootstrapping.java
M hibernate-core/src/test/java/org/hibernate/test/common/ServiceRegistryHolder.java
M hibernate-core/src/test/java/org/hibernate/testing/junit/UnitTestCase.java
M hibernate-core/src/test/java/org/hibernate/testing/junit/functional/ExecutionEnvironment.java
M hibernate-core/src/test/java/org/hibernate/testing/junit/functional/annotations/HibernateTestCase.java
M hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java
M hibernate-entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java
M hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractNonFunctionalTestCase.java
M hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/CacheTestUtil.java
Log Message:
-----------
HHH-5903 - Rename ServicesRegistry to ServiceRegistry
13 years, 9 months
Hibernate SVN: r20889 - in core/branches/Branch_3_3_2_GA_CP/core/src/test/java/org/hibernate: id and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2011-02-08 10:45:21 -0500 (Tue, 08 Feb 2011)
New Revision: 20889
Added:
core/branches/Branch_3_3_2_GA_CP/core/src/test/java/org/hibernate/id/
core/branches/Branch_3_3_2_GA_CP/core/src/test/java/org/hibernate/id/enhanced/
core/branches/Branch_3_3_2_GA_CP/core/src/test/java/org/hibernate/id/enhanced/OptimizerUnitTest.java
Log:
JBPAPP-5763 HHH-5217 Minimize double sequence value reads in PooledOptimizer
Added: core/branches/Branch_3_3_2_GA_CP/core/src/test/java/org/hibernate/id/enhanced/OptimizerUnitTest.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/test/java/org/hibernate/id/enhanced/OptimizerUnitTest.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/test/java/org/hibernate/id/enhanced/OptimizerUnitTest.java 2011-02-08 15:45:21 UTC (rev 20889)
@@ -0,0 +1,337 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.id.enhanced;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+//
+//import org.hibernate.id.IdentifierGeneratorHelper;
+//import org.hibernate.id.IntegralDataTypeHolder;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+@SuppressWarnings({ "deprecation" })
+public class OptimizerUnitTest extends TestCase {
+ public OptimizerUnitTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new TestSuite( OptimizerUnitTest.class );
+ }
+
+ public void testBasicNoOptimizerUsage() {
+ // test historic sequence behavior, where the initial values start at 1...
+ SourceMock sequence = new SourceMock( 1 );
+ Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.NONE, Long.class, 1 );
+ for ( int i = 1; i < 11; i++ ) {
+ final Long next = ( Long ) optimizer.generate( sequence );
+ assertEquals( i, next.intValue() );
+ }
+ assertEquals( 10, sequence.getTimesCalled() );
+ assertEquals( 10, sequence.getCurrentValue() );
+
+ // test historic table behavior, where the initial values started at 0 (we now force 1 to be the first used id value)
+ sequence = new SourceMock( 0 );
+ optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.NONE, Long.class, 1 );
+ for ( int i = 1; i < 11; i++ ) {
+ final Long next = ( Long ) optimizer.generate( sequence );
+ assertEquals( i, next.intValue() );
+ }
+ assertEquals( 11, sequence.getTimesCalled() ); // an extra time to get to 1 initially
+ assertEquals( 10, sequence.getCurrentValue() );
+ }
+
+ public void testBasicHiLoOptimizerUsage() {
+ int increment = 10;
+ Long next;
+
+ // test historic sequence behavior, where the initial values start at 1...
+ SourceMock sequence = new SourceMock( 1 );
+ Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.HILO, Long.class, increment );
+ for ( int i = 1; i <= increment; i++ ) {
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( i, next.intValue() );
+ }
+ assertEquals( 1, sequence.getTimesCalled() ); // once to initialze state
+ assertEquals( 1, sequence.getCurrentValue() );
+ // force a "clock over"
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( 11, next.intValue() );
+ assertEquals( 2, sequence.getTimesCalled() );
+ assertEquals( 2, sequence.getCurrentValue() );
+
+ // test historic table behavior, where the initial values started at 0 (we now force 1 to be the first used id value)
+ sequence = new SourceMock( 0 );
+ optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.HILO, Long.class, increment );
+ for ( int i = 1; i <= increment; i++ ) {
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( i, next.intValue() );
+ }
+ assertEquals( 2, sequence.getTimesCalled() ); // here have have an extra call to get to 1 initially
+ assertEquals( 1, sequence.getCurrentValue() );
+ // force a "clock over"
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( 11, next.intValue() );
+ assertEquals( 3, sequence.getTimesCalled() );
+ assertEquals( 2, sequence.getCurrentValue() );
+ }
+
+ public void testBasicPooledOptimizerUsage() {
+ Long next;
+ // test historic sequence behavior, where the initial values start at 1...
+ SourceMock sequence = new SourceMock( 1, 10 );
+ Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 10 );
+ for ( int i = 1; i < 11; i++ ) {
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( i, next.intValue() );
+ }
+ assertEquals( 2, sequence.getTimesCalled() ); // twice to initialize state
+ assertEquals( 11, sequence.getCurrentValue() );
+ // force a "clock over"
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( 11, next.intValue() );
+ assertEquals( 3, sequence.getTimesCalled() );
+ assertEquals( 21, sequence.getCurrentValue() );
+ }
+
+ public void testSubsequentPooledOptimizerUsage() {
+ // test the pooled optimizer in situation where the sequence is already beyond its initial value on init.
+ // cheat by telling the sequence to start with 1000
+ final SourceMock sequence = new SourceMock( 1001, 3, 5 );
+ // but tell the optimizer the start-with is 1
+ final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 );
+
+ assertEquals( 5, sequence.getTimesCalled() );
+ assertEquals( 1001, sequence.getCurrentValue() );
+
+ Long next = (Long) optimizer.generate( sequence );
+ assertEquals( 1001, next.intValue() );
+ assertEquals( (5+1), sequence.getTimesCalled() );
+ assertEquals( (1001+3), sequence.getCurrentValue() );
+
+ next = (Long) optimizer.generate( sequence );
+ assertEquals( (1001+1), next.intValue() );
+ assertEquals( (5+1), sequence.getTimesCalled() );
+ assertEquals( (1001+3), sequence.getCurrentValue() );
+
+ next = (Long) optimizer.generate( sequence );
+ assertEquals( (1001+2), next.intValue() );
+ assertEquals( (5+1), sequence.getTimesCalled() );
+ assertEquals( (1001+3), sequence.getCurrentValue() );
+
+ // force a "clock over"
+ next = (Long) optimizer.generate( sequence );
+ assertEquals( (1001+3), next.intValue() );
+ assertEquals( (5+2), sequence.getTimesCalled() );
+ assertEquals( (1001+6), sequence.getCurrentValue() );
+ }
+
+// public void testBasicPooledLoOptimizerUsage() {
+// final SourceMock sequence = new SourceMock( 1, 3 );
+// final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL_LO, Long.class, 3 );
+//
+// assertEquals( 0, sequence.getTimesCalled() );
+// assertEquals( -1, sequence.getCurrentValue() );
+//
+// Long next = ( Long ) optimizer.generate( sequence );
+// assertEquals( 1, next.intValue() );
+// assertEquals( 1, sequence.getTimesCalled() );
+// assertEquals( 1, sequence.getCurrentValue() );
+//
+// next = ( Long ) optimizer.generate( sequence );
+// assertEquals( 2, next.intValue() );
+// assertEquals( 1, sequence.getTimesCalled() );
+// assertEquals( 1, sequence.getCurrentValue() );
+//
+// next = ( Long ) optimizer.generate( sequence );
+// assertEquals( 3, next.intValue() );
+// assertEquals( 1, sequence.getTimesCalled() );
+// assertEquals( 1, sequence.getCurrentValue() );
+//
+//// // force a "clock over"
+// next = ( Long ) optimizer.generate( sequence );
+// assertEquals( 4, next.intValue() );
+// assertEquals( 2, sequence.getTimesCalled() );
+// assertEquals( (1+3), sequence.getCurrentValue() );
+// }
+
+ public void testSubsequentPooledLoOptimizerUsage() {
+ // test the pooled optimizer in situation where the sequence is already beyond its initial value on init.
+ // cheat by telling the sequence to start with 1000
+ final SourceMock sequence = new SourceMock( 1001, 3, 5 );
+ // but tell the optimizer the start-with is 1
+ final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 );
+
+ assertEquals( 5, sequence.getTimesCalled() );
+ assertEquals( 1001, sequence.getCurrentValue() );
+
+ Long next = ( Long ) optimizer.generate( sequence );
+ assertEquals( (1001), next.intValue() );
+ assertEquals( (5+1), sequence.getTimesCalled() );
+ assertEquals( (1001+3), sequence.getCurrentValue() );
+
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( (1001+1), next.intValue() );
+ assertEquals( (5+1), sequence.getTimesCalled() );
+ assertEquals( (1001+3), sequence.getCurrentValue() );
+
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( (1001+2), next.intValue() );
+ assertEquals( (5+1), sequence.getTimesCalled() );
+ assertEquals( (1001+3), sequence.getCurrentValue() );
+
+// // force a "clock over"
+ next = ( Long ) optimizer.generate( sequence );
+ assertEquals( (1001+3), next.intValue() );
+ assertEquals( (5+2), sequence.getTimesCalled() );
+ assertEquals( (1001+6), sequence.getCurrentValue() );
+ }
+
+ public void testRecoveredPooledOptimizerUsage() {
+ final SourceMock sequence = new SourceMock( 1, 3 );
+ final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 );
+
+ assertEquals( 0, sequence.getTimesCalled() );
+ assertEquals( -1, sequence.getCurrentValue() );
+
+ Long next = ( Long ) optimizer.generate( sequence );
+ assertEquals( 1, next.intValue() );
+ assertEquals( 2, sequence.getTimesCalled() );
+ assertEquals( 4, sequence.getCurrentValue() );
+
+ // app ends, and starts back up (we should "lose" only 2 and 3 as id values)
+ final Optimizer optimizer2 = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 );
+ next = ( Long ) optimizer2.generate( sequence );
+ assertEquals( 4, next.intValue() );
+ assertEquals( 3, sequence.getTimesCalled() );
+ assertEquals( 7, sequence.getCurrentValue() );
+ }
+
+// public void testRecoveredPooledLoOptimizerUsage() {
+// final SourceMock sequence = new SourceMock( 1, 3 );
+// final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL_LO, Long.class, 3, 1 );
+//
+// assertEquals( 0, sequence.getTimesCalled() );
+// assertEquals( -1, sequence.getCurrentValue() );
+//
+// Long next = ( Long ) optimizer.generate( sequence );
+// assertEquals( 1, next.intValue() );
+// assertEquals( 1, sequence.getTimesCalled() );
+// assertEquals( 1, sequence.getCurrentValue() );
+//
+// // app ends, and starts back up (we should "lose" only 2 and 3 as id values)
+// final Optimizer optimizer2 = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL_LO, Long.class, 3, 1 );
+// next = ( Long ) optimizer2.generate( sequence );
+// assertEquals( 4, next.intValue() );
+// assertEquals( 2, sequence.getTimesCalled() );
+// assertEquals( 4, sequence.getCurrentValue() );
+// }
+
+ private static class SourceMock implements AccessCallback {
+ private long value;
+ private long initialValue;
+ private int increment;
+ private int timesCalled = 0;
+
+ public SourceMock(long initialValue) {
+ this( initialValue, 1 );
+ }
+
+ public SourceMock(long initialValue, int increment) {
+ this( initialValue, increment, 0 );
+ }
+
+ public SourceMock(long initialValue, int increment, int timesCalled) {
+ this.increment = increment;
+ this.timesCalled = timesCalled;
+ if ( timesCalled != 0 ) {
+ this.value=initialValue;
+ this.initialValue = 1;
+ }
+ else {
+ this.value=-1;
+ this.initialValue = initialValue;
+ }
+ }
+
+ public long getNextValue() {
+ try {
+ if ( timesCalled == 0 ) {
+ initValue();
+ return value;
+ }
+ else {
+ return value+=increment;
+ }
+ }
+ finally {
+ timesCalled++;
+ }
+ }
+
+ private void initValue() {
+ this.value = initialValue;
+ }
+
+ public int getTimesCalled() {
+ return timesCalled;
+ }
+
+ public long getCurrentValue() {
+ return value;
+ }
+ }
+
+// public void testNoopDumping() {
+// SourceMock sequence = new SourceMock( 1 );
+// Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.NONE, Long.class, 1 );
+// for ( int i = 1; i <= 41; i++ ) {
+// System.out.println( i + " => " + optimizer.generate( sequence ) + " (" + sequence.getCurrentValue() + ")" );
+// }
+// }
+//
+// public void testHiLoDumping() {
+// int increment = 10;
+// SourceMock sequence = new SourceMock( 1 );
+// Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.HILO, Long.class, increment );
+// for ( int i = 1; i <= 41; i++ ) {
+// System.out.println( i + " => " + optimizer.generate( sequence ) + " (" + sequence.getCurrentValue() + ")" );
+// }
+// }
+//
+// public void testPooledDumping() {
+// int increment = 10;
+// SourceMock sequence = new SourceMock( 1, increment );
+// Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, increment );
+// for ( int i = 1; i <= 41; i++ ) {
+// System.out.println( i + " => " + optimizer.generate( sequence ) + " (" + sequence.getCurrentValue() + ")" );
+// }
+// }
+
+}
13 years, 9 months
Hibernate SVN: r20888 - core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/id/enhanced.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2011-02-08 10:38:08 -0500 (Tue, 08 Feb 2011)
New Revision: 20888
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/id/enhanced/OptimizerFactory.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java
Log:
JBPAPP-5763 HHH-5217 Minimize double sequence value reads in PooledOptimizer
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/id/enhanced/OptimizerFactory.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/id/enhanced/OptimizerFactory.java 2011-02-03 18:27:30 UTC (rev 20887)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/id/enhanced/OptimizerFactory.java 2011-02-08 15:38:08 UTC (rev 20888)
@@ -47,6 +47,23 @@
private static Class[] CTOR_SIG = new Class[] { Class.class, int.class };
+ /**
+ * Marker interface for optimizer which wish to know the user-specified initial value.
+ * <p/>
+ * Used instead of constructor injection since that is already a public understanding and
+ * because not all optimizers care.
+ */
+ public static interface InitialValueAwareOptimizer {
+ /**
+ * Reports the user specified initial value to the optimizer.
+ * <p/>
+ * <tt>-1</tt> is used to indicate that the user did not specify.
+ *
+ * @param initialValue The initial value specified by the user, or <tt>-1</tt> to indicate that the
+ * user did not specify.
+ */
+ public void injectInitialValue(long initialValue);
+ }
public static Optimizer buildOptimizer(String type, Class returnClass, int incrementSize) {
String optimizerClassName;
if ( NONE.equals( type ) ) {
@@ -74,8 +91,25 @@
// the default...
return new NoopOptimizer( returnClass, incrementSize );
}
-
/**
+ * Builds an optimizer
+ *
+ * @param type The optimizer type, either a short-hand name or the {@link Optimizer} class name.
+ * @param returnClass The generated value java type
+ * @param incrementSize The increment size.
+ * @param explicitInitialValue The user supplied initial-value (-1 indicates the user did not specify).
+ *
+ * @return The built optimizer
+ */
+ @SuppressWarnings({ "UnnecessaryBoxing", "deprecation" })
+ public static Optimizer buildOptimizer(String type, Class returnClass, int incrementSize, long explicitInitialValue) {
+ final Optimizer optimizer = buildOptimizer( type, returnClass, incrementSize );
+ if ( InitialValueAwareOptimizer.class.isInstance( optimizer ) ) {
+ ( (InitialValueAwareOptimizer) optimizer ).injectInitialValue( explicitInitialValue );
+ }
+ return optimizer;
+ }
+ /**
* Common support for optimizer implementations.
*/
public static abstract class OptimizerSupport implements Optimizer {
@@ -242,10 +276,10 @@
* Optimizer which uses a pool of values, storing the next low value of the
* range in the database.
*/
- public static class PooledOptimizer extends OptimizerSupport {
+ public static class PooledOptimizer extends OptimizerSupport implements InitialValueAwareOptimizer{
private long value;
private long hiValue = -1;
-
+ private long initialValue = -1;
public PooledOptimizer(Class returnClass, int incrementSize) {
super( returnClass, incrementSize );
if ( incrementSize < 1 ) {
@@ -269,7 +303,14 @@
// we are using a sequence...
log.info( "pooled optimizer source reported [" + value + "] as the initial value; use of 1 or greater highly recommended" );
}
- hiValue = callback.getNextValue();
+ if ( ( initialValue == -1 && value < incrementSize ) || ( value == initialValue ) ) {
+ // the call to obtain next-value just gave us the initialValue
+ hiValue = callback.getNextValue();
+ }
+ else {
+ hiValue = value;
+ value = hiValue - incrementSize;
+ }
}
else if ( value >= hiValue ) {
hiValue = callback.getNextValue();
@@ -300,5 +341,9 @@
public long getLastValue() {
return value - 1;
}
+
+ public void injectInitialValue( long initialValue ) {
+ this.initialValue = initialValue;
+ }
}
}
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java 2011-02-03 18:27:30 UTC (rev 20887)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java 2011-02-08 15:38:08 UTC (rev 20888)
@@ -178,7 +178,7 @@
this.databaseStructure = buildDatabaseStructure( params, dialect, forceTableUse, sequenceName, initialValue, incrementSize );
- this.optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize );
+ this.optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize, -1 );
this.databaseStructure.prepare( optimizer );
}
@@ -281,7 +281,7 @@
* @param sequenceName The name to use for the sequence or table.
* @param initialValue The initial value.
* @param incrementSize the increment size to use (after any adjustments).
- * @return The db structure representation
+ * @return An abstraction for the actual database structure in use (table vs. sequence).
*/
protected DatabaseStructure buildDatabaseStructure(
Properties params,
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java 2011-02-03 18:27:30 UTC (rev 20887)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java 2011-02-08 15:38:08 UTC (rev 20888)
@@ -294,7 +294,7 @@
String defOptStrategy = incrementSize <= 1 ? OptimizerFactory.NONE : OptimizerFactory.POOL;
String optimizationStrategy = PropertiesHelper.getString( OPT_PARAM, params, defOptStrategy );
- optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize );
+ optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize, -1 );
}
/**
13 years, 9 months