org.apache.torque.oid
Class AutoIncrementIdGenerator

java.lang.Object
  extended byorg.apache.torque.oid.AutoIncrementIdGenerator
All Implemented Interfaces:
IdGenerator

public class AutoIncrementIdGenerator
extends java.lang.Object
implements IdGenerator

This generator works with databases that have an sql syntax that allows the retrieval of the last id used to insert a row for a Connection.

Version:
$Id: AutoIncrementIdGenerator.java,v 1.5 2002/11/26 23:46:56 mpoeschl Exp $
Author:
John D. McNally

Field Summary
private  DB dbAdapter
          the adapter that knows the correct sql syntax
 
Constructor Summary
AutoIncrementIdGenerator(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)
          Returns the last ID used by this connection.
 int getIdAsInt(java.sql.Connection connection, java.lang.Object keyInfo)
          Returns the last ID used by this connection.
 long getIdAsLong(java.sql.Connection connection, java.lang.Object keyInfo)
          Returns the last ID used by this connection.
 java.lang.String getIdAsString(java.sql.Connection connection, java.lang.Object keyInfo)
          Returns the last ID used by this connection.
private  com.workingdogs.village.Value getIdAsVillageValue(java.sql.Connection connection, java.lang.Object keyInfo)
          Returns the last ID used by this connection.
 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

dbAdapter

private DB dbAdapter
the adapter that knows the correct sql syntax

Constructor Detail

AutoIncrementIdGenerator

public AutoIncrementIdGenerator(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
Returns the last ID used by this connection.

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
Returns the last ID used by this connection.

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
Returns the last ID used by this connection.

Specified by:
getIdAsBigDecimal in interface IdGenerator
Parameters:
connection - A Connection.
keyInfo - an Object that contains additional info.
Returns:
A BigDecimal with the last value auto-incremented as a result of an insert.
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 the last ID used by this connection.

Specified by:
getIdAsString in interface IdGenerator
Parameters:
connection - A Connection.
keyInfo - an Object that contains additional info.
Returns:
A String with the last value auto-incremented as a result of an insert.
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 final 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
Returns the last ID used by this connection.

Parameters:
connection - A Connection.
keyInfo - an Object that contains additional info.
Returns:
A Village Value with the last value auto-incremented as a result of an insert.
Throws:
java.lang.Exception - Database error.


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