Interface Dao

All Known Implementing Classes:
EntityDao

public interface Dao
Interface representing a Data Access Object (DAO) for performing CRUD operations and querying on entities. Defines methods to interact with the underlying data store, such as fetching entities by ID, querying based on conditions, updating, saving, and deleting entities, and managing transactions.
Since:
1.0
Author:
Blyzhnytsia Team
  • Method Details

    • findById

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

      <T> List<T> findAll(Class<T> entityClass)
      Retrieves all entities of a given type.
      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.
    • findAllById

      <T> List<T> findAllById(Class<T> entityClass, Collection<Object> primaryKeys)
      Retrieves entities by their primary keys.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The class of the entity.
      primaryKeys - Collection of primary keys for entities to be retrieved.
      Returns:
      A list of entities matching the provided primary keys.
    • findAllByColumnValue

      <T> List<T> findAllByColumnValue(Class<T> entityClass, String columnName, Object columnValue)
      Retrieves entities based on the value of a specific column.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The class of the entity.
      columnName - The name of the column.
      columnValue - The value of the column.
      Returns:
      A list of entities matching the criteria.
    • findByWhere

      <T> List<T> findByWhere(Class<T> entityClass, String whereCondition, Object... bindValues)
      Retrieves entities based on a custom WHERE condition.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The class of the entity.
      whereCondition - The WHERE condition.
      bindValues - Values to bind to the WHERE condition.
      Returns:
      A list of entities matching the criteria.
    • findByJoinTableField

      <T> List<T> findByJoinTableField(Class<T> entityClass, Field field, Object... bindValues)
      Retrieves entities by joining a table using a specified field.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The class of the entity.
      field - The field used for the join.
      bindValues - Values to bind to the join condition.
      Returns:
      A list of entities matching the criteria.
    • findByWhereJoin

      <T> List<T> findByWhereJoin(Class<T> entityClass, Object... bindValues)
      Retrieves a single entity by joining tables based on custom conditions.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The class of the entity.
      bindValues - Values to bind to the join conditions.
      Returns:
      A list of entities matching the criteria.
    • findAllByWhereJoin

      <T> List<T> findAllByWhereJoin(Class<T> entityClass, String query, Object... bindValues)
      Retrieves a list of entities of the specified type based on a custom SQL query with WHERE and JOIN clauses.
      Type Parameters:
      T - the type of entities to retrieve
      Parameters:
      entityClass - the class object representing the entity type
      query - the custom SQL query with WHERE and JOIN clauses
      bindValues - the bind values to be used in the query
      Returns:
      a list of entities of the specified type that match the criteria defined in the custom SQL query
    • findByQuery

      <T> List<T> findByQuery(Class<T> entityClass, String query, Object... bindValues)
      Retrieves entities based on a custom query.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The class of the entity.
      query - The custom query.
      bindValues - Values to bind to the query.
      Returns:
      A list of entities matching the criteria.
    • find

      int find(String query, Object[] bindValues)
      Executes a custom query and returns the number of affected rows.
      Parameters:
      query - The custom query.
      bindValues - Values to bind to the query.
      Returns:
      The number of affected rows.
    • update

      <T> void update(Class<T> entityClass, Object entity, List<ColumnSnapshot> diff)
      Updates an entity with the provided changes.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The class of the entity.
      entity - The entity to be updated.
      diff - List of changes to apply.
    • save

      <T> T save(Class<T> entityClass, T entity)
      Saves a new entity.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The class of the entity.
      entity - The entity to be saved.
      Returns:
      The saved entity.
    • saveAll

      <T> void saveAll(Class<T> entityClass, Collection<T> entities)
      Saves a collection of entities.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The class of the entities.
      entities - The entities to be saved.
    • deleteById

      <T> void deleteById(Class<T> entityClass, Object primaryKey)
      Deletes an entity by its primary key.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The class of the entity.
      primaryKey - The primary key of the entity to be deleted.
    • deleteAllById

      <T> void deleteAllById(Class<T> entityClass, Collection<Object> primaryKeys)
      Deletes entities by their primary keys.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The class of the entities.
      primaryKeys - Collection of primary keys for entities to be deleted.
    • deleteByColumnValue

      <T> List<T> deleteByColumnValue(Class<T> entityClass, String columnName, Object value)
      Deletes entities based on the value of a specific column.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The class of the entities.
      columnName - The name of the column.
      value - The value of the column.
      Returns:
      A list of deleted entities.
    • delete

      <T> void delete(Class<T> entityClass, Object entity)
      Deletes an entity.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The class of the entity.
      entity - The entity to be deleted.
    • deleteAll

      <T> void deleteAll(Class<T> entityClass, Collection<T> entities)
      Deletes a collection of entities.
      Type Parameters:
      T - The generic type representing the entity class.
      Parameters:
      entityClass - The class of the entities.
      entities - The entities to be deleted.
    • startTransaction

      void startTransaction() throws SQLException
      Starts a transaction.
      Throws:
      SQLException - If an SQL exception occurs.
    • commitTransaction

      void commitTransaction() throws SQLException
      Commits the current transaction.
      Throws:
      SQLException - If an SQL exception occurs.
    • rollbackTransaction

      void rollbackTransaction() throws SQLException
      Rolls back the current transaction.
      Throws:
      SQLException - If an SQL exception occurs.