Interface BibernateSession

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
BibernateFirstLevelCacheSession, BibernateSecondLevelCacheSession, CloseBibernateSession, DefaultBibernateSession, ValidatorBibernateSession

public interface BibernateSession extends Closeable
Interface representing a session with a Bibernate-based data store. Provides methods for common CRUD (Create, Read, Update, Delete) operations.
Since:
1.0
Author:
Blyzhnytsia Team
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the session, releasing any resources associated with it.
    void
    Commits the current transaction.
    <T> void
    delete(Class<T> entityClass, T entity)
    Deletes an entity from the data store.
    <T> void
    deleteAll(Class<T> entityClass, Collection<T> entities)
    Deletes all records associated with the provided entities from the specified table.
    <T> void
    deleteAllById(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> void
    deleteById(Class<T> entityClass, Object primaryKey)
    Deletes an entity from the data store by its primary key.
    int
    find(String query, Object[] bindValues)
    Finds the number of records returned by a custom query.
    <T> List<T>
    findAll(Class<T> entityClass)
    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>
    findById(Class<T> entityClass, Object primaryKey)
    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)
     
    default void
    Flushes changes to the underlying database.
    Gets the Data Access Object (DAO) associated with this session.
    void
    Rolls back the current transaction.
    <T> T
    save(Class<T> entityClass, T entity)
    Saves an entity to the data store.
    <T> void
    saveAll(Class<T> entityClass, Collection<T> entities)
    Saves a collection of entities into the specified table.
    void
    Starts a new transaction.
    <T> void
    update(Class<T> entityClass, Object entity)
    Updates an entity in the data store.
  • Method Details

    • findById

      <T> Optional<T> findById(Class<T> entityClass, Object primaryKey)
      Finds an entity by its primary key.
      Type Parameters:
      T - the type of the entity
      Parameters:
      entityClass - the class of the entity
      primaryKey - the primary key of the entity
      Returns:
      an Optional containing the found entity, or empty if not found
    • findAll

      <T> List<T> findAll(Class<T> entityClass)
      Retrieves all entities of a specified type from the data store.
      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

      <T> List<T> findAllById(Class<T> entityClass, Collection<Object> primaryKeys)
      Retrieves entities based on a collection of primary keys.
      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

      <T> List<T> findAllByColumnValue(Class<T> entityClass, String columnName, Object columnValue)
      Finds all entities of a given class with a specified column value.
      Type Parameters:
      T - the type of the entity
      Parameters:
      entityClass - the class of the entity
      columnName - the name of the column to match
      columnValue - the value to match
      Returns:
      a list of entities matching the criteria
    • findByWhere

      <T> List<T> findByWhere(Class<T> entityClass, String whereQuery, Object[] bindValues)
      Finds entities of a given class based on a custom WHERE clause.
      Type Parameters:
      T - the type of the entity
      Parameters:
      entityClass - the class of the entity
      whereQuery - the WHERE clause to apply
      bindValues - values to bind to the query parameters
      Returns:
      a list of entities matching the criteria
    • findByJoinTableField

      <T> List<T> findByJoinTableField(Class<T> entityClass, Field field, Object... bindValues)
      Finds entities of a given class based on a join table field.
      Type Parameters:
      T - the type of the entity
      Parameters:
      entityClass - the class of the entity
      field - the field to join on
      bindValues - values to bind to the query parameters
      Returns:
      a list of entities matching the criteria
    • findByWhereJoin

      <T> Optional<T> findByWhereJoin(Class<T> entityClass, Object[] bindValues)
    • findByQuery

      <T> List<T> findByQuery(Class<T> entityClass, String query, Object[] bindValues)
      Finds entities of a given class based on a custom query.
      Type Parameters:
      T - the type of the entity
      Parameters:
      entityClass - the class of the entity
      query - the custom query to execute
      bindValues - values to bind to the query parameters
      Returns:
      a list of entities matching the criteria
    • update

      <T> void update(Class<T> entityClass, Object entity)
      Updates an entity in the data store.
      Type Parameters:
      T - the type of the entity
      Parameters:
      entityClass - the class of the entity
      entity - the entity to update
    • find

      int find(String query, Object[] bindValues)
      Finds the number of records returned by a custom query.
      Parameters:
      query - the custom query to execute
      bindValues - values to bind to the query parameters
      Returns:
      the number of records returned by the query
    • save

      <T> T save(Class<T> entityClass, T entity)
      Saves an entity to the data store.
      Type Parameters:
      T - the type of the entity
      Parameters:
      entityClass - the class of the entity
      entity - the entity to save
      Returns:
      the saved entity
    • saveAll

      <T> void saveAll(Class<T> entityClass, Collection<T> entities)
      Saves a collection of entities into the specified table.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The Class object representing the type of entities to be saved.
      entities - A collection of entities to be persisted into the database.
    • flush

      default 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.
    • deleteById

      <T> void deleteById(Class<T> entityClass, Object primaryKey)
      Deletes an entity from the data store by its primary key.
      Type Parameters:
      T - the type of the entity
      Parameters:
      entityClass - the class of the entity
      primaryKey - the primary key of the entity to delete
    • deleteAllById

      <T> void deleteAllById(Class<T> entityClass, Collection<Object> primaryKeys)
      Deletes records from the specified table based on the provided collection of primary key values.
      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

      <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.
      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

      <T> void delete(Class<T> entityClass, T entity)
      Deletes an entity from the data store.
      Type Parameters:
      T - the type of the entity
      Parameters:
      entityClass - the class of the entity
      entity - the entity to delete
    • deleteAll

      <T> void deleteAll(Class<T> entityClass, Collection<T> entities)
      Deletes all records associated with the provided entities from the specified table.
      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.
    • close

      void close()
      Closes the session, releasing any resources associated with it.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getDao

      Dao getDao()
      Gets the Data Access Object (DAO) associated with this session.
      Returns:
      the DAO instance
    • startTransaction

      void startTransaction() throws SQLException
      Starts a new transaction. This method should be called before any operations that are meant to be part of a transaction.
      Throws:
      SQLException - if a database access error occurs or this method is called on a closed connection
    • commitTransaction

      void commitTransaction() throws SQLException
      Commits the current transaction. This method should be called to make all changes made within the transaction permanent.
      Throws:
      SQLException - if a database access error occurs, the connection is closed or this method is called when no transaction is active
    • rollbackTransaction

      void rollbackTransaction() throws SQLException
      Rolls back the current transaction. This method should be called if any errors occur within the transaction and the changes made need to be discarded.
      Throws:
      SQLException - if a database access error occurs, the connection is closed or this method is called when no transaction is active