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
FieldsModifier and TypeFieldDescriptionprivate final BibernateSessionThe underlying BibernateSession implementation.private final DistributedSetThe distributed set used for caching entities.private static final StringSeparator used in constructing cache keys.private static final StringA constant String representing the separator used for string concatenation or splitting. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the session and releases any resources associated with it.voidCommits the current transaction for the session using underlying Bibernate session.<T> voidDeletes the given entity from the database.<T> voiddeleteAll(Class<T> entityClass, Collection<T> entities) Deletes all entities in the provided collection from the database.<T> voiddeleteAllById(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> voiddeleteById(Class<T> entityClass, Object primaryKey) Deletes an entity by its primary key.intFinds 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.voidflush()Flushes changes to the underlying database.getDao()Retrieves the DAO associated with this session.voidRolls back the current transaction for the session using underlying Bibernate session.<T> TSaves the provided entity of the specified class.<T> voidsaveAll(Class<T> entityClass, Collection<T> entity) Flushes changes to the underlying database.voidStarts a new transaction for the session using underlying Bibernate session.<T> voidUpdates 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:
findByIdin 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:
findAllin 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:
findAllByIdin 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:
findAllByColumnValuein 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:
findByWherein 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:
findByJoinTableFieldin 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:
findByWhereJoinin 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:
findByQueryin 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:
updatein 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:
findin 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:
savein 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:
saveAllin 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:
flushin interfaceBibernateSession
-
deleteById
Deletes an entity by its primary key.- Specified by:
deleteByIdin 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:
deleteAllByIdin 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:
deleteByColumnValuein 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:
deletein 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:
deleteAllin 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceBibernateSession- Specified by:
closein interfaceCloseable
-
getDao
Retrieves the DAO associated with this session.- Specified by:
getDaoin interfaceBibernateSession- Returns:
- The DAO associated with this session
-
startTransaction
Starts a new transaction for the session using underlying Bibernate session.- Specified by:
startTransactionin 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:
commitTransactionin 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:
rollbackTransactionin interfaceBibernateSession- Throws:
SQLException- If an SQL exception occurs while rolling back the transaction
-