public class SequenceHandler
extends java.lang.Object
CURRENT-VALUE
,
NEXT-VALUE
functions and CURRENT-VALUE
statement and an utility
contains
method. The access to these methods is synchronized so for a database
only one thread can execute a primitive on a sequence. The
SequenceManager
is
responsible for instantiating only one SequenceHandler
per database.
Implementations of this class will use different strategies for handling 4GL sequences,
depending on the native support from the respective database system. They will override the
four protected safeXXX
methods. It is guaranteed that when they are executed,
the database-level lock has been acquired. Because that, it is recommended that these methods
should be fast and should not acquire other locks to prevent possible dead-locks.
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
database
The database logical name on which this handler will work with.
|
private static java.util.logging.Logger |
LOG
Logger (safe as a JVM-wide value rather than as context-local).
|
Constructor and Description |
---|
SequenceHandler(java.lang.String ldbName)
The only constructor takes the name of the database as argument.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(java.lang.String seqName)
Test whether the database contains a sequence.
|
int64 |
getCurrentValue(java.lang.String seqName)
Queries the current value of a sequence.
|
int64 |
getNextValue(java.lang.String seqName)
Computes and returns the next value of a sequence.
|
protected static int64 |
getResultValue(java.lang.Object result)
Extract the int64 value from a query result set.
|
protected boolean |
safeContains(java.lang.String seqName,
java.lang.String ldbName)
Test whether the database contains a sequence.
|
protected int64 |
safeGetCurrentValue(java.lang.String seqName,
java.lang.String ldbName)
Queries the current value of a sequence.
|
protected int64 |
safeGetNextValue(java.lang.String seqName,
java.lang.String ldbName)
Computes and returns the next value of a sequence.
|
protected void |
safeSetValue(java.lang.String seqName,
java.lang.String ldbName,
long newVal)
Initialize (reset) the current value of a sequence.
|
void |
setValue(java.lang.String seqName,
long newVal)
Initialize (reset) the current value of a sequence.
|
private static final java.util.logging.Logger LOG
private java.lang.String database
public SequenceHandler(java.lang.String ldbName)
ldbName
- The database logical name on which this handler will work with.public final int64 getCurrentValue(java.lang.String seqName)
This method will acquire the lock for modifying sequences on this database and then will call the protected overridable safe version form derived classes.
seqName
- The name of the sequence.public final int64 getNextValue(java.lang.String seqName)
This method will acquire the lock for modifying sequences on this database and then will call the protected overridable safe version form derived classes.
seqName
- The name of the sequence.public final void setValue(java.lang.String seqName, long newVal)
This method will acquire the lock for modifying sequences on this database and then will call the protected overridable safe version form derived classes.
seqName
- The name of the sequence.newVal
- The value the sequence will be reseted to.public final boolean contains(java.lang.String seqName)
This method will acquire the lock for modifying sequences on this database and then will call the protected overridable safe version form derived classes.
seqName
- The name of the sequence.protected static int64 getResultValue(java.lang.Object result)
result
- Single result of a sequence query. May be null
.protected int64 safeGetCurrentValue(java.lang.String seqName, java.lang.String ldbName)
This method should be called only in a safe environment, where the database-level lock for access to sequences has already been acquired.
seqName
- The name of the sequence.ldbName
- The database to which the sequence belongs to. If is null then the first connected
database is assumed.protected int64 safeGetNextValue(java.lang.String seqName, java.lang.String ldbName)
This method should be called only in a safe environment, where the database-level lock for access to sequences has already been acquired.
seqName
- The name of the sequence.ldbName
- The database to which the sequence belongs to. If is null then
the first connected database is assumed.protected void safeSetValue(java.lang.String seqName, java.lang.String ldbName, long newVal)
This method should be called only in a safe environment, where the database-level lock for access to sequences has already been acquired.
seqName
- The name of the sequence.ldbName
- The database to which the sequence belongs to. If is null then
the first connected database is assumed.newVal
- The value the sequence will be reseted to.protected boolean safeContains(java.lang.String seqName, java.lang.String ldbName)
This method should be called only in a safe environment, where the database-level lock for access to sequences has already been acquired.
seqName
- The name of the sequence.ldbName
- The database to which the sequence belongs to. If is null then the first connected
database is assumed.