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.cayenne.dba.oracle
Class OraclePkGenerator

    java.lang.Object
      org.apache.cayenne.dba.JdbcPkGenerator
          org.apache.cayenne.dba.oracle.OraclePkGenerator

All Implemented Interfaces:
  PkGenerator

Direct Known Subclasses:
  IngresPkGenerator, PostgresPkGenerator

    public class OraclePkGenerator

extends JdbcPkGenerator

Sequence-based primary key generator implementation for Oracle. Uses Oracle sequences to generate primary key values. This approach is at least 50% faster when tested with Oracle compared to the lookup table approach.

When using Cayenne key caching mechanism, make sure that sequences in the database have "INCREMENT BY" greater or equal to OraclePkGenerator "pkCacheSize" property value. If this is not the case, you will need to adjust PkGenerator value accordingly. For example when sequence is incremented by 1 each time, use the following code:

     dataNode.getAdapter().getPkGenerator().setPkCacheSize(1);

Author:
  Andrus Adamchik

Field Summary

Fields inherited from class org.apache.cayenne.dba.JdbcPkGenerator
`DEFAULT_PK_CACHE_SIZE, pkCache, pkCacheSize`

Constructor Summary
`OraclePkGenerator()`

Method Summary
`void` | `createAutoPk(DataNode node, List dbEntities)` Generates necessary database objects to provide automatic primary key support.
`List` | `createAutoPkStatements(List dbEntities)` Returns a list of SQL strings needed to generates database objects to provide automatic primary support for the list of entities.
`protected String` | `createSequenceString(DbEntity ent)`
`void` | `dropAutoPk(DataNode node, List dbEntities)` Drops table named "AUTO_PK_SUPPORT" if it exists in the database.
`List` | `dropAutoPkStatements(List dbEntities)` Returns SQL string needed to drop database objects associated with automatic primary key generation.
`protected String` | `dropSequenceString(DbEntity ent)` Returns a SQL string needed to drop any database objects associated with automatic primary key generation process for a specific DbEntity.
`protected List` | `getExistingSequences(DataNode node)` Fetches a list of existing sequences that might match Cayenne generated ones.
`protected int` | `pkCacheSize(DbEntity entity)`
`protected int` | `pkFromDatabase(DataNode node, DbEntity ent)` Generates primary key by calling Oracle sequence corresponding to the `dbEntity`.
`protected String` | `sequenceName(DbEntity entity)` Returns expected primary key sequence name for a DbEntity.
`protected String` | `stripSchemaName(String sequenceName)`

Methods inherited from class org.apache.cayenne.dba.JdbcPkGenerator
`autoPkTableExists, binaryPK, dropAutoPkString, generatePkForDbEntity, getPkCacheSize, pkCreateString, pkDeleteString, pkSelectString, pkTableCreateString, pkUpdateString, reset, runUpdate, setPkCacheSize`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### OraclePkGenerator

    public OraclePkGenerator()

Method Detail

### createAutoPk

    public void createAutoPk(DataNode node,
                             List dbEntities)
                      throws Exception

  Description copied from interface: `PkGenerator`
  Generates necessary database objects to provide automatic primary key support.

  Specified by:
    `createAutoPk` in interface `PkGenerator`
  Overrides:
    `createAutoPk` in class `JdbcPkGenerator`
  Parameters:
    `node` - node that provides access to a DataSource.
    `dbEntities` - a list of entities that require primary key autogeneration support
  Throws:
    `Exception`

### createAutoPkStatements

    public List createAutoPkStatements(List dbEntities)

  Description copied from interface: `PkGenerator`
  Returns a list of SQL strings needed to generates database objects to provide automatic primary support for the list of entities. No actual database operations are performed.

  Specified by:
    `createAutoPkStatements` in interface `PkGenerator`
  Overrides:
    `createAutoPkStatements` in class `JdbcPkGenerator`

### dropAutoPk

    public void dropAutoPk(DataNode node,
                           List dbEntities)
                    throws Exception

  Description copied from class: `JdbcPkGenerator`
  Drops table named "AUTO_PK_SUPPORT" if it exists in the database.

  Specified by:
    `dropAutoPk` in interface `PkGenerator`
  Overrides:
    `dropAutoPk` in class `JdbcPkGenerator`
  Parameters:
    `node` - node that provides access to a DataSource.
    `dbEntities` - a list of entities whose primary key autogeneration support should be dropped.
  Throws:
    `Exception`

### dropAutoPkStatements

    public List dropAutoPkStatements(List dbEntities)

  Description copied from interface: `PkGenerator`
  Returns SQL string needed to drop database objects associated with automatic primary key generation. No actual database operations are performed.

  Specified by:
    `dropAutoPkStatements` in interface `PkGenerator`
  Overrides:
    `dropAutoPkStatements` in class `JdbcPkGenerator`

### createSequenceString

    protected String createSequenceString(DbEntity ent)

### dropSequenceString

    protected String dropSequenceString(DbEntity ent)

  Returns a SQL string needed to drop any database objects associated with automatic primary key generation process for a specific DbEntity.

### pkFromDatabase

    protected int pkFromDatabase(DataNode node,
                                 DbEntity ent)
                          throws Exception

  Generates primary key by calling Oracle sequence corresponding to the `dbEntity`. Executed SQL looks like this:

         SELECT pk_table_name.nextval FROM DUAL

  Overrides:
    `pkFromDatabase` in class `JdbcPkGenerator`
  Throws:
    `Exception`

### pkCacheSize

    protected int pkCacheSize(DbEntity entity)

### sequenceName

    protected String sequenceName(DbEntity entity)

  Returns expected primary key sequence name for a DbEntity.

### stripSchemaName

    protected String stripSchemaName(String sequenceName)

### getExistingSequences

    protected List getExistingSequences(DataNode node)
                                 throws SQLException

  Fetches a list of existing sequences that might match Cayenne generated ones.

  Throws:
    `SQLException`

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 © 2001-2007 Apache Cayenne. All Rights Reserved.