views:

61

answers:

1

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 pattern in this situation?

How should client create SearchModel instance?

Please, share.

Regards.

+3  A: 

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.

duffymo
+1, indeed. (there is a generic dao project here http://code.google.com/p/generic-dao/ )
Bozho