Class SybasePkGenerator
java.lang.Object
org.apache.cayenne.dba.JdbcPkGenerator
org.apache.cayenne.dba.sybase.SybasePkGenerator
- All Implemented Interfaces:
PkGenerator
Primary key generator implementation for Sybase. Uses a lookup table named
"AUTO_PK_SUPPORT" and a stored procedure "auto_pk_for_table" to search and
increment primary keys for tables.
-
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 TypeMethodDescriptionvoidcreateAutoPk(DataNode node, List<DbEntity> dbEntities) Generates database objects to provide automatic primary key support.createAutoPkStatements(List<DbEntity> dbEntities) Returns a list of SQL strings needed to generates database objects to provide automatic primary support for the list of entities.voiddropAutoPk(DataNode node, List<DbEntity> dbEntities) Drops database objects related to automatic primary key support.dropAutoPkStatements(List<DbEntity> dbEntities) Returns SQL string needed to drop database objects associated with automatic primary key generation.protected longlongPkFromDatabase(DataNode node, DbEntity entity) Performs primary key generation ignoring cache.protected StringMethods inherited from class JdbcPkGenerator
autoPkTableExists, dropAutoPkString, generatePk, getAdapter, getPkCacheSize, pkCreateString, pkDeleteString, pkSelectString, pkUpdateString, reset, runUpdate, setAdapter, setPkCacheSizeModifier and TypeMethodDescriptionprotected booleanautoPkTableExists(DataNode node) Checks if AUTO_PK_TABLE already exists in the database.protected StringgeneratePk(DataNode node, DbAttribute pk) Generates a unique and non-repeating primary key for specified dbEntity.Get 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 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
-
SybasePkGenerator
public SybasePkGenerator()Used by DI- Since:
- 4.1
-
SybasePkGenerator
-
-
Method Details
-
pkTableCreateString
- Overrides:
pkTableCreateStringin classJdbcPkGenerator
-
createAutoPk
Generates database objects to provide automatic primary key support. Method will execute the following SQL statements:1. Executed only if a corresponding table does not exist in the database.
CREATE TABLE AUTO_PK_SUPPORT ( TABLE_NAME VARCHAR(32) NOT NULL, NEXT_ID DECIMAL(19,0) NOT NULL )2. Executed under any circumstances.
if exists (SELECT * FROM sysobjects WHERE name = 'auto_pk_for_table') BEGIN DROP PROCEDURE auto_pk_for_table END
3. Executed under any circumstances.
CREATE PROCEDURE auto_pk_for_table@tname VARCHAR(32), @pkbatchsize INT AS BEGIN BEGIN TRANSACTION UPDATE AUTO_PK_SUPPORT set NEXT_ID = NEXT_ID + @pkbatchsize WHERE TABLE_NAME = @tname SELECT NEXT_ID from AUTO_PK_SUPPORT where NEXT_ID = @tname COMMIT END- Specified by:
createAutoPkin interfacePkGenerator- Overrides:
createAutoPkin classJdbcPkGenerator- Parameters:
node- node that provides access to a DataSource.dbEntities- a list of entities that require primary key auto-generation support- Throws:
Exception
-
createAutoPkStatements
Description copied from interface:PkGeneratorReturns 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:
createAutoPkStatementsin interfacePkGenerator- Overrides:
createAutoPkStatementsin classJdbcPkGenerator
-
dropAutoPk
Drops database objects related to automatic primary key support. Method will execute the following SQL statements:if exists (SELECT * FROM sysobjects WHERE name = 'AUTO_PK_SUPPORT') BEGIN DROP TABLE AUTO_PK_SUPPORT END if exists (SELECT * FROM sysobjects WHERE name = 'auto_pk_for_table') BEGIN DROP PROCEDURE auto_pk_for_table END
- Specified by:
dropAutoPkin interfacePkGenerator- Overrides:
dropAutoPkin classJdbcPkGenerator- 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
-
dropAutoPkStatements
Description copied from interface:PkGeneratorReturns SQL string needed to drop database objects associated with automatic primary key generation. No actual database operations are performed.- Specified by:
dropAutoPkStatementsin interfacePkGenerator- Overrides:
dropAutoPkStatementsin classJdbcPkGenerator
-
longPkFromDatabase
Description copied from class:JdbcPkGeneratorPerforms primary key generation ignoring cache. Generates a range of primary keys as specified by "pkCacheSize" bean property.This method is called internally from "generatePkForDbEntity" and then generated range of key values is saved in cache for performance. Subclasses that implement different primary key generation solutions should override this method, not "generatePkForDbEntity".
- Overrides:
longPkFromDatabasein classJdbcPkGenerator- Throws:
Exception- Since:
- 3.0
-