Your SlideShare is downloading. ×
Hands On Spring Data
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Hands On Spring Data


Published on

Slides to the Hands On Spring Data lab, presented in Paris on Dec 10th, 2012. Code exercises are here:

Slides to the Hands On Spring Data lab, presented in Paris on Dec 10th, 2012. Code exercises are here:

  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Hands On Spring DataEric Bottard, Developer Advocate, VMware@ebottardFlorent Biville, Developer, Lateral Thoughts@fbiville© 2012 SpringSource, by VMware
  • 2. Eric BOTTARD• Developer Advocate VMware• @ebottard• ebottard@vmware.com2
  • 3. Florent BIVILLE• Développeur chez LateralThoughts• @fbiville3
  • 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
  • 5. RelationalJDBCJPA
  • 6. Document storeMongoDBCouchDB
  • 7. Column orientedHBaseCassandra
  • 8. GraphNeo4jOrientDB
  • 9. Data GridsGemFireCoherenceTerracotta
  • 10. Key ValueRedisRiak
  • 11. Big DataHadoop
  • 12. Templates
  • 13. Mapping
  • 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
  • 15. Example: MongoDB@Document@CompoundIndexes({ @CompoundIndex(name = "age_idx", def = "{lastName: 1, age: -1}")})public class Person<T extends Address> { @Id private String id; @Indexed(unique = true) private Integer ssn; @Field("fName") private String firstName; @Indexed private String lastName; @Transient private Integer accountTotal; @DBRef private List<Account> accounts; private T address;
  • 16. Repositories
  • 17. Repositoriespublic interface PersonRepository extends CrudRepository<User, Long> { …}No implementation needed!
  • 18. Magic Finders
  • 19. Magic Finderspublic interface PersonRepository extends Repository<User, Long> { List<Person> findByEmailAddressAndLastname(EmailAddress emailAddress, Stringlastname); // Enables the distinct flag for the query List<Person> findDistinctPeopleByLastnameOrFirstname(String lastname, Stringfirstname); List<Person> findPeopleDistinctByLastnameOrFirstname(String lastname, Stringfirstname); // Enabling ignoring case for an individual property List<Person> findByLastnameIgnoreCase(String lastname); // Enabling ignoring case for all suitable properties List<Person> findByLastnameAndFirstnameAllIgnoreCase(String lastname, Stringfirstname); // Enabling static ORDER BY for a query List<Person> findByLastnameOrderByFirstnameAsc(String lastname); List<Person> findByLastnameOrderByFirstnameDesc(String lastname);}
  • 20. Pagination
  • 21. Pagination and Dynamic Orderingpublic interface PersonRepository extends CrudRepository<User, Long> { Page<User> findByLastname(String lastname, Pageable pageable); List<User> findByLastname(String lastname, Sort sort); // NOTE: Pageable embeds a Sort}
  • 22. Qu eries
  • 23. Explicit Queriespublic 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);}
  • 24. Cross Store support
  • 25. Query DSL Integration
  • 26. REST
  • 27. REST Shell
  • 28. Customization
  • 29. JSON
  • 30. Mongo DB - schema-less document DBdatabasesmongo> show dbs; myDatabase 0.3046578 GBmongo> use myDatabase; collections mongo> show collections; rockCollection colleagueSean mongo> db.rockCollection.find().pretty(); // last call “prettifies” output documents mongo> db.rockCollection.find({name:"The Beatles"}).pretty(); {"_id" : ObjectId("50b7d870744e5ef5eee5224e"), "_class" : "", "name" : "The Beatles", [...] }
  • 31. MongoDB: Queries as JSON documentsdb.inventory.find({ price:1.99, $or: [ { qty: { $lt: 20 } }, { sale: true } ]})
  • 32. 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
  • 33. Nodes & Relationships35
  • 34. Nodes NoSQL Spring HELPS_WITH standsFor: "Not Only Data how: "it roxx" SQL"IS_PART_OF Properties Relationship Spring
  • 35. Cypher
  • 36. Neo4J - Cypher Query Languagestart doctor=node:characters(character = Doctor)match (doctor)<-[:COMPANION_OF]-(companion) -[:APPEARED_IN]->(episode)return companion.character, count(episode)order by count(episode) desclimit 5
  • 37. Image credits• keys• spiderweb• columns• documents• umbrella• nail• relational• callback• repositories• pagination• magic• cypher• mapping• grid• elephant• cross knot• rope knot• married• shell• diesel• car tuning• rest on couch: If you haven’t, go watch Fight Club. NOW.39