Cacheable
SequenceUpdater.BulkInsertUpdater
, SequenceUpdater.SyssequenceUpdater
public abstract class SequenceUpdater extends java.lang.Object implements Cacheable
An object cached in the data dictionary which manages new values for sequences. Note that this class must be public and have a 0-arg constructor in order to satisfy the Cacheable contract.
This is the abstract superclass of specific implementations for specific sequences. For instance, one subclass handles the ANSI/ISO sequences stored in SYSSEQUENCES. Another subclass could handle the sequences stored in Derby's identity columns.
This class does a couple tricky things:
Here is the algorithm pursued when the caller asks for the next number in a sequence:
Modifier and Type | Class | Description |
---|---|---|
static class |
SequenceUpdater.BulkInsertUpdater |
Implementation of SequenceUpdater for use with the bulk-insert optimization
used by InsertResultSet.
|
static class |
SequenceUpdater.SyssequenceUpdater |
Specific implementation of SequenceUpdater for the sequences managed by
SYSSEQUENCES.
|
Modifier and Type | Field | Description |
---|---|---|
protected DataDictionaryImpl |
_dd |
|
protected SequenceGenerator |
_sequenceGenerator |
This is the object which allocates ranges of sequence values
|
protected java.lang.String |
_uuidString |
This is the key used to lookup this generator in the cache.
|
Constructor | Description |
---|---|
SequenceUpdater() |
No-arg constructor to satisfy the Cacheable contract
|
SequenceUpdater(DataDictionaryImpl dd) |
Normal constructor
|
Modifier and Type | Method | Description |
---|---|---|
void |
clean(boolean forRemove) |
Clean the object.
|
void |
clearIdentity() |
Put the object into the No Identity state.
|
Cacheable |
createIdentity(java.lang.Object key,
java.lang.Object createParameter) |
Create a new item.
|
protected abstract SequenceGenerator |
createSequenceGenerator(TransactionController readOnlyTC) |
Initialize the sequence generator.
|
SequenceUpdater.BulkInsertUpdater |
getBulkInsertUpdater(boolean restart) |
Get the SequenceUpdater used for the bulk-insert optimization in InsertResultSet.
|
private static Context |
getContextOrNull(java.lang.String contextID) |
Privileged lookup of a Context.
|
private static ContextService |
getContextService() |
Privileged lookup of the ContextService.
|
void |
getCurrentValueAndAdvance(NumberDataValue returnValue) |
Get the next sequence number managed by this generator and advance the number.
|
java.lang.Object |
getIdentity() |
Get the identity of this object.
|
private static LanguageConnectionContext |
getLCC() |
|
boolean |
isDirty() |
Returns true of the object is dirty.
|
private boolean |
isNumber(java.lang.String text) |
|
protected SequencePreallocator |
makePreallocator(TransactionController tc) |
Make a new range allocator (called when the generator is instantiated)
|
private StandardException |
missingAllocator(java.lang.String propertyName,
java.lang.String className,
java.lang.Exception e) |
|
java.lang.Long |
peekAtCurrentValue() |
Get the current value of the sequence generator without advancing it.
|
void |
reset(java.lang.Long newValue) |
Reset the sequence generator to a new start value.
|
Cacheable |
setIdentity(java.lang.Object key) |
Set the identity of the object.
|
private StandardException |
tooMuchContentionException() |
Create an exception to state that there is too much contention on the generator.
|
private StandardException |
unimplementedFeature() |
Report an unimplemented feature
|
boolean |
updateCurrentValueOnDisk(java.lang.Long oldValue,
java.lang.Long newValue) |
Update the value on disk.
|
protected abstract boolean |
updateCurrentValueOnDisk(TransactionController tc,
java.lang.Long oldValue,
java.lang.Long newValue,
boolean wait) |
Update the sequence value on disk.
|
protected DataDictionaryImpl _dd
protected java.lang.String _uuidString
protected SequenceGenerator _sequenceGenerator
public SequenceUpdater()
public SequenceUpdater(DataDictionaryImpl dd)
protected abstract SequenceGenerator createSequenceGenerator(TransactionController readOnlyTC) throws StandardException
Initialize the sequence generator. Work is done inside a read-only subtransaction of the session's execution transaction.
StandardException
protected abstract boolean updateCurrentValueOnDisk(TransactionController tc, java.lang.Long oldValue, java.lang.Long newValue, boolean wait) throws StandardException
Update the sequence value on disk. This method does its work in a subtransaction of the user's execution transaction.
tc
- The transaction to useoldValue
- Expected value on disk for this sequencenewValue
- The value to poke into the system table backing this sequencewait
- Whether to wait for a lockStandardException
- May throw an exception if a lock can't be obtained.private StandardException tooMuchContentionException()
Create an exception to state that there is too much contention on the generator. For backward compatibility reasons, different messages are needed by sequences and identities. See DERBY-5426.
public void clean(boolean forRemove) throws StandardException
Cacheable
clean
in interface Cacheable
StandardException
- Standard Derby error policy.public boolean isDirty()
Cacheable
public java.lang.Object getIdentity()
Cacheable
getIdentity
in interface Cacheable
public void clearIdentity()
Cacheable
clearIdentity
in interface Cacheable
public Cacheable createIdentity(java.lang.Object key, java.lang.Object createParameter) throws StandardException
Cacheable
Create a new item and set the identity of the object to represent it.
The object will be in the No Identity state,
ie. it will have just been created or clearIdentity() was just called.
The object must copy the information out of key, not just store a reference to key
if the key is not immutable.
After this call the expression getIdentity().equals(key) must return true.
If the class of the object needs to change (e.g. to support a different format)
then the object should create a new object, call its initParameter() with the parameters
the original object was called with, set its identity and return a reference to it. The cache
manager will discard the reference to the old object.
If an exception is thrown the object must be left in the no-identity state.
MT - single thread required - Method must only be called be cache manager
and the cache manager will guarantee only one thread can be calling it.
createIdentity
in interface Cacheable
StandardException
- If forCreate is true and the object cannot be created.CacheManager.create(java.lang.Object, java.lang.Object)
public Cacheable setIdentity(java.lang.Object key) throws StandardException
Cacheable
Set the identity of the object to represent an item that already exists,
e.g. an existing container.
The object will be in the No Identity state,
ie. it will have just been created or clearIdentity() was just called.
The object must copy the information out of key, not just store a reference to key.
After this call the expression getIdentity().equals(key) must return true.
If the class of the object needs to change (e.g. to support a different format)
then the object should create a new object, call its initParameter() with the parameters
the original object was called with, set its identity and return a reference to it. The cache
manager will discard the reference to the old object.
If an exception is thrown the object must be left in the no-identity state.
MT - single thread required - Method must only be called be cache manager
and the cache manager will guarantee only one thread can be calling it.
setIdentity
in interface Cacheable
StandardException
- Thrown on errorCacheable.setIdentity(java.lang.Object)
public void reset(java.lang.Long newValue) throws StandardException
Reset the sequence generator to a new start value. This is used by the special bulk-insert optimization in InsertResultSet.
StandardException
public SequenceUpdater.BulkInsertUpdater getBulkInsertUpdater(boolean restart) throws StandardException
Get the SequenceUpdater used for the bulk-insert optimization in InsertResultSet.
restart
- True if the counter should be re-initialized to its start position.StandardException
public void getCurrentValueAndAdvance(NumberDataValue returnValue) throws StandardException
Get the next sequence number managed by this generator and advance the number. Could raise an exception if the legal range is exhausted and wrap-around is not allowed. Only one thread at a time is allowed through here. We do not want a race between the two calls to the sequence generator: getCurrentValueAndAdvance() and allocateNewRange().
returnValue
- This value is stuffed with the new sequence number.StandardException
public java.lang.Long peekAtCurrentValue() throws StandardException
Get the current value of the sequence generator without advancing it. May return null if the generator is exhausted.
StandardException
public boolean updateCurrentValueOnDisk(java.lang.Long oldValue, java.lang.Long newValue) throws StandardException
Update the value on disk. Does its work in a subtransaction of the user's execution transaction. If that fails, raises a TOO MUCH CONTENTION exception.
StandardException
protected SequencePreallocator makePreallocator(TransactionController tc) throws StandardException
StandardException
private StandardException missingAllocator(java.lang.String propertyName, java.lang.String className, java.lang.Exception e)
private boolean isNumber(java.lang.String text)
private static LanguageConnectionContext getLCC()
private StandardException unimplementedFeature()
private static ContextService getContextService()
private static Context getContextOrNull(java.lang.String contextID)
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.