Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.torque.oid
Class AbstractIdGenerator

    java.lang.Object
      org.apache.torque.oid.AbstractIdGenerator

All Implemented Interfaces:
  IdGenerator

Direct Known Subclasses:
  AutoIncrementIdGenerator, SequenceIdGenerator

    public abstract class AbstractIdGenerator

extends Object
implements IdGenerator

This class serves as a common base class for the sequence-based and the autoincrement-based id generators

Version:
  $Id: AbstractIdGenerator.java 1448414 2013-02-20 21:06:35Z tfischer $
Author:
  Thomas Vandahl

Field Summary
`protected Adapter` | `adapter` The adapter that knows the correct sql syntax
`protected String` | `databaseName` The internal name of the Database that this Generator is connected to.

Constructor Summary
`AbstractIdGenerator(Adapter adapter, String databaseName)` Creates an IdGenerator which will work with the specified database.

Method Summary
`protected
`<T> T`
` | `getId(Connection connection, Object keyInfo, RecordMapper<T> mapper)` Returns the last ID used by this connection.
`BigDecimal` | `getIdAsBigDecimal(Connection connection, Object keyInfo)` Returns the last ID used by this connection.
`int` | `getIdAsInt(Connection connection, Object keyInfo)` Returns the last ID used by this connection.
`long` | `getIdAsLong(Connection connection, Object keyInfo)` Returns the last ID used by this connection.
`String` | `getIdAsString(Connection connection, Object keyInfo)` Returns the last ID used by this connection.
`abstract boolean` | `isConnectionRequired()` A flag to determine whether a Connection is required to generate an id.
`abstract boolean` | `isPostInsert()` A flag to determine the timing of the id generation
`abstract 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

### adapter

    protected Adapter adapter

  The adapter that knows the correct sql syntax

### databaseName

    protected String databaseName

  The internal name of the Database that this Generator is connected to.

Constructor Detail

### AbstractIdGenerator

    public AbstractIdGenerator(Adapter adapter,
                               String databaseName)

  Creates an IdGenerator which will work with the specified database.

  Parameters:
    `adapter` - the adapter that knows the correct sql syntax.
    `databaseName` - The name of the databaseName to find the correct schema.

Method Detail

### getIdAsInt

    public int getIdAsInt(Connection connection,
                          Object keyInfo)
                   throws TorqueException

  Returns the last ID used by this connection.

  Specified by:
    `getIdAsInt` in interface `IdGenerator`
  Parameters:
    `connection` - The database connection to read the new id, not null.
    `keyInfo` - the name of the table for which the id is retrieved.
  Returns:
    An int with the new id.
  Throws:
    `TorqueException` - if a database error occurs.

### getIdAsLong

    public long getIdAsLong(Connection connection,
                            Object keyInfo)
                     throws TorqueException

  Returns the last ID used by this connection.

  Specified by:
    `getIdAsLong` in interface `IdGenerator`
  Parameters:
    `connection` - The database connection to read the new id, not null.
    `keyInfo` - the name of the table for which the id is retrieved.
  Returns:
    A long with the new id.
  Throws:
    `TorqueException` - if a database error occurs.

### getIdAsBigDecimal

    public BigDecimal getIdAsBigDecimal(Connection connection,
                                        Object keyInfo)
                                 throws TorqueException

  Returns the last ID used by this connection.

  Specified by:
    `getIdAsBigDecimal` in interface `IdGenerator`
  Parameters:
    `connection` - The database connection to read the new id, not null.
    `keyInfo` - the name of the table for which the id is retrieved.
  Returns:
    A BigDecimal with the new id.
  Throws:
    `TorqueException` - if a database error occurs.

### getIdAsString

    public String getIdAsString(Connection connection,
                                Object keyInfo)
                         throws TorqueException

  Returns the last ID used by this connection.

  Specified by:
    `getIdAsString` in interface `IdGenerator`
  Parameters:
    `connection` - The database connection to read the new id, not null.
    `keyInfo` - the name of the table for which the id is retrieved.
  Returns:
    A String with the new id.
  Throws:
    `TorqueException` - if a database error occurs.

### isPriorToInsert

    public abstract boolean isPriorToInsert()

  A flag to determine the timing of the id generation

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

### isPostInsert

    public abstract boolean isPostInsert()

  A flag to determine the timing of the id generation

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

### isConnectionRequired

    public abstract 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

### getId

    protected <T> T getId(Connection connection,
                          Object keyInfo,
                          RecordMapper<T> mapper)
               throws TorqueException

  Returns the last ID used by this connection.

  Parameters:
    `connection` - A Connection.
    `keyInfo` - an Object that contains additional info.
    `mapper` - The RecordMapper that maps from a ResultSet to the appropriate java object.
  Returns:
    The generated id.
  Throws:
    `TorqueException` - if a database error occurs.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2013 The Apache Software Foundation. All Rights Reserved.