Class SQLServerPkGenerator
java.lang.Object
org.apache.cayenne.dba.JdbcPkGenerator
org.apache.cayenne.dba.oracle.OraclePkGenerator
org.apache.cayenne.dba.sqlserver.SQLServerPkGenerator
- All Implemented Interfaces:
PkGenerator
The default PK generator for MS SQL,
which uses sequences to generate a PK for an integer key type
and NEWID() for UNIQUEIDENTIFIER key type
- Since:
- 4.1
-
Field Summary
Fields inherited from class JdbcPkGenerator
adapter, DEFAULT_PK_CACHE_SIZE, pkCache, pkCacheSize, pkStartValueModifier and TypeFieldDescriptionprotected JdbcAdapterstatic final intprotected ConcurrentMap<String, Queue<Long>> protected intprotected long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateAutoPkStatements(List<DbEntity> dbEntities) Creates a list of CREATE SEQUENCE statements for the list of DbEntities.protected StringdropAutoPkStatements(List<DbEntity> dbEntities) Creates a list of DROP SEQUENCE statements for the list of DbEntities.generatePk(DataNode node, DbAttribute pk) Generates a unique and non-repeating primary key for specified dbEntity.protected Stringprotected StringguidPkFromDatabase(DataNode node, DbEntity entity) protected Stringprotected StringselectNextValQuery(String sequenceName) protected StringsequenceName(DbEntity entity) Returns expected primary key sequence name for a DbEntity.Methods inherited from class OraclePkGenerator
createAutoPk, dropAutoPk, dropSequenceString, getExistingSequences, longPkFromDatabase, pkCacheSizeModifier and TypeMethodDescriptionvoidcreateAutoPk(DataNode node, List<DbEntity> dbEntities) Generates necessary database objects to provide automatic primary key support.voiddropAutoPk(DataNode node, List<DbEntity> dbEntities) Drops PK sequences for all specified DbEntities.protected StringReturns a SQL string needed to drop any database objects associated with automatic primary key generation process for a specific DbEntity.getExistingSequences(DataNode node) Fetches a list of existing sequences that might match Cayenne generated ones.protected longlongPkFromDatabase(DataNode node, DbEntity entity) Generates primary key by calling Oracle sequence corresponding to thedbEntity.protected intpkCacheSize(DbEntity entity) Methods inherited from class JdbcPkGenerator
autoPkTableExists, dropAutoPkString, getAdapter, getPkCacheSize, pkCreateString, pkDeleteString, pkSelectString, pkTableCreateString, pkUpdateString, reset, runUpdate, setAdapter, setPkCacheSizeModifier and TypeMethodDescriptionprotected booleanautoPkTableExists(DataNode node) Checks if AUTO_PK_TABLE already exists in the database.protected StringGet an adapter associated with current PkGeneratorintReturns a size of the entity primary key cache.protected StringpkCreateString(String entName) protected StringpkDeleteString(List<DbEntity> dbEntities) protected StringpkSelectString(String entName) protected Stringprotected StringpkUpdateString(String entName) voidreset()Resets any cached primary keys forcing generator to go to the database next time id generation is requested.intRuns JDBC update over a Connection obtained from DataNode.voidsetAdapter(DbAdapter adapter) Install the adapter associated with current PkGeneratorvoidsetPkCacheSize(int pkCacheSize) Sets the size of the entity primary key cache.
-
Constructor Details
-
SQLServerPkGenerator
public SQLServerPkGenerator() -
SQLServerPkGenerator
-
-
Method Details
-
createSequenceString
- Overrides:
createSequenceStringin classOraclePkGenerator
-
getSequencePrefix
- Overrides:
getSequencePrefixin classOraclePkGenerator
-
selectNextValQuery
- Overrides:
selectNextValQueryin classOraclePkGenerator
-
createAutoPkStatements
Description copied from class:OraclePkGeneratorCreates a list of CREATE SEQUENCE statements for the list of DbEntities.- Specified by:
createAutoPkStatementsin interfacePkGenerator- Overrides:
createAutoPkStatementsin classOraclePkGenerator
-
dropAutoPkStatements
Description copied from class:OraclePkGeneratorCreates a list of DROP SEQUENCE statements for the list of DbEntities.- Specified by:
dropAutoPkStatementsin interfacePkGenerator- Overrides:
dropAutoPkStatementsin classOraclePkGenerator
-
generatePk
Description copied from class:JdbcPkGeneratorGenerates a unique and non-repeating primary key for specified dbEntity.This implementation is naive since it does not lock the database rows when executing select and subsequent update. Adapter-specific implementations are more robust.
- Specified by:
generatePkin interfacePkGenerator- Overrides:
generatePkin classJdbcPkGenerator- Throws:
Exception
-
selectAllSequencesQuery
- Overrides:
selectAllSequencesQueryin classOraclePkGenerator
-
sequenceName
Description copied from class:OraclePkGeneratorReturns expected primary key sequence name for a DbEntity.- Overrides:
sequenceNamein classOraclePkGenerator
-
guidPkFromDatabase
- Throws:
SQLException
-