Class SequenceIdGenerator
java.lang.Object
io.github.blyznytsiaorg.bibernate.dao.jdbc.identity.AbstractGenerator
io.github.blyznytsiaorg.bibernate.dao.jdbc.identity.SequenceIdGenerator
- All Implemented Interfaces:
Generator
Implementation of the sequence-based ID generator in Bibernate.
This generator is responsible for handling entities with sequence-based generation of primary key values. This SequenceIdGenerator generator anticipates that the identifier will be generated in additional query to database before an INSERT operation into the table.
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final String
private final Map
<Class<?>, SequenceConf> -
Constructor Summary
ConstructorDescriptionSequenceIdGenerator
(BibernateDatabaseSettings bibernateDatabaseSettings, List<String> executedQueries) Constructs an SequenceIdGenerator with the specified Bibernate database settings and a list to store executed queries. -
Method Summary
Modifier and TypeMethodDescriptionprivate Object
generateId
(Class<?> entityClass, String tableName, DataSource dataSource) private Long
getNextIdFromDbSeq
(DataSource dataSource, String sequenceName) private SequenceConf
getSequenceConf
(Class<?> entityClass, String tableName) <T> void
handle
(Class<T> entityClass, Collection<T> entities, DataSource dataSource) Handles the generation of sequence-based primary keys for a collection of entities and inserts the entities into the database using batch processing.type()
Returns SEQUENCE GenerationType for further understanding of what type of generator we are dealing withMethods inherited from class io.github.blyznytsiaorg.bibernate.dao.jdbc.identity.AbstractGenerator
addToExecutedQueries, addUpdatedEntity, getBatchSize, getGeneratedValue, insertManyToManyJoinTable, populatePreparedStatement, populatePreparedStatement, populatePreparedStatement, showSql
-
Field Details
-
SELECT_NEXT_QUERY
- See Also:
-
sequences
-
-
Constructor Details
-
SequenceIdGenerator
public SequenceIdGenerator(BibernateDatabaseSettings bibernateDatabaseSettings, List<String> executedQueries) Constructs an SequenceIdGenerator with the specified Bibernate database settings and a list to store executed queries.- Parameters:
bibernateDatabaseSettings
- The database settings for Bibernate.executedQueries
- The list to store executed queries.
-
-
Method Details
-
type
Returns SEQUENCE GenerationType for further understanding of what type of generator we are dealing with -
handle
Handles the generation of sequence-based primary keys for a collection of entities and inserts the entities into the database using batch processing. Gets generated id from the sequence of database and sets it to the entity. If the method will be performed in transaction then id will be cleaned up from the entity in case of rollback. Can overbook set of sequences (depends on allocation size property) and use it to avoid redundant sql queries to database- Specified by:
handle
in interfaceGenerator
- Type Parameters:
T
- The type of entities in the collection.- Parameters:
entityClass
- The class of the entities being handled.entities
- The collection of entities for which primary keys are generated.dataSource
- The data source for obtaining a database connection.
-
generateId
-
getNextIdFromDbSeq
-
getSequenceConf
-