org.pfsw.db.util
Class ObjectIdentifierDB

java.lang.Object
  extended by org.pfsw.text.ObjectIdGenerator
      extended by org.pfsw.db.util.ObjectIdentifierGenerator
          extended by org.pfsw.db.util.ObjectIdentifierDB
All Implemented Interfaces:
org.pfsw.bif.identifier.IObjectIdGenerator, ObjectIdentifierProducer, org.pfsw.text.StringGenerator

public class ObjectIdentifierDB
extends ObjectIdentifierGenerator

Instances of this class provide generation of unique identifiers backed by a specific database table. That means the next available id will be always updated in the database.


Field Summary
protected  java.lang.Integer blockSize
           
protected static int INITIAL_BLOCKSIZE
           
protected static java.lang.String OID_CN_BLOCKSIZE
           
protected static java.lang.String OID_CN_CATEGORY
           
protected static java.lang.String OID_CN_NEXTID
           
protected static java.lang.String OID_TABLE_NAME
           
protected  boolean tableInitialized
           
 
Fields inherited from class org.pfsw.text.ObjectIdGenerator
bufferLen, DEFAULT_LENGTH, DEFAULT_PAD_CHAR, DEFAULT_START_ID
 
Constructor Summary
ObjectIdentifierDB(javax.sql.DataSource ds)
          Initialize the new instance with the given data source.
ObjectIdentifierDB(javax.sql.DataSource ds, java.lang.String categoryName)
          Initialize the new instance with the data source.
ObjectIdentifierDB(java.lang.String tableQualifier, javax.sql.DataSource ds)
          Initialize the new instance with the given data source.
ObjectIdentifierDB(java.lang.String tableQualifier, javax.sql.DataSource ds, java.lang.String categoryName)
          Initialize the new instance with the data source.
 
Method Summary
protected  boolean anyRowExists(java.sql.Connection conn, java.lang.String sql)
           
protected  java.lang.String categoryString()
           
protected  boolean checkCategoryRowExists(java.sql.Connection conn)
           
protected  boolean checkTableExists(java.sql.Connection conn)
           
protected  void closeConnection(java.sql.Connection conn)
           
protected  void closeStatement(java.sql.Statement stmt)
           
protected  void createOidTable(java.sql.Connection conn)
           
protected  void createRowForCategory(java.sql.Connection conn)
           
 int getBlockSize()
          Returns the block size this generator is using.
protected  java.lang.String getCategory()
           
protected  javax.sql.DataSource getDataSource()
           
protected  java.sql.Connection getDbConnection()
           
protected  long getLastPrefetchedId()
           
protected  long getNextId()
           
protected  java.lang.String getQualifier()
           
protected  java.lang.String getSelect()
           
protected  java.lang.String getSelectAny()
           
protected  java.lang.String getSelectCategory()
           
protected  java.lang.String getTableName()
           
protected  java.lang.String getUpdate()
           
protected  long idFromDB()
           
protected  void loadNextIdFromDB()
           
protected  org.pfsw.logging.Logger logger()
           
protected  void reportSQLException(java.lang.String msg, java.sql.SQLException ex)
           
 void setBlockSize(int newValue)
          Set the block size this generator is using.
protected  void setCategory(java.lang.String newValue)
           
protected  void setDataSource(javax.sql.DataSource newValue)
           
protected  void setLastPrefetchedId(long newValue)
           
protected  void setNextId(long id)
           
protected  void setNextIdInDB(java.sql.Connection conn, long id)
           
protected  void setQualifier(java.lang.String newValue)
           
protected  void setSelect(java.lang.String newValue)
           
protected  void setSelectAny(java.lang.String newValue)
           
protected  void setSelectCategory(java.lang.String newValue)
           
protected  void setUpdate(java.lang.String newValue)
           
protected  java.lang.String sqlCreateOidTable()
           
protected  java.lang.String sqlInsertCategoryRow(java.lang.String cat)
           
protected  java.lang.String sqlSelectAny()
           
protected  java.lang.String sqlSelectCategory()
           
protected  java.lang.String sqlSelectNextId()
           
protected  java.lang.String sqlUpdateNextId()
           
protected  boolean tableInitialized()
           
 
Methods inherited from class org.pfsw.text.ObjectIdGenerator
calcBufferLength, generateString, generateString, getDefaultLength, getDefaultPadChar, getDefaultStartId, getFullLength, getLength, getNextAvailableId, getPadChar, getPrefix, getPrefixLength, hasPrefix, leftPad, newIdentifier, nextIdentifier, setLength, setNextAvailableId, setPadChar, setPrefix, str
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.pfsw.db.util.ObjectIdentifierProducer
nextIdentifier
 
Methods inherited from interface org.pfsw.bif.identifier.IObjectIdGenerator
newIdentifier
 

Field Detail

OID_TABLE_NAME

protected static final java.lang.String OID_TABLE_NAME
See Also:
Constant Field Values

OID_CN_CATEGORY

