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 Summary
Modifier and TypeMethodDescriptionvoid
Commits the current transaction.<T> void
Deletes an entity.<T> void
deleteAll
(Class<T> entityClass, Collection<T> entities) Deletes a collection of entities.<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 value) 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
Executes a custom query and returns the number of affected rows.<T> List
<T> Retrieves all entities of a given type.<T> List
<T> findAllByColumnValue
(Class<T> entityClass, String columnName, Object columnValue) Retrieves entities based on the value of a specific column.<T> List
<T> findAllById
(Class<T> entityClass, Collection<Object> primaryKeys) Retrieves entities by their primary keys.<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.<T> Optional
<T> Finds an entity by its primary key.<T> List
<T> findByJoinTableField
(Class<T> entityClass, Field field, Object... bindValues) Retrieves entities by joining a table using a specified field.<T> List
<T> findByQuery
(Class<T> entityClass, String query, Object... bindValues) Retrieves entities based on a custom query.<T> List
<T> findByWhere
(Class<T> entityClass, String whereCondition, Object... bindValues) Retrieves entities based on a custom WHERE condition.<T> List
<T> findByWhereJoin
(Class<T> entityClass, Object... bindValues) Retrieves a single entity by joining tables based on custom conditions.void
Rolls back the current transaction.<T> T
Saves a new entity.<T> void
saveAll
(Class<T> entityClass, Collection<T> entities) Saves a collection of entities.void
Starts a transaction.<T> void
update
(Class<T> entityClass, Object entity, List<ColumnSnapshot> diff) Updates an entity with the provided changes.
-
Method Details
-
findById
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
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
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
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
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
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
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
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 typequery
- the custom SQL query with WHERE and JOIN clausesbindValues
- 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
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
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
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
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
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
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
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
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
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
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
Starts a transaction.- Throws:
SQLException
- If an SQL exception occurs.
-
commitTransaction
Commits the current transaction.- Throws:
SQLException
- If an SQL exception occurs.
-
rollbackTransaction
Rolls back the current transaction.- Throws:
SQLException
- If an SQL exception occurs.
-