org.ujorm.orm
Class UjoSequencer

java.lang.Object
  extended by org.ujorm.orm.UjoSequencer
Direct Known Subclasses:
NativeDbSequencer

public class UjoSequencer
extends Object

The default sequence provider. A result value is recieved from a special database table.


Field Summary
protected  long maxValue
          Total limit, zero means no restriction
static int SEQ_LIMIT
          DB field: seqLimit
static int SEQ_MAX_VALUE
          DB field: maxValue
static int SEQ_STEP
          DB field: step
protected  long seqLimit
          Buffer limit
protected  long sequence
          Current sequence value
protected  MetaTable table
          Basic table.
 
Constructor Summary
UjoSequencer(MetaTable table)
           
 
Method Summary
protected  int executeSql(Connection connection, String sql, String tableName)
          Executes UPDATE for required parameters
 long[] getCurrentDBSequence(Connection connection, StringBuilder sql)
          Returns current db sequence for an actual table with a performance optimizations.
 MetaDatabase getDatabase()
          Returns model of the database
 String getDatabaseSchema()
          Returns the database schema
 int getIncrement()
          The UJO cache is the number of pre-allocated numbers inside the OrmUjo framework.
 int getInitDbCache()
          The cache of a database sequence is zero by default.
 MetaTable getTable()
          Returns a related table or null if sequence is general for the all MetaDatabase space
 boolean isSequenceTableRequired()
          Method returns true because the internal table 'ujorm_pk_support' is required to get a next sequence value.
 long nextValue(Session session)
          Returns the next sequence value by a synchronized method.
 void reset()
          Forces to reload sequence from db on next call for nextValue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEQ_LIMIT

public static final int SEQ_LIMIT
DB field: seqLimit

See Also:
Constant Field Values

SEQ_STEP

public static final int SEQ_STEP
DB field: step

See Also:
Constant Field Values

SEQ_MAX_VALUE

public static final int SEQ_MAX_VALUE
DB field: maxValue

See Also:
Constant Field Values

table

protected final MetaTable table
Basic table.


sequence

protected long sequence
Current sequence value


seqLimit

protected long seqLimit
Buffer limit


maxValue

protected long maxValue
Total limit, zero means no restriction

Constructor Detail

UjoSequencer

public UjoSequencer(MetaTable table)
Method Detail

nextValue

public long nextValue(Session session)
Returns the next sequence value by a synchronized method.


getDatabaseSchema

public String getDatabaseSchema()
Returns the database schema


getIncrement

public int getIncrement()
The UJO cache is the number of pre-allocated numbers inside the OrmUjo framework.


getInitDbCache

public int getInitDbCache()
The cache of a database sequence is zero by default.


getDatabase

public MetaDatabase getDatabase()
Returns model of the database


getTable

public MetaTable getTable()
Returns a related table or null if sequence is general for the all MetaDatabase space


isSequenceTableRequired

public boolean isSequenceTableRequired()
Method returns true because the internal table 'ujorm_pk_support' is required to get a next sequence value. In case you have a different imlementation, there is possible overwrite this method and return an another value.


reset

public void reset()
Forces to reload sequence from db on next call for nextValue.


getCurrentDBSequence

public long[] getCurrentDBSequence(Connection connection,
                                   StringBuilder sql)
                            throws Exception
Returns current db sequence for an actual table with a performance optimizations.

Parameters:
connection - Connection
sql - Temporarry buffer for a better performance. The value can be null a not null will be cleaned always.
Returns:
Returns current db sequence for an actual table with a value order:
[SEQ_LIMIT, SEQ_STEP, SEQ_MAX_VALUE].
If no sequence is found then the method returns the value null.
Throws:
Exception

executeSql

protected int executeSql(Connection connection,
                         String sql,
                         String tableName)
                  throws SQLException
Executes UPDATE for required parameters

Throws:
SQLException


Copyright 2013, Pavel Ponec