com.anthonyeden.lib.db
Class UniqueIDGenerator

java.lang.Object
  extended bycom.anthonyeden.lib.db.UniqueIDGenerator

public class UniqueIDGenerator
extends java.lang.Object

Unique ID generator which retrieves and increments a unique integer, prefix and suffix from a database.

Author:
Anthony Eden

Constructor Summary
UniqueIDGenerator(java.sql.Connection connection)
          Create a new UniqueIDGenerator using the given JDBC connection.
UniqueIDGenerator(LockManager lockManager, java.sql.Connection connection)
          Create a new UniqueIDGenerator using the given LockManager and JDBC connection.
 
Method Summary
 void createIdType(java.lang.String type, java.lang.String prefix, java.lang.String suffix, int initialValue)
          Add an ID type to the database.
 java.lang.String generateId(java.lang.String type)
          Generate the specified ID type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UniqueIDGenerator

public UniqueIDGenerator(java.sql.Connection connection)
                  throws java.sql.SQLException
Create a new UniqueIDGenerator using the given JDBC connection. The UniqueIDGenerator's LockManager uses the given connection object as well.

Parameters:
connection - The JDBC connection
Throws:
java.sql.SQLException

UniqueIDGenerator

public UniqueIDGenerator(LockManager lockManager,
                         java.sql.Connection connection)
                  throws java.sql.SQLException
Create a new UniqueIDGenerator using the given LockManager and JDBC connection.

Parameters:
lockManager - The lock manager
connection - The JDBC connection
Throws:
java.sql.SQLException
Method Detail

generateId

public java.lang.String generateId(java.lang.String type)
                            throws java.lang.Exception
Generate the specified ID type.

Parameters:
type - A type String
Returns:
The ID
Throws:
java.lang.Exception

createIdType

public void createIdType(java.lang.String type,
                         java.lang.String prefix,
                         java.lang.String suffix,
                         int initialValue)
                  throws java.lang.Exception
Add an ID type to the database. The type must not be null and must not already exist in the database. The given prefix and suffix will be appended to the beginning and the end of the unique number when ids are created. If the prefix and suffix are null then their values will be an empty String.

Parameters:
type - The type String
prefix - Prefix String or null
suffix - Suffix String or null
Throws:
java.lang.Exception


Copyright (c) 2000-2003 Anthony Eden. All Rights Reserved.