Class JdbcPkGenerator
- All Implemented Interfaces:
- PkGenerator
- Direct Known Subclasses:
- FrontBasePkGenerator,- MySQLPkGenerator,- OpenBasePkGenerator,- OraclePkGenerator,- SybasePkGenerator
public class JdbcPkGenerator extends Object implements PkGenerator
- 
Field SummaryFields Modifier and Type Field Description protected JdbcAdapteradapterstatic intDEFAULT_PK_CACHE_SIZEprotected ConcurrentMap<String,Queue<Long>>pkCacheprotected intpkCacheSizeprotected longpkStartValue
- 
Constructor SummaryConstructors Constructor Description JdbcPkGenerator()JdbcPkGenerator(JdbcAdapter adapter)
- 
Method SummaryModifier and Type Method Description protected booleanautoPkTableExists(DataNode node)Checks if AUTO_PK_TABLE already exists in the database.voidcreateAutoPk(DataNode node, List<DbEntity> dbEntities)Generates necessary database objects to provide automatic primary key support.List<String>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 table named "AUTO_PK_SUPPORT" if it exists in the database.List<String>dropAutoPkStatements(List<DbEntity> dbEntities)Returns SQL string needed to drop database objects associated with automatic primary key generation.protected StringdropAutoPkString()ObjectgeneratePk(DataNode node, DbAttribute pk)Generates a unique and non-repeating primary key for specified dbEntity.JdbcAdaptergetAdapter()Get an adapter associated with current PkGeneratorintgetPkCacheSize()Returns a size of the entity primary key cache.protected longlongPkFromDatabase(DataNode node, DbEntity entity)Performs primary key generation ignoring cache.protected StringpkCreateString(String entName)protected StringpkDeleteString(List<DbEntity> dbEntities)protected StringpkSelectString(String entName)protected StringpkTableCreateString()protected StringpkUpdateString(String entName)voidreset()Resets any cached primary keys forcing generator to go to the database next time id generation is requested.intrunUpdate(DataNode node, String sql)Runs 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.
- 
Field Details- 
DEFAULT_PK_CACHE_SIZEpublic static final int DEFAULT_PK_CACHE_SIZE- See Also:
- Constant Field Values
 
- 
adapter
- 
pkCache
- 
pkCacheSizeprotected int pkCacheSize
- 
pkStartValueprotected long pkStartValue
 
- 
- 
Constructor Details- 
JdbcPkGeneratorpublic JdbcPkGenerator()- Since:
- 4.1
 
- 
JdbcPkGenerator
 
- 
- 
Method Details- 
getAdapterDescription copied from interface:PkGeneratorGet an adapter associated with current PkGenerator- Specified by:
- getAdapterin interface- PkGenerator
 
- 
createAutoPkDescription copied from interface:PkGeneratorGenerates necessary database objects to provide automatic primary key support.- Specified by:
- createAutoPkin interface- PkGenerator
- Parameters:
- node- node that provides access to a DataSource.
- dbEntities- a list of entities that require primary key auto-generation support
- Throws:
- Exception
 
- 
createAutoPkStatementsDescription 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 interface- PkGenerator
 
- 
dropAutoPkDrops table named "AUTO_PK_SUPPORT" if it exists in the database.- Specified by:
- dropAutoPkin interface- PkGenerator
- 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
 
- 
dropAutoPkStatementsDescription 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 interface- PkGenerator
 
- 
pkTableCreateString
- 
pkDeleteString
- 
pkCreateString
- 
pkSelectString
- 
pkUpdateString
- 
dropAutoPkString
- 
autoPkTableExistsChecks if AUTO_PK_TABLE already exists in the database.- Throws:
- SQLException
 
- 
runUpdateRuns JDBC update over a Connection obtained from DataNode. Returns a number of objects returned from update.- Throws:
- SQLException- in case of query failure.
 
- 
generatePkGenerates 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 interface- PkGenerator
- Throws:
- Exception
- Since:
- 3.0
 
- 
setAdapterDescription copied from interface:PkGeneratorInstall the adapter associated with current PkGenerator- Specified by:
- setAdapterin interface- PkGenerator
 
- 
longPkFromDatabasePerforms 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". - Throws:
- Exception
- Since:
- 3.0
 
- 
getPkCacheSizepublic int getPkCacheSize()Returns a size of the entity primary key cache. Default value is 20. If cache size is set to a value less or equals than "one", no primary key caching is done.
- 
setPkCacheSizepublic void setPkCacheSize(int pkCacheSize)Sets the size of the entity primary key cache. IfpkCacheSizeparameter is less than 1, cache size is set to "one".Note that our tests show that setting primary key cache value to anything much bigger than 20 does not give any significant performance increase. Therefore it does not make sense to use bigger values, since this may potentially create big gaps in the database primary key sequences in cases like application crashes or restarts. 
- 
resetpublic void reset()Description copied from interface:PkGeneratorResets any cached primary keys forcing generator to go to the database next time id generation is requested. May not be applicable for all generator implementations.- Specified by:
- resetin interface- PkGenerator
 
 
-