Class ValidatorBibernateSession
java.lang.Object
io.github.blyznytsiaorg.bibernate.session.ValidatorBibernateSession
- All Implemented Interfaces:
BibernateSession,Closeable,AutoCloseable
Wrapper class that provides validation functionality for a Bibernate session.
It delegates method calls to an underlying Bibernate session while performing validation checks.
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the session, releasing any resources associated with it.voidCommits the current transaction.<T> voidDeletes an entity from the data store.<T> voiddeleteAll(Class<T> entityClass, Collection<T> entities) Deletes all records associated with the provided entities from the specified table.<T> voiddeleteAllById(Class<T> entityClass, Collection<Object> primaryKeys) Deletes records from the specified table based on the provided collection of primary key values.<T> List<T> deleteByColumnValue(Class<T> entityClass, String columnName, Object columnValue) Deletes records from the specified table where the value in the specified column matches the given criteria.<T> voiddeleteById(Class<T> entityClass, Object primaryKey) Deletes an entity from the data store by its primary key.intFinds the number of records returned by a custom query.<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) Finds all entities of a given class with a specified column value.<T> List<T> findAllById(Class<T> entityClass, Collection<Object> primaryKeys) Retrieves entities based on a collection of primary keys.<T> Optional<T> Finds an entity by its primary key.<T> List<T> findByJoinTableField(Class<T> entityClass, Field field, Object... bindValues) Finds entities of a given class based on a join table field.<T> List<T> findByQuery(Class<T> entityClass, String query, Object[] bindValues) Finds entities of a given class based on a custom query.<T> List<T> findByWhere(Class<T> entityClass, String whereQuery, Object[] bindValues) Finds entities of a given class based on a custom WHERE clause.<T> Optional<T> findByWhereJoin(Class<T> entityClass, Object[] bindValues) voidflush()Flushes changes to the underlying database.getDao()Gets the Data Access Object (DAO) associated with this session.voidRolls back the current transaction.<T> TSaves the given entity to the database.<T> voidsaveAll(Class<T> entityClass, Collection<T> entities) Saves all entities in the provided collection to the database.voidStarts a new transaction.<T> voidUpdates the entity of the specified class in the database.
-
Field Details
-
bibernateSession
-
-
Constructor Details
-
ValidatorBibernateSession
public ValidatorBibernateSession()
-
-
Method Details
-
findById
Description copied from interface:BibernateSessionFinds an entity by its primary key.- 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 found entity, or empty if not found
-
findAll
Description copied from interface:BibernateSessionRetrieves 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
Description copied from interface:BibernateSessionRetrieves 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) Description copied from interface:BibernateSessionFinds all entities of a given class with a specified column value.- Specified by:
findAllByColumnValuein interfaceBibernateSession- Type Parameters:
T- the type of the entity- Parameters:
entityClass- the class of the entitycolumnName- the name of the column to matchcolumnValue- the value to match- Returns:
- a list of entities matching the criteria
-
findByWhere
Description copied from interface:BibernateSessionFinds entities of a given class based on a custom WHERE clause.- Specified by:
findByWherein interfaceBibernateSession- Type Parameters:
T- the type of the entity- Parameters:
entityClass- the class of the entitywhereQuery- the WHERE clause to applybindValues- values to bind to the query parameters- Returns:
- a list of entities matching the criteria
-
findByJoinTableField
Description copied from interface:BibernateSessionFinds entities of a given class based on a join table field.- Specified by:
findByJoinTableFieldin interfaceBibernateSession- Type Parameters:
T- the type of the entity- Parameters:
entityClass- the class of the entityfield- the field to join onbindValues- values to bind to the query parameters- Returns:
- a list of entities matching the criteria
-
findByWhereJoin
- Specified by:
findByWhereJoinin interfaceBibernateSession
-
findByQuery
Description copied from interface:BibernateSessionFinds entities of a given class based on a custom query.- Specified by:
findByQueryin interfaceBibernateSession- Type Parameters:
T- the type of the entity- Parameters:
entityClass- the class of the entityquery- the custom query to executebindValues- values to bind to the query parameters- Returns:
- a list of entities matching the criteria
-
update
Updates the entity of the specified class in the database. This method ensures that both the entity class and the entity instance are not null before proceeding with the update operation. Additionally, it verifies that the entity has a strategy generator for its ID or that the ID value is not null.- Specified by:
updatein interfaceBibernateSession- Type Parameters:
T- the type of the entity- Parameters:
entityClass- the class of the entity to be updatedentity- the entity instance to be updated- Throws:
NullPointerException- if eitherentityClassorentityisnullIllegalArgumentException- if the entity does not have a strategy generator for its ID and the ID value is null
-
find
Description copied from interface:BibernateSessionFinds the number of records returned by a custom query.- Specified by:
findin interfaceBibernateSession- Parameters:
query- the custom query to executebindValues- values to bind to the query parameters- Returns:
- the number of records returned by the query
-
save
Saves the given entity to the database.This method ensures that both the entity class and the entity instance are not null before proceeding with the save operation. Additionally, it verifies that the entity has a strategy generator for its ID or that the ID value is not null.
- Specified by:
savein interfaceBibernateSession- Type Parameters:
T- the type of the entity- Parameters:
entityClass- the class of the entity to be savedentity- the entity instance to be saved- Returns:
- the saved entity
- Throws:
NullPointerException- if eitherentityClassorentityisnullIllegalArgumentException- if the entity does not have a strategy generator for its ID and the ID value is null
-
saveAll
Saves all entities in the provided collection to the database.This method ensures that the entity class is not null before proceeding with the save operation. Additionally, it verifies that each entity in the collection has a strategy generator for its ID or that the ID value is not null.
- Specified by:
saveAllin interfaceBibernateSession- Type Parameters:
T- the type of the entities- Parameters:
entityClass- the class of the entities to be savedentities- the collection of entities to be saved- Throws:
NullPointerException- ifentityClassisnullIllegalArgumentException- if any entity in the collection does not have a strategy generator for its ID and the ID value is null
-
deleteById
Description copied from interface:BibernateSessionDeletes an entity from the data store 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
Description copied from interface:BibernateSessionDeletes records from the specified table based on the provided collection of primary key values.- Specified by:
deleteAllByIdin interfaceBibernateSession- Type Parameters:
T- The generic type representing the entity class.- Parameters:
entityClass- The Class object representing the type of entities for which records will be deleted.primaryKeys- A collection of primary key values identifying the records to be deleted.
-
deleteByColumnValue
Description copied from interface:BibernateSessionDeletes records from the specified table where the value in the specified column matches the given criteria.- Specified by:
deleteByColumnValuein interfaceBibernateSession- Type Parameters:
T- The generic type representing the entity class.- Parameters:
entityClass- The Class object representing the type of entities for which records will be deleted.columnName- The name of the column used in the WHERE condition for deletion.columnValue- The value to match in the specified column for deletion.- Returns:
- A list of entities of type T that were deleted from the table.
-
delete
Description copied from interface:BibernateSessionDeletes an entity from the data store.- Specified by:
deletein interfaceBibernateSession- Type Parameters:
T- the type of the entity- Parameters:
entityClass- the class of the entityentity- the entity to delete
-
deleteAll
Description copied from interface:BibernateSessionDeletes all records associated with the provided entities from the specified table.- Specified by:
deleteAllin interfaceBibernateSession- Type Parameters:
T- The generic type representing the entity class.- Parameters:
entityClass- The Class object representing the type of entities to be deleted.entities- A collection of entities whose corresponding records will be deleted.
-
flush
public void flush()Description copied from interface:BibernateSessionFlushes 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
-
close
public void close()Description copied from interface:BibernateSessionCloses the session, releasing any resources associated with it.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceBibernateSession- Specified by:
closein interfaceCloseable
-
getDao
Description copied from interface:BibernateSessionGets the Data Access Object (DAO) associated with this session.- Specified by:
getDaoin interfaceBibernateSession- Returns:
- the DAO instance
-
startTransaction
Description copied from interface:BibernateSessionStarts a new transaction. This method should be called before any operations that are meant to be part of a transaction.- Specified by:
startTransactionin interfaceBibernateSession- Throws:
SQLException- if a database access error occurs or this method is called on a closed connection
-
commitTransaction
Description copied from interface:BibernateSessionCommits the current transaction. This method should be called to make all changes made within the transaction permanent.- Specified by:
commitTransactionin interfaceBibernateSession- Throws:
SQLException- if a database access error occurs, the connection is closed or this method is called when no transaction is active
-
rollbackTransaction
Description copied from interface:BibernateSessionRolls back the current transaction. This method should be called if any errors occur within the transaction and the changes made need to be discarded.- Specified by:
rollbackTransactionin interfaceBibernateSession- Throws:
SQLException- if a database access error occurs, the connection is closed or this method is called when no transaction is active
-