Package 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:
- DB2PkGenerator,- DerbyPkGenerator,- H2PkGenerator,- IngresPkGenerator,- PostgresPkGenerator,- SQLServerPkGenerator
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);
- 
Field SummaryFields inherited from class org.apache.cayenne.dba.JdbcPkGeneratoradapter, DEFAULT_PK_CACHE_SIZE, pkCache, pkCacheSize, pkStartValue
- 
Constructor SummaryConstructors Modifier Constructor Description OraclePkGenerator()Used by DIprotectedOraclePkGenerator(JdbcAdapter adapter)
- 
Method SummaryModifier and Type Method Description voidcreateAutoPk(DataNode node, List<DbEntity> dbEntities)Generates necessary database objects to provide automatic primary key support.List<String>createAutoPkStatements(List<DbEntity> dbEntities)Creates a list of CREATE SEQUENCE statements for the list of DbEntities.protected StringcreateSequenceString(DbEntity ent)voiddropAutoPk(DataNode node, List<DbEntity> dbEntities)Drops PK sequences for all specified DbEntities.List<String>dropAutoPkStatements(List<DbEntity> dbEntities)Creates a list of DROP SEQUENCE statements for the list of DbEntities.protected StringdropSequenceString(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<String>getExistingSequences(DataNode node)Fetches a list of existing sequences that might match Cayenne generated ones.protected StringgetSequencePrefix()protected longlongPkFromDatabase(DataNode node, DbEntity entity)Generates primary key by calling Oracle sequence corresponding to thedbEntity.protected intpkCacheSize(DbEntity entity)protected StringselectAllSequencesQuery()protected StringselectNextValQuery(String pkGeneratingSequenceName)protected StringsequenceName(DbEntity entity)Returns expected primary key sequence name for a DbEntity.Methods inherited from class org.apache.cayenne.dba.JdbcPkGeneratorautoPkTableExists, dropAutoPkString, generatePk, getAdapter, getPkCacheSize, pkCreateString, pkDeleteString, pkSelectString, pkTableCreateString, pkUpdateString, reset, runUpdate, setAdapter, setPkCacheSize
- 
Constructor Details- 
OraclePkGeneratorpublic OraclePkGenerator()Used by DI- Since:
- 4.1
 
- 
OraclePkGenerator
 
- 
- 
Method Details- 
createAutoPkDescription copied from interface:PkGeneratorGenerates necessary database objects to provide automatic primary key support.- Specified by:
- createAutoPkin interface- PkGenerator
- Overrides:
- createAutoPkin class- JdbcPkGenerator
- Parameters:
- node- node that provides access to a DataSource.
- dbEntities- a list of entities that require primary key auto-generation support
- Throws:
- Exception
 
- 
createAutoPkStatementsCreates a list of CREATE SEQUENCE statements for the list of DbEntities.- Specified by:
- createAutoPkStatementsin interface- PkGenerator
- Overrides:
- createAutoPkStatementsin class- JdbcPkGenerator
 
- 
dropAutoPkDrops PK sequences for all specified DbEntities.- Specified by:
- dropAutoPkin interface- PkGenerator
- Overrides:
- dropAutoPkin class- JdbcPkGenerator
- Parameters:
- node- node that provides access to a DataSource.
- dbEntities- a list of entities whose primary key auto-generation support should be dropped.
- Throws:
- Exception
 
- 
dropAutoPkStatementsCreates a list of DROP SEQUENCE statements for the list of DbEntities.- Specified by:
- dropAutoPkStatementsin interface- PkGenerator
- Overrides:
- dropAutoPkStatementsin class- JdbcPkGenerator
 
- 
createSequenceString
- 
dropSequenceStringReturns a SQL string needed to drop any database objects associated with automatic primary key generation process for a specific DbEntity.
- 
selectNextValQuery
- 
selectAllSequencesQuery
- 
longPkFromDatabaseGenerates primary key by calling Oracle sequence corresponding to thedbEntity. Executed SQL looks like this:SELECT pk_table_name.nextval FROM DUAL - Overrides:
- longPkFromDatabasein class- JdbcPkGenerator
- Throws:
- Exception
- Since:
- 3.0
 
- 
pkCacheSize
- 
sequenceNameReturns expected primary key sequence name for a DbEntity.
- 
getSequencePrefix
- 
getExistingSequencesFetches a list of existing sequences that might match Cayenne generated ones.- Throws:
- SQLException
 
 
-