org.springframework.jdbc.support.incrementer
Class HsqlMaxValueIncrementer

org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer
  |
  +--org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer

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.

Author:
Isabelle Muszynski, Jean-Pierre Pawlak, Thomas Risberg
Version: $Id: HsqlMaxValueIncrementer.java,v 1.2 2004/02/02 11:36:54 jhoeller Exp $

Constructor Summary
HsqlMaxValueIncrementer()
          Default constructor.
HsqlMaxValueIncrementer(DataSource ds, String incrementerName, String columnName)
          Alternative constructor.
HsqlMaxValueIncrementer(DataSource ds, String incrementerName, String columnName, int cacheSize)
          Alternative constructor.
HsqlMaxValueIncrementer(DataSource ds, String incrementerName, String columnName, boolean prefixWithZero, int padding)
          Alternative constructor.
HsqlMaxValueIncrementer(DataSource ds, String incrementerName, String columnName, boolean prefixWithZero, int padding, int cacheSize)
          Alternative constructor.

Method Summary
 voidsetPrefixWithZero(boolean prefixWithZero, int length)
          Set whether to prefix with zero.

Methods inherited from class org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer
afterPropertiesSet, getCacheSize, getColumnName, getDataSource, getIncrementerName, isDirty, nextDoubleValue, nextIntValue, nextLongValue, nextStringValue, nextValue, setCacheSize, setColumnName, setDataSource, setDirty, setIncrementerName

Constructor Detail

HsqlMaxValueIncrementer

public HsqlMaxValueIncrementer()
Default constructor.

HsqlMaxValueIncrementer

public HsqlMaxValueIncrementer(DataSource ds, String incrementerName, String columnName)
Alternative 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(DataSource ds, String incrementerName, String columnName, int cacheSize)
Alternative 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(DataSource ds, String incrementerName, String columnName, boolean prefixWithZero, int padding)
Alternative 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(DataSource ds, String incrementerName, String columnName, boolean prefixWithZero, int padding, int cacheSize)
Alternative 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)
Set whether to prefix with zero.

Association Links

to Class org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer.NextMaxValueProvider