org.datanucleus.store.valuegenerator
Class AbstractGenerator

java.lang.Object
  extended by org.datanucleus.store.valuegenerator.AbstractGenerator
All Implemented Interfaces:
ValueGenerator
Direct Known Subclasses:
AbstractDatastoreGenerator, AbstractUIDGenerator, TimestampGenerator, TimestampValueGenerator

public abstract class AbstractGenerator
extends java.lang.Object
implements ValueGenerator

Abstract value generator.


Field Summary
protected  int allocationSize
          Allocation size
protected  ValueGenerationBlock block
          The current block of values that have been reserved.
protected  int initialValue
          Initial value (of the first id).
protected static Localiser LOCALISER
          Localisation of messages
protected  java.lang.String name
          Symbolic name for the sequence.
protected  java.util.Properties properties
          Properties controlling the generator behaviour.
protected  boolean repositoryExists
          Flag for whether we know that the repository exists.
 
Constructor Summary
AbstractGenerator(java.lang.String name, java.util.Properties props)
          Constructor.
 
Method Summary
 void allocate(int additional)
          Method to allocate a number of values into the block.
protected  boolean createRepository()
          Method to create any needed repository for the values.
 java.lang.Object current()
          Accessor for the current value allocated.
 long currentValue()
          Accessor for the current element in the sequence as a long.
 java.lang.String getName()
          Accessor for the symbolic name for this generator.
static java.lang.Class getStorageClass()
          Accessor for the storage class for values generated with this generator.
 java.lang.Object next()
          Get next value from the reserved block of values.
 long nextValue()
          Accessor for the next element in the sequence as a long.
protected  ValueGenerationBlock obtainGenerationBlock()
          Get a new block with the default number of ids.
protected  ValueGenerationBlock obtainGenerationBlock(int number)
          Get a new block with the specified number of ids.
protected  boolean repositoryExists()
          Method to return if the repository already exists.
protected  boolean requiresRepository()
          Indicator for whether the generator requires its own repository.
protected  ValueGenerationBlock reserveBlock()
          Method to reserve a default sized block of values.
protected abstract  ValueGenerationBlock reserveBlock(long size)
          Method to reserve a block of "size" values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static final Localiser LOCALISER
Localisation of messages


name

protected java.lang.String name
Symbolic name for the sequence.


properties

protected java.util.Properties properties
Properties controlling the generator behaviour.


allocationSize

protected int allocationSize
Allocation size


initialValue

protected int initialValue
Initial value (of the first id).


block

protected ValueGenerationBlock block
The current block of values that have been reserved.


repositoryExists

protected boolean repositoryExists
Flag for whether we know that the repository exists. Only applies if repository is required.

Constructor Detail

AbstractGenerator

public AbstractGenerator(java.lang.String name,
                         java.util.Properties props)
Constructor. Will receive the following properties (as a minimum) through this constructor.

Parameters:
name - Symbolic name for this generator
props - Properties controlling the behaviour of the generator (or null if not required).
Method Detail

getStorageClass

public static java.lang.Class getStorageClass()
Accessor for the storage class for values generated with this generator.

Returns:
Storage class (e.g Long.class)

getName

public java.lang.String getName()
Accessor for the symbolic name for this generator.

Specified by:
getName in interface ValueGenerator
Returns:
Symbolic name for the generator.

next

public java.lang.Object next()
Get next value from the reserved block of values.

Specified by:
next in interface ValueGenerator
Returns:
The next value

current

public java.lang.Object current()
Accessor for the current value allocated. Returns null if none are allocated

Specified by:
current in interface ValueGenerator
Returns:
The current value

nextValue

public long nextValue()
Accessor for the next element in the sequence as a long.

Specified by:
nextValue in interface ValueGenerator
Returns:
The next element
Throws:
NucleusDataStoreException - Thrown if not numeric

currentValue

public long currentValue()
Accessor for the current element in the sequence as a long.

Specified by:
currentValue in interface ValueGenerator
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 interface ValueGenerator
Parameters:
additional - The number to allocate

obtainGenerationBlock

protected ValueGenerationBlock obtainGenerationBlock()
Get a new block with the default number of ids.

Returns:
the block

obtainGenerationBlock

protected ValueGenerationBlock 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 reserveBlock()
Method to reserve a default sized block of values.

Returns:
The reserved block

reserveBlock

protected abstract ValueGenerationBlock reserveBlock(long size)
Method to reserve a block of "size" values.

Parameters:
size - Number of values to reserve
Returns:
The allocated block

requiresRepository

protected boolean requiresRepository()
Indicator for whether the generator requires its own repository. AbstractValueGenerator returns false and this should be overridden by all generators requiring a repository.

Returns:
Whether a repository is required.

repositoryExists

protected boolean repositoryExists()
Method to return if the repository already exists.

Returns:
Whether the repository exists

createRepository

protected boolean createRepository()
Method to create any needed repository for the values. AbstractValueGenerator just returns true and should be overridden by any implementing generator requiring its own repository.

Returns:
If all is ready for use


Copyright © 2011. All Rights Reserved.