Polishing of CustomerRepository in JPA Java 8 sample project.

This commit is contained in:
Oliver Gierke
2014-07-22 06:33:18 +02:00
parent 58ac158e39
commit d1623673d8

View File

@@ -35,11 +35,29 @@ public interface CustomerRepository extends Repository<Customer, Long> {
*/
Optional<Customer> findOne(Long id);
/**
* Saves the given {@link Customer}.
*
* @param customer
* @return
*/
<S extends Customer> S save(S customer);
/**
* Sample method to derive a query from using JDK 8's {@link Optional} as return type.
*
* @param lastname
* @return
*/
Optional<Customer> findByLastname(String lastname);
/**
* Sample default method to show JDK 8 feature support.
*
* @param customer
* @return
*/
default Optional<Customer> findByLastname(Customer customer) {
return findByLastname(customer.lastname);
return findByLastname(customer == null ? null : customer.lastname);
}
}