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 |
registerExportables(org.hibernate.boot.model.relational.Database database) |
String[] |
sqlCreateStrings(org.hibernate.dialect.Dialect dialect)
Deprecated.
|
String[] |
sqlDropStrings(org.hibernate.dialect.Dialect dialect)
Deprecated.
|
boolean |
supportsBulkInsertionIdentifierGeneration() |
String |
toString() |
public 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.Configurable
org.hibernate.MappingException
public boolean supportsBulkInsertionIdentifierGeneration()
supportsBulkInsertionIdentifierGeneration
in interface org.hibernate.id.BulkInsertionCapableIdentifierGenerator
public String determineBulkInsertionIdentifierGenerationSelectFragment(org.hibernate.dialect.Dialect dialect)
determineBulkInsertionIdentifierGenerationSelectFragment
in interface org.hibernate.id.BulkInsertionCapableIdentifierGenerator
public Serializable generate(org.hibernate.engine.spi.SharedSessionContractImplementor session, Object object) throws org.hibernate.HibernateException
generate
in interface org.hibernate.id.IdentifierGenerator
org.hibernate.HibernateException
public Object generatorKey()
generatorKey
in interface org.hibernate.id.PersistentIdentifierGenerator
@Deprecated public String[] sqlCreateStrings(org.hibernate.dialect.Dialect dialect)
sqlCreateStrings
in interface org.hibernate.id.PersistentIdentifierGenerator
@Deprecated public String[] sqlDropStrings(org.hibernate.dialect.Dialect dialect)
sqlDropStrings
in interface org.hibernate.id.PersistentIdentifierGenerator
public void registerExportables(org.hibernate.boot.model.relational.Database database)
registerExportables
in interface org.hibernate.boot.model.relational.ExportableProducer
Copyright © 2022. All rights reserved.