| java.lang.Object org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer org.springframework.jdbc.support.incrementer.DerbyMaxValueIncrementer
DerbyMaxValueIncrementer | public class DerbyMaxValueIncrementer extends AbstractDataFieldMaxValueIncrementer (Code) | | Class to increment maximum value of a given Derby table with the equivalent
of an auto-increment column. Note: If you use this class, your Derby key
column should NOT be defined as an IDENTITY column, as the sequence table does the job.
Thanks to Endre St¿lsvik for the suggestion!
The sequence is kept in a table. There should be one sequence table per
table that needs an auto-generated key.
Derby requires an additional column to be used for the insert since it is impossible
to insert a null into the identity column and have the value generated. This is solved by
providing the name of a dummy column that also must be created in the sequence table.
Example:
create table tab (id int not null primary key, text varchar(100));
create table tab_sequence (value int generated always as identity, dummy char(1));
insert into tab_sequence (dummy) values(null);
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.
HINT: Since Derby supports the JDBC 3.0 method getGeneratedKeys it's recommended to
use IDENTITY columns directly in the tables and then utilizing a
org.springframework.jdbc.support.KeyHolder when calling the with the update(PreparedStatementCreator psc, KeyHolder generatedKeyHolder) method of
the
org.springframework.jdbc.core.JdbcTemplate .
author: Thomas Risberg since: 2.5 |
DerbyMaxValueIncrementer | public DerbyMaxValueIncrementer()(Code) | | Default constructor.
|
DerbyMaxValueIncrementer | public DerbyMaxValueIncrementer(DataSource ds, String incrementerName, String columnName)(Code) | | Convenience constructor.
Parameters: ds - the DataSource to use Parameters: incrementerName - the name of the sequence/table to use Parameters: columnName - the name of the column in the sequence table to use |
DerbyMaxValueIncrementer | public DerbyMaxValueIncrementer(DataSource ds, String incrementerName, String columnName, String dummyName)(Code) | | Convenience constructor.
Parameters: ds - the DataSource to use Parameters: incrementerName - the name of the sequence/table to use Parameters: columnName - the name of the column in the sequence table to use Parameters: dummyName - the name of the dummy column used for inserts |
afterPropertiesSet | public void afterPropertiesSet()(Code) | | |
getCacheSize | public int getCacheSize()(Code) | | Return the number of buffered keys.
|
getColumnName | public String getColumnName()(Code) | | Return the name of the column in the sequence table.
|
getDummyName | public String getDummyName()(Code) | | Return the name of the dummy column.
|
setCacheSize | public void setCacheSize(int cacheSize)(Code) | | Set the number of buffered keys.
|
setColumnName | public void setColumnName(String columnName)(Code) | | Set the name of the column in the sequence table.
|
setDummyName | public void setDummyName(String dummyName)(Code) | | Set the name of the dummy column.
|
Fields inherited from org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer | protected int paddingLength(Code)(Java Doc)
|
|
|