DAO

  • Data Access Object, to save Model/Domain into the database.
  • Dao interface could look like this:
public interface Dao<T> {
    
    Optional<T> get(long id);
    
    List<T> getAll();
    
    void save(T t);
    
    void update(T t, String[] params);
    
    void delete(T t);
}
  • And you have to implement this interface, for example
public class UserDao implements Dao<User> {
    private final EntityManager entityManager;

	public void create(User user) {
		entityManager.persist(user);
	}
}

Note:

  • DAO is different than Repository Pattern. In a way such repository pattern can implement multiple DAOs and contains business logic.
  • DAO is purely just for data fetching