Class BibernateSecondLevelCacheSession
java.lang.Object
io.github.blyznytsiaorg.bibernate.session.BibernateSecondLevelCacheSession
- All Implemented Interfaces:
BibernateSession
,Closeable
,AutoCloseable
Implementation of the
BibernateSession
interface that provides second-level caching functionality
for immutable entities fetched from the database.
It utilizes a distributed set for caching entities and extends the capabilities of the underlying
BibernateSession
.- Since:
- 1.0
- Author:
- Blyzhnytsia Team
-
Field Summary
Modifier and TypeFieldDescriptionprivate final BibernateSession
The underlying BibernateSession implementation.private final DistributedSet
The distributed set used for caching entities.private static final String
Separator used in constructing cache keys.private static final String
A constant String representing the separator used for string concatenation or splitting. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the session and releases any resources associated with it.void
Commits the current transaction for the session using underlying Bibernate session.<T> void
Deletes the given entity from the database.<T> void
deleteAll
(Class<T> entityClass, Collection<T> entities) Deletes all entities in the provided collection from the database.<T> void
deleteAllById
(Class<T> entityClass, Collection<Object> primaryKeys) Deletes entities by their primary keys.<T> List
<T> deleteByColumnValue
(Class<T> entityClass, String columnName, Object columnValue) Deletes entities based on the value of a specific column.<T> void
deleteById
(Class<T> entityClass, Object primaryKey) Deletes an entity by its primary key.int
Finds entities based on the provided query and bind values.<T> List
<T> Retrieves all entities of a specified type from the data store.<T> List
<T> findAllByColumnValue
(Class<T> entityClass, String columnName, Object columnValue) Retrieves entities by the value of a specific column.<T> List
<T> findAllById
(Class<T> entityClass, Collection<Object> primaryKeys) Retrieves entities based on a collection of primary keys.<T> Optional
<T> Retrieves an entity by its primary key, optionally caching it if it's immutable.<T> List
<T> findByJoinTableField
(Class<T> entityClass, Field field, Object... bindValues) Retrieves entities based on a join table field and bind values.<T> List
<T> findByQuery
(Class<T> entityClass, String query, Object[] bindValues) Retrieves entities based on the provided query and bind values.<T> List
<T> findByWhere
(Class<T> entityClass, String whereQuery, Object[] bindValues) Retrieves entities based on a custom WHERE clause and bind values.<T> Optional
<T> findByWhereJoin
(Class<T> entityClass, Object[] bindValues) Retrieves entities based on a custom query and bind values.void
flush()
Flushes changes to the underlying database.getDao()
Retrieves the DAO associated with this session.void
Rolls back the current transaction for the session using underlying Bibernate session.<T> T
Saves the provided entity of the specified class.<T> void
saveAll
(Class<T> entityClass, Collection<T> entity) Flushes changes to the underlying database.void
Starts a new transaction for the session using underlying Bibernate session.<T> void
Updates the given entity in the database.
-
Field Details
-
DOT
Separator used in constructing cache keys.- See Also:
-
SEPARATOR
A constant String representing the separator used for string concatenation or splitting.- See Also:
-
bibernateSession
The underlying BibernateSession implementation. -
distributedSet
The distributed set used for caching entities.
-
-
Constructor Details
-
BibernateSecondLevelCacheSession
public BibernateSecondLevelCacheSession()
-
-
Method Details
-
findById
Retrieves an entity by its primary key, optionally caching it if it's immutable.- Specified by:
findById
in interfaceBibernateSession
- Type Parameters:
T
- the type of the entity- Parameters:
entityClass
- The class of the entityprimaryKey
- The primary key of the entity- Returns:
- An Optional containing the entity, if found
-
findAll
Retrieves all entities of a specified type from the data store.- Specified by:
findAll
in interfaceBibernateSession
- Type Parameters:
T
- The generic type representing the entity class.- Parameters:
entityClass
- The class of the entity.- Returns:
- A list of all entities of the specified type in the data store.
-
findAllById
Retrieves entities based on a collection of primary keys.- Specified by:
findAllById
in interfaceBibernateSession
- Type Parameters:
T
- The generic type representing the entity class.- Parameters:
entityClass
- The class of the entity.primaryKeys
- A collection of primary keys for identifying and retrieving specific records.- Returns:
- A list of entities matching the provided collection of primary keys.
-
findAllByColumnValue
public <T> List<T> findAllByColumnValue(Class<T> entityClass, String columnName, Object columnValue) Retrieves entities by the value of a specific column.- Specified by:
findAllByColumnValue
in interfaceBibernateSession
- Type Parameters:
T
- the type of the entity- Parameters:
entityClass
- The class of the entitycolumnName
- The name of the columncolumnValue
- The value of the column- Returns:
- A list of entities matching the criteria
-
findByWhere
Retrieves entities based on a custom WHERE clause and bind values.- Specified by:
findByWhere
in interfaceBibernateSession
- Type Parameters:
T
- the type of the entity- Parameters:
entityClass
- The class of the entitywhereQuery
- The WHERE clausebindValues
- The bind values for parameters in the WHERE clause- Returns:
- A list of entities matching the criteria
-
findByJoinTableField
Retrieves entities based on a join table field and bind values.- Specified by:
findByJoinTableField
in interfaceBibernateSession
- Type Parameters:
T
- the type of the entity- Parameters:
entityClass
- The class of the entityfield
- The field in the join tablebindValues
- The bind values for parameters in the query- Returns:
- A list of entities matching the criteria
-
findByWhereJoin
Retrieves entities based on a custom query and bind values.- Specified by:
findByWhereJoin
in interfaceBibernateSession
- Parameters:
entityClass
- The class of the entitybindValues
- The bind values for parameters in the query- Returns:
- A list of entities matching the criteria
-
findByQuery
Retrieves entities based on the provided query and bind values.- Specified by:
findByQuery
in interfaceBibernateSession
- Type Parameters:
T
- The type of the entity- Parameters:
entityClass
- The class of the entityquery
- The query to executebindValues
- The bind values for parameters in the query- Returns:
- A list of entities matching the provided query and bind values
-
update
Updates the given entity in the database.- Specified by:
update
in interfaceBibernateSession
- Type Parameters:
T
- The type of the entity- Parameters:
entityClass
- The class of the entityentity
- The entity to update
-
find
Finds entities based on the provided query and bind values.- Specified by:
find
in interfaceBibernateSession
- Parameters:
query
- The query to executebindValues
- The bind values for parameters in the query- Returns:
- The number of entities found
-
save
Saves the provided entity of the specified class.- Specified by:
save
in interfaceBibernateSession
- Type Parameters:
T
- The type of the entity- Parameters:
entityClass
- The class of the entity to saveentity
- The entity to save- Returns:
- The saved entity
-
saveAll
Flushes changes to the underlying database. This method synchronizes the state of the Bibernate session with the database. Any changes that have been queued for insertion, update, or deletion are executed immediately.- Specified by:
saveAll
in interfaceBibernateSession
- Type Parameters:
T
- The type of the entity- Parameters:
entityClass
- The class of the entityentity
- The entity to save
-
flush
public void flush()Flushes changes to the underlying database. This method synchronizes the state of the Bibernate session with the database. Any changes that have been queued for insertion, update, or deletion are executed immediately.- Specified by:
flush
in interfaceBibernateSession
-
deleteById
Deletes an entity by its primary key.- Specified by:
deleteById
in interfaceBibernateSession
- Type Parameters:
T
- The type of the entity- Parameters:
entityClass
- The class of the entityprimaryKey
- The primary key of the entity to delete
-
deleteAllById
Deletes entities by their primary keys.- Specified by:
deleteAllById
in interfaceBibernateSession
- Type Parameters:
T
- The type of the entity- Parameters:
entityClass
- The class of the entityprimaryKeys
- The collection of primary keys for entities to delete
-
deleteByColumnValue
Deletes entities based on the value of a specific column.- Specified by:
deleteByColumnValue
in interfaceBibernateSession
- Type Parameters:
T
- The type of the entity- Parameters:
entityClass
- The class of the entitycolumnName
- The name of the columncolumnValue
- The value of the column- Returns:
- A list of entities matching the criteria
-
delete
Deletes the given entity from the database.- Specified by:
delete
in interfaceBibernateSession
- Type Parameters:
T
- The type of the entity- Parameters:
entityClass
- The class of the entityentity
- The entity to delete
-
deleteAll
Deletes all entities in the provided collection from the database.- Specified by:
deleteAll
in interfaceBibernateSession
- Type Parameters:
T
- The type of the entities- Parameters:
entityClass
- The class of the entitiesentities
- The collection of entities to delete
-
close
public void close()Closes the session and releases any resources associated with it.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceBibernateSession
- Specified by:
close
in interfaceCloseable
-
getDao
Retrieves the DAO associated with this session.- Specified by:
getDao
in interfaceBibernateSession
- Returns:
- The DAO associated with this session
-
startTransaction
Starts a new transaction for the session using underlying Bibernate session.- Specified by:
startTransaction
in interfaceBibernateSession
- Throws:
SQLException
- If an SQL exception occurs while starting the transaction
-
commitTransaction
Commits the current transaction for the session using underlying Bibernate session.- Specified by:
commitTransaction
in interfaceBibernateSession
- Throws:
SQLException
- If an SQL exception occurs while committing the transaction
-
rollbackTransaction
Rolls back the current transaction for the session using underlying Bibernate session.- Specified by:
rollbackTransaction
in interfaceBibernateSession
- Throws:
SQLException
- If an SQL exception occurs while rolling back the transaction
-