- java.lang.Object
-
- org.datanucleus.store.valuegenerator.AbstractGenerator<T>
-
- All Implemented Interfaces:
ValueGenerator<T>
- Direct Known Subclasses:
AbstractConnectedGenerator
,AbstractUUIDGenerator
,AUIDGenerator
,TimestampGenerator
,TimestampValueGenerator
,UUIDGenerator
,UUIDObjectGenerator
public abstract class AbstractGenerator<T> extends Object implements ValueGenerator<T>
Abstract value generator.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
allocationSize
Allocation sizeprotected ValueGenerationBlock<T>
block
The current block of values that have been reserved.protected int
initialValue
Initial value (of the first id).protected String
name
Symbolic name for the value generator.protected StoreManager
storeMgr
-
Fields inherited from interface org.datanucleus.store.valuegenerator.ValueGenerator
PROPERTY_CATALOG_NAME, PROPERTY_CLASS_NAME, PROPERTY_COLUMN_NAME, PROPERTY_FIELD_NAME, PROPERTY_KEY_CACHE_SIZE, PROPERTY_KEY_DATABASE_CACHE_SIZE, PROPERTY_KEY_INITIAL_VALUE, PROPERTY_KEY_MAX_VALUE, PROPERTY_KEY_MIN_VALUE, PROPERTY_ROOT_CLASS_NAME, PROPERTY_SCHEMA_NAME, PROPERTY_SEQUENCE_NAME, PROPERTY_SEQUENCETABLE_CATALOG, PROPERTY_SEQUENCETABLE_NAME_COLUMN, PROPERTY_SEQUENCETABLE_NEXTVAL_COLUMN, PROPERTY_SEQUENCETABLE_SCHEMA, PROPERTY_SEQUENCETABLE_TABLE, PROPERTY_TABLE_NAME
-
-
Constructor Summary
Constructors Constructor Description AbstractGenerator(StoreManager storeMgr, String name)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
allocate(int additional)
Method to allocate a number of values into the block.T
current()
Accessor for the current value allocated.long
currentValue()
Accessor for the current element as a long.String
getName()
Accessor for the symbolic name for this generator.T
next()
Get next value from the reserved block of values.long
nextValue()
Accessor for the next element as a long.protected ValueGenerationBlock<T>
obtainGenerationBlock()
Get a new block with the default number of ids.protected ValueGenerationBlock<T>
obtainGenerationBlock(int number)
Get a new block with the specified number of ids.protected ValueGenerationBlock<T>
reserveBlock()
Method to reserve a default sized block of values.protected abstract ValueGenerationBlock<T>
reserveBlock(long size)
Method to reserve a block of "size" values.
-
-
-
Field Detail
-
storeMgr
protected StoreManager storeMgr
-
name
protected String name
Symbolic name for the value generator.
-
allocationSize
protected int allocationSize
Allocation size
-
initialValue
protected int initialValue
Initial value (of the first id).
-
block
protected ValueGenerationBlock<T> block
The current block of values that have been reserved.
-
-
Constructor Detail
-
AbstractGenerator
public AbstractGenerator(StoreManager storeMgr, String name)
Constructor.- Parameters:
storeMgr
- Store Managername
- Symbolic name for this generator
-
-
Method Detail
-
getName
public String getName()
Accessor for the symbolic name for this generator.- Returns:
- Symbolic name for the generator.
-
next
public T next()
Get next value from the reserved block of values.- Specified by:
next
in interfaceValueGenerator<T>
- Returns:
- The next value
-
current
public T current()
Accessor for the current value allocated. Returns null if none are allocated- Specified by:
current
in interfaceValueGenerator<T>
- Returns:
- The current value
-
nextValue
public long nextValue()
Accessor for the next element as a long.- Specified by:
nextValue
in interfaceValueGenerator<T>
- Returns:
- The next element
- Throws:
NucleusDataStoreException
- Thrown if not numeric
-
currentValue
public long currentValue()
Accessor for the current element as a long.- Specified by:
currentValue
in interfaceValueGenerator<T>
- Returns:
- The current element
- Throws:
NucleusDataStoreException
- Thrown if not numeric
-
allocate
public void allocate(int additional)
Method to allocate a number of values into the block. If the block already exists and has remaining values, the additional values are added to the block.- Specified by:
allocate
in interfaceValueGenerator<T>
- Parameters:
additional
- The number to allocate
-
obtainGenerationBlock
protected ValueGenerationBlock<T> obtainGenerationBlock()
Get a new block with the default number of ids.- Returns:
- the block
-
obtainGenerationBlock
protected ValueGenerationBlock<T> obtainGenerationBlock(int number)
Get a new block with the specified number of ids.- Parameters:
number
- The number of additional ids required- Returns:
- the block
-
reserveBlock
protected ValueGenerationBlock<T> reserveBlock()
Method to reserve a default sized block of values.- Returns:
- The reserved block
-
reserveBlock
protected abstract ValueGenerationBlock<T> reserveBlock(long size)
Method to reserve a block of "size" values.- Parameters:
size
- Number of values to reserve- Returns:
- The allocated block
-
-