Apparently you’d like to implement a Crudrepository which is part of Spring Data, but is used as a strategy for persistent entities (JPA).
Since you don’t want to use any JPA files, we go to an alternative:
The Spring Data JDBC Generic DAO implementation which seeks a light and simple Generic approach to RDBMS, was based on the Jdbctemplate (Spring Framework).
It delivers the full implementation of Spring Pagingandsortingrepository abstraction, without using JPA, XML.
public interface PagingAndSortingRepository<T, ID extends Serializable> extends CrudRepository<T, ID> {
T save(T entity);
Iterable<T> save(Iterable<? extends T> entities);
T findOne(ID id);
boolean exists(ID id);
Iterable<T> findAll();
long count();
void delete(ID id);
void delete(T entity);
void delete(Iterable<? extends T> entities);
void deleteAll();
Iterable<T> findAll(Sort sort);
Page<T> findAll(Pageable pageable);
Iterable<T> findAll(Iterable<ID> ids);
}
Below is a usage reference:
Page<User> page = userRepository.findAll(
new PageRequest(
5, 10,
new Sort(
new Order(DESC, "reputation"),
new Order(ASC, "user_name")
)
)
);
And a great subject with api creator Tomasz Nurkiewicz.
You want to create a Template to reuse methods from an Abstract class for CRUD operations - Create, Read, Update, Delete? And then don’t have to have these methods rewritten in your DAO classes? Are you using a relational database? What’s the problem with having to implement these methods? And what’s the problem with using JPA?
– Filipe Miranda
Take a look in this Tutorial’s point topic. it explains well what you are looking for:
– camargorodrigo
Use Relational Database, I have no problem, but I wanted to develop a own for specific methods because I will not use inheritance but relational tables. rs
– Tiago Ferezin
Tiago, it’s still not clear to me what its purpose is. Don’t need to write methods with select, update? Or do you want to learn how DAO works? If you want a layer abstraction, it seems to me that you want to build a small API to abstract CRUD operations, but you will end up having to map the entities. Explain your purpose better.
– Filipe Miranda
is not to write DAO methods in all classes, for me to make my standard of consultations
– Tiago Ferezin
A few years ago, I had a Genericdao that was an abstract class with exactly those characteristics, and it seemed like a good idea. In the end I ended up abandoning this, because I had a strong tendency to create more problems than to solve.
– Victor Stafusa
Eh like this Genericdao msm Victor
– Tiago Ferezin