com.interface21.jdbc.core.support
Class MySQLMaxValueIncrementer

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

public class MySQLMaxValueIncrementer
extends AbstractDataFieldMaxValueIncrementer

Class to increment maximum value of a given MySQL table with the equivalent of an auto-increment column (note : if you use this class, your MySQL 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. The table type of the sequence table should be MyISAM so the sequences are allocated without regard to any transactions that might be in progress.

Example:
  create table tab (id int unsigned not null primary key, text varchar(100));
  create table tab_sequence (value int not null) type=MYISAM;
  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: MySQLMaxValueIncrementer.java,v 1.16 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
MySQLMaxValueIncrementer()
          Default constructor
MySQLMaxValueIncrementer(javax.sql.DataSource ds, java.lang.String incrementerName, java.lang.String columnName)
          Constructor
MySQLMaxValueIncrementer(javax.sql.DataSource ds, java.lang.String incrementerName, java.lang.String columnName, boolean prefixWithZero, int padding)
          Constructor
MySQLMaxValueIncrementer(javax.sql.DataSource ds, java.lang.String incrementerName, java.lang.String columnName, boolean prefixWithZero, int padding, int cacheSize)
          Constructor
MySQLMaxValueIncrementer(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

MySQLMaxValueIncrementer

public MySQLMaxValueIncrementer()
Default constructor

MySQLMaxValueIncrementer

public MySQLMaxValueIncrementer(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

MySQLMaxValueIncrementer

public MySQLMaxValueIncrementer(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

MySQLMaxValueIncrementer

public MySQLMaxValueIncrementer(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

MySQLMaxValueIncrementer

public MySQLMaxValueIncrementer(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.