I want to make an Abstract Class in Java for use in the Dao classes that I will use in various projects, not to repeat the selection, insertion, deletion, and update methods in all dao classes.
I did not want to use hibernate and others.
Thankful
I want to make an Abstract Class in Java for use in the Dao classes that I will use in various projects, not to repeat the selection, insertion, deletion, and update methods in all dao classes.
I did not want to use hibernate and others.
Thankful
Apparently you'd like to implement a CrudRepository which is part of Spring Data, but is used as a strategy for persistent entities (JPA).
As you do not want to use any JPA provider, we move on to an alternative:
The Spring Data JDBC generic DAO implementation that seeks a generic, lightweight and simple approach to RDBMS, was based on the JdbcTemplate (Spring Framework) .
It delivers the complete implementation of the 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);
}
Here's 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 idealizer of the api Tomasz Nurkiewicz .