Skip to content

Commit e04e8cc

Browse files
committed
improve javadoc of "pooled" optimizers
1 parent 6f8595e commit e04e8cc

File tree

4 files changed

+55
-12
lines changed

4 files changed

+55
-12
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/MappingSettings.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,20 @@ public interface MappingSettings {
118118
String KEYWORD_AUTO_QUOTING_ENABLED = "hibernate.auto_quote_keyword";
119119

120120
/**
121-
* When a generator specifies an increment size and an optimizer was not explicitly
122-
* specified, which of the "pooled" optimizers should be preferred? Can specify an
123-
* optimizer short name or the name of a class which implements
124-
* {@link org.hibernate.id.enhanced.Optimizer}.
121+
* Specifies an {@linkplain org.hibernate.id.enhanced.Optimizer optimizer}
122+
* which should be used when a generator specifies an {@code allocationSize}
123+
* and no optimizer is not explicitly specified, either:
124+
* <ul>
125+
* <li>a class implementing {@link org.hibernate.id.enhanced.Optimizer},
126+
* <li>the name of a class implementing {@code Optimizer}, or</li>
127+
* <li>an {@linkplain StandardOptimizerDescriptor optimizer short name}.
128+
* </ul>
125129
*
126130
* @settingDefault {@link StandardOptimizerDescriptor#POOLED}
131+
*
132+
* @see org.hibernate.id.enhanced.PooledOptimizer
133+
* @see org.hibernate.id.enhanced.PooledLoOptimizer
134+
* @see org.hibernate.id.enhanced.HiLoOptimizer
127135
*/
128136
String PREFERRED_POOLED_OPTIMIZER = "hibernate.id.optimizer.pooled.preferred";
129137

hibernate-core/src/main/java/org/hibernate/id/enhanced/Optimizer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@
1515
* this optimization takes the form of trying to ensure we do not have to
1616
* hit the database on each and every request to get an identifier value.
1717
* <p>
18+
* An optimizer may be selected by setting the configuration property
19+
* {@value org.hibernate.cfg.MappingSettings#PREFERRED_POOLED_OPTIMIZER}.
20+
* <p>
1821
* Optimizers work on constructor injection. They should provide a
1922
* constructor accepting the following arguments:
2023
* <ol>
2124
* <li>{@code java.lang.Class} - The return type for the generated values</li>
2225
* <li>{@code int} - The increment size</li>
2326
* </ol>
2427
*
28+
* @see org.hibernate.cfg.MappingSettings#PREFERRED_POOLED_OPTIMIZER
29+
*
2530
* @author Steve Ebersole
2631
*/
2732
public interface Optimizer {

hibernate-core/src/main/java/org/hibernate/id/enhanced/PooledLoOptimizer.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,27 @@
1717
import java.util.concurrent.locks.ReentrantLock;
1818

1919
/**
20-
* Variation of {@link PooledOptimizer} which interprets the incoming database
21-
* value as the lo value, rather than the hi value.
20+
* Optimizer which uses a pool of values, backed by a <em>logical sequence</em>.
21+
* A logical sequence is usually just an unpooled sequence or table generator.
22+
* <p>
23+
* The pool size is controlled by the {@code allocationSize} of a
24+
* {@linkplain jakarta.persistence.SequenceGenerator sequence generator} or
25+
* {@linkplain jakarta.persistence.TableGenerator sequence generator}.
26+
* <p>
27+
* From time to time, the optimizer allocates a range of values to itself,
28+
* interpreting the next value retrieved from the logical sequence as the
29+
* lower bound on the range of newly allocated ids. Thus, the generated ids
30+
* begin with the value retrieved from the logical sequence.
31+
* <p>
32+
* The {@link PooledOptimizer} is similar, but interprets the current value
33+
* of the logical sequence as an upper bound on the range of already-allocated
34+
* ids.
2235
*
2336
* @author Steve Ebersole
2437
*
2538
* @see PooledOptimizer
39+
* @see jakarta.persistence.SequenceGenerator#allocationSize
40+
* @see jakarta.persistence.TableGenerator#allocationSize
2641
*/
2742
public class PooledLoOptimizer extends AbstractOptimizer {
2843

hibernate-core/src/main/java/org/hibernate/id/enhanced/PooledOptimizer.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,33 @@
2020
import java.util.concurrent.locks.ReentrantLock;
2121

2222
/**
23-
* Optimizer which uses a pool of values, storing the next low value of the range
24-
* in the database.
23+
* Optimizer which uses a pool of values, backed by a <em>logical sequence</em>.
24+
* A logical sequence is usually just an unpooled sequence or table generator.
2525
* <p>
26-
* This optimizer works essentially the same as the {@link HiLoOptimizer}, except
27-
* that here the bucket ranges are actually encoded into the database structures.
26+
* The pool size is controlled by the {@code allocationSize} of a
27+
* {@linkplain jakarta.persistence.SequenceGenerator sequence generator} or
28+
* {@linkplain jakarta.persistence.TableGenerator sequence generator}.
2829
* <p>
29-
* If you prefer that the database value be interpreted as the bottom end of our
30-
* current range, then use the {@link PooledLoOptimizer} strategy.
30+
* This optimizer interprets the current value held by its underlying logical
31+
* sequence (that is, the last value generated by a database sequence, or the
32+
* current value of a table row emulating a sequence) as an upper bound on the
33+
* range of already-allocated ids. From time to time, the optimizer allocates
34+
* a range of values to itself, interpreting the next value retrieved from the
35+
* logical sequence as an upper bound on the range of newly allocated ids.
36+
* <p>
37+
* The {@link PooledLoOptimizer} is similar, but interprets the current value
38+
* of the logical sequence as a lower bound on the range of already-allocated
39+
* ids.
40+
* <p>
41+
* This optimizer has similar performance characteristics to the
42+
* {@link HiLoOptimizer}, but here the range bounds are stored directly by the
43+
* underlying database structures.
3144
*
3245
* @author Steve Ebersole
3346
*
3447
* @see PooledLoOptimizer
48+
* @see jakarta.persistence.SequenceGenerator#allocationSize
49+
* @see jakarta.persistence.TableGenerator#allocationSize
3550
*/
3651
public class PooledOptimizer extends AbstractOptimizer implements InitialValueAwareOptimizer {
3752

0 commit comments

Comments
 (0)