We have a dao as a project (jar file).
Clients use its interfaces and factories to operate with database.
Alongside with standard CRUD operations, dao allows you to search an entity by some search criteria.
What is the best way to represent this criteria?
Is transfer object appropriate patter开发者_StackOverflown in this situation?
How should client create SearchModel instance?
Please, share.
Regards.
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 bound parameters and query by example. I've found it to be flexible enough to satisfy most of my needs.
精彩评论