This document summarizes a presentation on Spring Data by Eric Bottard and Florent Biville. Spring Data aims to provide a consistent programming model for new data stores while retaining store-specific features. It uses conventions over configuration for mapping objects to data stores. Repositories provide basic CRUD functionality without implementations. Magic finders allow querying by properties. Pagination and sorting are also supported.
4. “ Spring Data is an umbrella project which
aims to provide a familiar and consistent
Spring-based programming model for for
new datastores while retaining store-
specific features and capabilities
14. Mapping
• Tells the framework how to store object properties and
relationships
• Favors convention over configuration
• Does not try to shoehorn one model into another (e.g.
does not use JPA annotations for Mongo)
14
19. Magic Finders
public interface PersonRepository extends Repository<User, Long> {
List<Person> findByEmailAddressAndLastname(EmailAddress emailAddress, String
lastname);
// Enables the distinct flag for the query
List<Person> findDistinctPeopleByLastnameOrFirstname(String lastname, String
firstname);
List<Person> findPeopleDistinctByLastnameOrFirstname(String lastname, String
firstname);
// Enabling ignoring case for an individual property
List<Person> findByLastnameIgnoreCase(String lastname);
// Enabling ignoring case for all suitable properties
List<Person> findByLastnameAndFirstnameAllIgnoreCase(String lastname, String
firstname);
// Enabling static ORDER BY for a query
List<Person> findByLastnameOrderByFirstnameAsc(String lastname);
List<Person> findByLastnameOrderByFirstnameDesc(String lastname);
}
23. Explicit Queries
public interface ProductsRepository extends JpaRepository<Product, Long> {
@Query(value = "select p from Product p order by p.rating desc",
countQuery = "select count(p) from Product p")
Page<Product> findTopRated(Pageable pageable);
}
33. GridFS - can I haz large objectz?
• mongo> show collections;
– fs.chunks
– fs.files
• CHUNKS
– 256KB portion of a Mongo object (a.k.a. file), stored into
collection “fs.chunks”
• FILES
– Metadata about the file stored into “fs.files”: filename, content
type ...
• Spring Data brings
– GridFsTemplate
– GridFsResource (wraps GridFSDBFile)
33