public class PrimaryKeyFactory extends DumpableObject
This class also increases INSERT performance because is avoids
to perform the 'select max(column) from table'
to find out a new primary key value. It also has the advantage
of being database-independent (not relying on particular features
of the RDBMS system).
Note that primary keys can be requested only for DBObjects that are told to be managed by the factory. It also works only for tables which do NOT have a composed primary key. Note also that there should only exist one single Primary key factory at a time. If there were two managing the same tables they would confuse each other.
DBObject
Constructor and Description |
---|
PrimaryKeyFactory(javax.sql.DataSource connPool,
DBObject... tables)
Constructs the PrimaryKeyFactory by fetching the current maximum
primary key values of all managed tables from the database.
|
PrimaryKeyFactory(DBConnectionPool connPool)
Constructs an empty PrimaryKeyFactory.
|
PrimaryKeyFactory(DBObject... tables)
Same as
PrimaryKeyFactory(DataSource, DBObject[]) but tries to
get the ConnectionPool from the DBObject class. |
Modifier and Type | Method and Description |
---|---|
void |
addKeyManagementFor(DBObject dbo)
Adds primary key management for the given DBObject.
|
int |
getKeyFor(java.lang.String tableName)
Returns a new primary key value for the given table.
|
boolean |
isKeyAvailableFor(java.lang.String tableName)
Tells whether the given table is managed by this factory.
|
DumpString |
toDumpString(DumpString s)
Returns a string that displays the current content of this factory
for debugging purposes.
|
ToString |
toString(ToString s)
This method allows subclasses to add values to the existing ToString of the superclass.
|
configureDumpHeadlineLength, configureDumpMaxElementsPrinted, copyDumpStringValues, copyToStringValues, createDumpHeader, toDumpString, toString
public PrimaryKeyFactory(javax.sql.DataSource connPool, DBObject... tables) throws java.lang.Exception
connPool
- The DBConnectionPool instancetables
- Instances of DBObjects to be managedjava.lang.Exception
public PrimaryKeyFactory(DBObject... tables) throws java.lang.Exception
PrimaryKeyFactory(DataSource, DBObject[])
but tries to
get the ConnectionPool from the DBObject class.tables
- Instances of DBObjects to be managedjava.lang.Exception
public PrimaryKeyFactory(DBConnectionPool connPool) throws java.lang.Exception
connPool
- The DBConnectionPool instancejava.lang.Exception
addKeyManagementFor(DBObject)
public int getKeyFor(java.lang.String tableName)
java.lang.IllegalArgumentException
- if the table is not managed by the factory.public boolean isKeyAvailableFor(java.lang.String tableName)
public void addKeyManagementFor(DBObject dbo) throws java.lang.Exception
java.lang.Exception
public ToString toString(ToString s)
Dumpable
toString
in interface Dumpable
toString
in class DumpableObject
public DumpString toDumpString(DumpString s)
toDumpString
in interface Dumpable
toDumpString
in class DumpableObject
Copyright © 2014 EsprIT-Systems. All Rights Reserved.