com.interface21.jdbc.core.support
Class HsqlMaxValueIncrementer

java.lang.Object
  |
  +--com.interface21.jdbc.core.support.AbstractDataFieldMaxValueIncrementer
        |
        +--com.interface21.jdbc.core.support.HsqlMaxValueIncrementer
All Implemented Interfaces:
DataFieldMaxValueIncrementer, InitializingBean

public class HsqlMaxValueIncrementer
extends AbstractDataFieldMaxValueIncrementer

Class to increment maximum value of a given HSQL table with the equivalent of an auto-increment column (note : if you use this class, your HSQL key column should NOT be auto-increment, as the sequence table does the job)
The sequence is kept in a table; there should be one sequence table per table that needs an auto-generated key.

Example:
  create table tab (id int not null primary key, text varchar(100));
  create table tab_sequence (value identity);
  insert into tab_sequence values(0);

If cacheSize is set, the intermediate values are served without querying the database. If the server or your application is stopped or crashes or a transaction is rolled back, the unused values will never be served. The maximum hole size in numbering is consequently the value of cacheSize.

Version:
$Id: HsqlMaxValueIncrementer.java,v 1.3 2003/06/19 05:06:25 trisberg Exp $
Author:
Isabelle Muszynski, Jean-Pierre Pawlak, Thomas Risberg

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
HsqlMaxValueIncrementer()
          Default constructor
HsqlMaxValueIncrementer(javax.sql.DataSource ds, java.lang.String incrementerName, java.lang.String columnName)
          Constructor
HsqlMaxValueIncrementer(javax.sql.DataSource ds, java.lang.String incrementerName, java.lang.String columnName, boolean prefixWithZero, int padding)
          Constructor
HsqlMaxValueIncrementer(javax.sql.DataSource ds, java.lang.String incrementerName, java.lang.String columnName, boolean prefixWithZero, int padding, int cacheSize)
          Constructor
HsqlMaxValueIncrementer(javax.sql.DataSource ds, java.lang.String incrementerName, java.lang.String columnName, int cacheSize)
          Constructor
 
Method Summary
protected  double incrementDoubleValue()
          Template method implementation to be provided by concrete subclasses
protected  int incrementIntValue()
          Template method implementation to be provided by concrete subclasses
protected  long incrementLongValue()
          Template method implementation to be provided by concrete subclasses
protected  java.lang.String incrementStringValue()
          Template method implementation to be provided by concrete subclasses
 void setPrefixWithZero(boolean prefixWithZero, int length)
          Sets the prefixWithZero.
 
Methods inherited from class com.interface21.jdbc.core.support.AbstractDataFieldMaxValueIncrementer
afterPropertiesSet, getCacheSize, getColumnName, getDataSource, getIncrementerName, isDirty, nextDoubleValue, nextIntValue, nextLongValue, nextStringValue, nextValue, setCacheSize, setColumnName, setDataSource, setDirty, setIncrementerName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

HsqlMaxValueIncrementer

public HsqlMaxValueIncrementer()
Default constructor

HsqlMaxValueIncrementer

public HsqlMaxValueIncrementer(javax.sql.DataSource ds,
                               java.lang.String incrementerName,
                               java.lang.String columnName)
Constructor
Parameters:
ds - the datasource to use
incrementerName - the name of the sequence/table to use
columnName - the name of the column in the sequence table to use

HsqlMaxValueIncrementer

public HsqlMaxValueIncrementer(javax.sql.DataSource ds,
                               java.lang.String incrementerName,
                               java.lang.String columnName,
                               int cacheSize)
Constructor
Parameters:
ds - the datasource to use
incrementerName - the name of the sequence/table to use
columnName - the name of the column in the sequence table to use
cacheSize - the number of buffered keys

HsqlMaxValueIncrementer

public HsqlMaxValueIncrementer(javax.sql.DataSource ds,
                               java.lang.String incrementerName,
                               java.lang.String columnName,
                               boolean prefixWithZero,
                               int padding)
Constructor
Parameters:
ds - the datasource to use
incrementerName - the name of the sequence/table to use
columnName - the name of the column in the sequence table to use
prefixWithZero - in case of a String return value, should the string be prefixed with zeroes
padding - the length to which the string return value should be padded with zeroes

HsqlMaxValueIncrementer

public HsqlMaxValueIncrementer(javax.sql.DataSource ds,
                               java.lang.String incrementerName,
                               java.lang.String columnName,
                               boolean prefixWithZero,
                               int padding,
                               int cacheSize)
Constructor
Parameters:
ds - the datasource to use
incrementerName - the name of the sequence/table to use
columnName - the name of the column in the sequence table to use
prefixWithZero - in case of a String return value, should the string be prefixed with zeroes
padding - the length to which the string return value should be padded with zeroes
cacheSize - the number of buffered keys
Method Detail

setPrefixWithZero

public void setPrefixWithZero(boolean prefixWithZero,
                              int length)
Sets the prefixWithZero.
Parameters:
prefixWithZero - The prefixWithZero to set

incrementIntValue

protected int incrementIntValue()
Description copied from class: AbstractDataFieldMaxValueIncrementer
Template method implementation to be provided by concrete subclasses
Overrides:
incrementIntValue in class AbstractDataFieldMaxValueIncrementer
See Also:
AbstractDataFieldMaxValueIncrementer.incrementIntValue()

incrementLongValue

protected long incrementLongValue()
Description copied from class: AbstractDataFieldMaxValueIncrementer
Template method implementation to be provided by concrete subclasses
Overrides:
incrementLongValue in class AbstractDataFieldMaxValueIncrementer
See Also:
AbstractDataFieldMaxValueIncrementer.incrementLongValue()

incrementDoubleValue

protected double incrementDoubleValue()
Description copied from class: AbstractDataFieldMaxValueIncrementer
Template method implementation to be provided by concrete subclasses
Overrides:
incrementDoubleValue in class AbstractDataFieldMaxValueIncrementer
See Also:
AbstractDataFieldMaxValueIncrementer.incrementDoubleValue()

incrementStringValue

protected java.lang.String incrementStringValue()
Description copied from class: AbstractDataFieldMaxValueIncrementer
Template method implementation to be provided by concrete subclasses
Overrides:
incrementStringValue in class AbstractDataFieldMaxValueIncrementer
See Also:
AbstractDataFieldMaxValueIncrementer.incrementStringValue()


Rod Johnson and Spring contributors 2001-2003.