|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectnet.spy.SpyObject
net.spy.db.GetPK
Primary key generator. This is an extensible singleton that provides access to a database-backed set of primary keys along with a fetch-ahead cache of those keys.
The default implementation assumes you have the following table
(primary_key) in the database the configuration defines:
| primary_keys | ||
|---|---|---|
| Column Name | Column Type | Column Description |
| table_name | varchar | The name of the table (or other resource) for which we are generating the given primary key. All table names in this column must be in lowercase as the input from the user will be lowercased on key retrieval. |
| primary_key | numeric | The next primary key value issued. |
| incr_value | numeric | The amount to increment the primary key each time. |
Other schemas may exist as long as they fit into the ``update something, select something'' model and they operate as described below.
| Constructor Summary | |
protected |
GetPK()
Constructor for an extensible Singleton. |
| Method Summary | |
static GetPK |
getInstance()
Get the instance of GetPK. |
BigDecimal |
getPrimaryKey(SpyConfig conf,
String table)
Get a primary key from the database described in the given config. |
protected DBSP |
getSelectDBSP(Connection conn)
Get the DBSP required for selecting primary key information back out of the primary key table. |
protected DBSP |
getUpdateDBSP(Connection conn)
Get the DBSP required for updating the primary key table. |
| Methods inherited from class net.spy.SpyObject |
getLogger |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
protected GetPK()
| Method Detail |
public static GetPK getInstance()
public BigDecimal getPrimaryKey(SpyConfig conf,
String table)
throws SQLException
conf - the configurationtable - the table for which the key is needed
SQLException - if there's a problem getting the key
protected DBSP getUpdateDBSP(Connection conn)
throws SQLException
A subclass may override this to change the behavior of the first
part of the ``fetch from db'' stage. The DBSP returned will take
exactly one parameter: table_name and will be called
via executeUpdate. The update must update exactly one row.
Any more or fewer will cause the process to fail and an exception
will be thrown.
For an example implementation, please see UpdatePrimaryKey
(this is the default).
conn - the connection to use (already in a transaction)
SQLException - if there's a problem getting the DBSP
protected DBSP getSelectDBSP(Connection conn)
throws SQLException
A subclass may override this method to change the behavior of the
select statement that finds the range of results for a table. The
DBSP returned will take exactly one parameter:
table_name and return a result set containing at least
the following two columns:
first_key - the first key in the rangelast_key - the last key in the range
For an example implementation, please see SelectPrimaryKey
(this is the default).
conn - the connection to use (already in a transaction)
SQLException - if there's a problem getting the DBSP
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||