public class BatchSequenceGenerator extends Object implements org.hibernate.id.BulkInsertionCapableIdentifierGenerator, org.hibernate.id.PersistentIdentifierGenerator, org.hibernate.id.Configurable
WITH RECURSIVE t(n) AS (
SELECT 1
UNION ALL
SELECT n + 1
FROM t
WHERE n < ?)
SELECT nextval(seq_xxx)
FROM t;
WITH t(n) AS (
SELECT 1 AS n
FROM (VALUES 1)
UNION ALL
SELECT n + 1 AS n
FROM t
WHERE n < ?)
SELECT next value for SEQ_CHILD_ID AS n
FROM t;
SELECT next value for seq_parent_id
FROM UNNEST(SEQUENCE_ARRAY(1, ?, 1));
SELECT seq_xxx.nextval
FROM dual
CONNECT BY rownum <= ?
WITH t(n) AS (
SELECT 1 AS n
UNION ALL
SELECT n + 1 AS n
FROM t
WHERE n < ?)
SELECT NEXT VALUE FOR seq_xxx AS n
FROM t
WITH RECURSIVE t(n, level_num) AS (
SELECT NEXT VALUE FOR seq_xxx AS n, 1 AS level_num
FROM rdb$database
UNION ALL
SELECT NEXT VALUE FOR seq_xxx AS n, level_num + 1 AS level_num
FROM t
WHERE level_num < ?)
SELECT n
FROM t
In theory any RDBMS that supports WITH RECURSIVE and
sequences is supported.
For more details about how to use it, check out this article on vladmihalcea.com.
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_FETCH_SIZE
The default value for
FETCH_SIZE_PARAM. |
static String |
FETCH_SIZE_PARAM
Indicates how many sequence values to fetch at once.
|
static String |
SEQUENCE_PARAM
Indicates the name of the sequence to use, mandatory.
|
| Constructor and Description |
|---|
BatchSequenceGenerator() |
| Modifier and Type | Method and Description |
|---|---|
void |
configure(org.hibernate.type.Type type,
Properties params,
org.hibernate.service.ServiceRegistry serviceRegistry) |
String |
determineBulkInsertionIdentifierGenerationSelectFragment(org.hibernate.dialect.Dialect dialect) |
Serializable |
generate(org.hibernate.engine.spi.SharedSessionContractImplementor session,
Object object) |
Object |
generatorKey() |
void |
initialize(org.hibernate.boot.model.relational.SqlStringGenerationContext context) |
void |
registerExportables(org.hibernate.boot.model.relational.Database database) |
String[] |
sqlCreateStrings(org.hibernate.dialect.Dialect dialect) |
String[] |
sqlDropStrings(org.hibernate.dialect.Dialect dialect) |
boolean |
supportsBulkInsertionIdentifierGeneration() |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitpublic static final String SEQUENCE_PARAM
public static final String FETCH_SIZE_PARAM
DEFAULT_FETCH_SIZE.public static final int DEFAULT_FETCH_SIZE
FETCH_SIZE_PARAM.public void configure(org.hibernate.type.Type type,
Properties params,
org.hibernate.service.ServiceRegistry serviceRegistry)
throws org.hibernate.MappingException
configure in interface org.hibernate.id.Configurableconfigure in interface org.hibernate.id.IdentifierGeneratororg.hibernate.MappingExceptionpublic void initialize(org.hibernate.boot.model.relational.SqlStringGenerationContext context)
initialize in interface org.hibernate.id.IdentifierGeneratorpublic boolean supportsBulkInsertionIdentifierGeneration()
supportsBulkInsertionIdentifierGeneration in interface org.hibernate.id.BulkInsertionCapableIdentifierGeneratorpublic String determineBulkInsertionIdentifierGenerationSelectFragment(org.hibernate.dialect.Dialect dialect)
determineBulkInsertionIdentifierGenerationSelectFragment in interface org.hibernate.id.BulkInsertionCapableIdentifierGeneratorpublic Serializable generate(org.hibernate.engine.spi.SharedSessionContractImplementor session, Object object) throws org.hibernate.HibernateException
generate in interface org.hibernate.id.IdentifierGeneratororg.hibernate.HibernateExceptionpublic Object generatorKey()
generatorKey in interface org.hibernate.id.PersistentIdentifierGeneratorpublic String[] sqlCreateStrings(org.hibernate.dialect.Dialect dialect)
public String[] sqlDropStrings(org.hibernate.dialect.Dialect dialect)
public void registerExportables(org.hibernate.boot.model.relational.Database database)
registerExportables in interface org.hibernate.boot.model.relational.ExportableProducerregisterExportables in interface org.hibernate.id.IdentifierGeneratorCopyright © 2023. All rights reserved.