protected static final java.lang.String OID_CN_CATEGORY
See Also:
Constant Field Values

OID_CN_NEXTID

protected static final java.lang.String OID_CN_NEXTID
See Also:
Constant Field Values

OID_CN_BLOCKSIZE

protected static final java.lang.String OID_CN_BLOCKSIZE
See Also:
Constant Field Values

INITIAL_BLOCKSIZE

protected static final int INITIAL_BLOCKSIZE
See Also:
Constant Field Values

tableInitialized

protected boolean tableInitialized

blockSize

protected java.lang.Integer blockSize
Constructor Detail

ObjectIdentifierDB

public ObjectIdentifierDB(javax.sql.DataSource ds)
Initialize the new instance with the given data source.

Parameters:
ds - A valid data source that allows connection to a database

ObjectIdentifierDB

public ObjectIdentifierDB(java.lang.String tableQualifier,
                          javax.sql.DataSource ds)
Initialize the new instance with the given data source.

Parameters:
tableQualifier - A qualifier that is put in front of the table name
ds - A valid data source that allows connection to a database

ObjectIdentifierDB

public ObjectIdentifierDB(javax.sql.DataSource ds,
                          java.lang.String categoryName)
Initialize the new instance with the data source. Assign a category where the OIDs belong to.

Parameters:
ds - A valid data source that allows connection to a database
categoryName - The name of the OID's category

ObjectIdentifierDB

public ObjectIdentifierDB(java.lang.String tableQualifier,
                          javax.sql.DataSource ds,
                          java.lang.String categoryName)
Initialize the new instance with the data source. Assign a category where the OIDs belong to.

Parameters:
tableQualifier - A qualifier that is put in front of the table name
ds - A valid data source that allows connection to a database
categoryName - The name of the OID's category
Method Detail

getBlockSize

public int getBlockSize()
Returns the block size this generator is using.


setBlockSize

public void setBlockSize(int newValue)
Set the block size this generator is using.


getNextId

protected long getNextId()
Overrides:
getNextId in class org.pfsw.text.ObjectIdGenerator

loadNextIdFromDB

protected void loadNextIdFromDB()

setNextId

protected void setNextId(long id)
Overrides:
setNextId in class org.pfsw.text.ObjectIdGenerator

setNextIdInDB

protected void setNextIdInDB(java.sql.Connection conn,
                             long id)
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

tableInitialized

protected boolean tableInitialized()

idFromDB

protected long idFromDB()

sqlCreateOidTable

protected java.lang.String sqlCreateOidTable()

sqlInsertCategoryRow

protected java.lang.String sqlInsertCategoryRow(java.lang.String cat)

sqlUpdateNextId

protected java.lang.String sqlUpdateNextId()

sqlSelectNextId

protected java.lang.String sqlSelectNextId()

sqlSelectCategory

protected java.lang.String sqlSelectCategory()

sqlSelectAny

protected java.lang.String sqlSelectAny()

categoryString

protected java.lang.String categoryString()

createOidTable

protected void createOidTable(java.sql.Connection conn)
                       throws java.sql.SQLException
Throws:
java.sql.SQLException

createRowForCategory

protected void createRowForCategory(java.sql.Connection conn)
                             throws java.sql.SQLException
Throws:
java.sql.SQLException

checkTableExists

protected boolean checkTableExists(java.sql.Connection conn)

checkCategoryRowExists

protected boolean checkCategoryRowExists(java.sql.Connection conn)

anyRowExists

protected boolean anyRowExists(java.sql.Connection conn,
                               java.lang.String sql)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

reportSQLException

protected void reportSQLException(java.lang.String msg,
                                  java.sql.SQLException ex)

getTableName

protected java.lang.String getTableName()

getDbConnection

protected java.sql.Connection getDbConnection()
                                       throws java.sql.SQLException
Throws:
java.sql.SQLException

closeConnection

protected void closeConnection(java.sql.Connection conn)

closeStatement

protected void closeStatement(java.sql.Statement stmt)

logger

protected org.pfsw.logging.Logger logger()

getDataSource

protected javax.sql.DataSource getDataSource()

setDataSource

protected void setDataSource(javax.sql.DataSource newValue)

getCategory

protected java.lang.String getCategory()

setCategory

protected void setCategory(java.lang.String newValue)

getSelect

protected java.lang.String getSelect()

setSelect

protected void setSelect(java.lang.String newValue)

getSelectCategory

protected java.lang.String getSelectCategory()

setSelectCategory

protected void setSelectCategory(java.lang.String newValue)

getSelectAny

protected java.lang.String getSelectAny()

setSelectAny

protected void setSelectAny(java.lang.String newValue)

getUpdate

protected java.lang.String getUpdate()

setUpdate

protected void setUpdate(java.lang.String newValue)

getQualifier

protected java.lang.String getQualifier()

setQualifier

protected void setQualifier(java.lang.String newValue)

getLastPrefetchedId

protected long getLastPrefetchedId()

setLastPrefetchedId

protected void setLastPrefetchedId(long newValue)