org.apache.torque.oid
Class AutoIncrementIdGenerator

java.lang.Object
  extended by org.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 473821 2006-11-11 22:37:25Z tv $
Author:
John D. McNally

Constructor Summary
AutoIncrementIdGenerator(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)
          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.
 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

AutoIncrementIdGenerator

public AutoIncrementIdGenerator(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
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


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