org.apache.torque.oid
Interface IdGenerator

All Known Implementing Classes:
AutoIncrementIdGenerator, IDBroker, SequenceIdGenerator

public interface IdGenerator

Interface to be implemented by id generators. It is possible that some implementations might not require all the arguments, for example MySQL will not require a keyInfo Object, while the IDBroker implementation does not require a Connection as it only rarely needs one and retrieves a connection from the Connection pool service only when needed.

Version:
$Id: IdGenerator.java 239630 2005-08-24 12:25:32Z henning $
Author:
John D. McNally

Method Summary
 java.math.BigDecimal getIdAsBigDecimal(java.sql.Connection connection, java.lang.Object keyInfo)
          Returns an id as a BigDecimal.
 int getIdAsInt(java.sql.Connection connection, java.lang.Object keyInfo)
          Returns an id as a primitive int.
 long getIdAsLong(java.sql.Connection connection, java.lang.Object keyInfo)
          Returns an id as a primitive long.
 java.lang.String getIdAsString(java.sql.Connection connection, java.lang.Object keyInfo)
          Returns an id as a String.
 boolean isConnectionRequired()
          A flag to determine whether a Connection is required to generate an id.
 boolean isPostInsert()
          A flag to determine the timing of the id generation
 boolean isPriorToInsert()
          A flag to determine the timing of the id generation
 

Method Detail

getIdAsInt

public int getIdAsInt(java.sql.Connection connection,
                      java.lang.Object keyInfo)
               throws java.lang.Exception
Returns an id as a primitive int. If you use numeric identifiers, it's suggested that getIdAsLong(Connection, Object) be used instead (due to the limitted range of this method).

Parameters:
connection - A Connection.
keyInfo - an Object that contains additional info.
Returns:
An int with the value for the id.
Throws:
java.lang.Exception - Database error.

getIdAsLong

public long getIdAsLong(java.sql.Connection connection,
                        java.lang.Object keyInfo)
                 throws java.lang.Exception
Returns an id as a primitive long.

Parameters:
connection - A Connection.
keyInfo - an Object that contains additional info.
Returns:
A long with the value for the id.
Throws:
java.lang.Exception - Database error.

getIdAsBigDecimal

public java.math.BigDecimal getIdAsBigDecimal(java.sql.Connection connection,
                                              java.lang.Object keyInfo)
                                       throws java.lang.Exception
Returns an id as a BigDecimal.

Parameters:
connection - A Connection.
keyInfo - an Object that contains additional info.
Returns:
A BigDecimal id.
Throws:
java.lang.Exception - Database error.

getIdAsString

public java.lang.String getIdAsString(java.sql.Connection connection,
                                      java.lang.Object keyInfo)
                               throws java.lang.Exception
Returns an id as a String.

Parameters:
connection - A Connection.
keyInfo - an Object that contains additional info.
Returns:
A String id
Throws:
java.lang.Exception - Database error.

isPriorToInsert

public boolean isPriorToInsert()
A flag to determine the timing of the id generation

Returns:
a boolean value

isPostInsert

public boolean isPostInsert()
A flag to determine the timing of the id generation

Returns:
Whether id is availble post-insert.

isConnectionRequired

public boolean isConnectionRequired()
A flag to determine whether a Connection is required to generate an id.

Returns:
a boolean value


Copyright © 2000-2006 Apache Software Foundation. All Rights Reserved.