Template for transferring a search model to dao

We have dao as a project (jar file).

Clients use their interfaces and factories to work with the database.

In addition to standard CRUD operations, dao allows you to search for an object by some search criteria.

What is the best way to present these criteria?

Does the transfer pattern match the object in this situation?

How should a client create an instance of SearchModel?

Please share.

Sincerely.

+3
source share
1 answer

I usually use a generic DAO:

package persistence;

import java.io.Serializable;
import java.util.List;

public interface GenericDao<T, K extends Serializable>
{
    T find(K id);
    List<T> find();
    List<T> find(T example);
    List<T> find(String queryName, String [] paramNames, Object [] bindValues);

    K save(T instance);
    void update(T instance);
    void delete(T instance);
}

This allows me to use named queries with related parameters and a query using an example. I found it flexible enough to satisfy most of my needs.

+3

Source: https://habr.com/ru/post/1746981/


All Articles