org.apache.torque.oid
Class SequenceIdGenerator

java.lang.Object
  extended by org.apache.torque.oid.SequenceIdGenerator
All Implemented Interfaces:
IdGenerator

public class SequenceIdGenerator
extends java.lang.Object
implements IdGenerator

This generator works with databases that have an sql syntax for getting an id prior to inserting a row into the database.

Version:
$Id: SequenceIdGenerator.java 473821 2006-11-11 22:37:25Z tv $
Author:
John D. McNally

Constructor Summary
SequenceIdGenerator(DB dbAdapter, java.lang.String name)
          Creates an IdGenerator which will work with the specified database.
 
Method Summary
 java.math.BigDecimal getIdAsBigDecimal(java.sql.Connection connection, java.lang.Object keyInfo)
          Retrieves an id as a BigDecimal.
 int getIdAsInt(java.sql.Connection connection, java.lang.Object keyInfo)
          Retrieves an id as an int.
 long getIdAsLong(java.sql.Connection connection, java.lang.Object keyInfo)
          Retrieves an id as an long.
 java.lang.String getIdAsString(java.sql.Connection connection, java.lang.Object keyInfo)
          Retrieves an id as an 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SequenceIdGenerator

public SequenceIdGenerator(DB dbAdapter,
                           java.lang.String name)
Creates an IdGenerator which will work with the specified database.

Parameters:
dbAdapter - the adapter that knows the correct sql syntax.
name - The name of the datasource to find the correct schema
Method Detail

getIdAsInt

public int getIdAsInt(java.sql.Connection connection,
                      java.lang.Object keyInfo)
               throws java.lang.Exception
Retrieves an id as an int.

Specified by:
getIdAsInt in interface IdGenerator
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
Retrieves an id as an long.

Specified by:
getIdAsLong in interface IdGenerator
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
Retrieves an id as a BigDecimal.

Specified by:
getIdAsBigDecimal in interface IdGenerator
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
Retrieves an id as an String.

Specified by:
getIdAsString in interface IdGenerator
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

Specified by:
isPriorToInsert in interface IdGenerator
Returns:
a boolean value

isPostInsert

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

Specified by:
isPostInsert in interface IdGenerator
Returns:
a boolean value

isConnectionRequired

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

Specified by:
isConnectionRequired in interface IdGenerator
Returns:
a boolean value


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