org.apache.torque.oid
Class SequenceIdGenerator

java.lang.Object
  extended byorg.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,v 1.10 2003/08/25 16:33:22 henning Exp $
Author:
John D. McNally

Field Summary
private  DB dbAdapter
          the adapter that knows the correct sql syntax
private static org.apache.commons.logging.Log log
          The log.
 
Constructor Summary
SequenceIdGenerator(DB adapter)
          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.
private  com.workingdogs.village.Value getIdAsVillageValue(java.sql.Connection connection, java.lang.Object keyInfo)
          Retrieves an id as a Village Value.
 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
 

Field Detail

log

private static org.apache.commons.logging.Log log
The log.


dbAdapter

private DB dbAdapter
the adapter that knows the correct sql syntax

Constructor Detail

SequenceIdGenerator

public SequenceIdGenerator(DB adapter)
Creates an IdGenerator which will work with the specified database.

Parameters:
adapter - the adapter that knows the correct sql syntax.
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

getIdAsVillageValue

private com.workingdogs.village.Value getIdAsVillageValue(java.sql.Connection connection,
                                                          java.lang.Object keyInfo)
                                                   throws java.lang.Exception
Retrieves an id as a Village Value.

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


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