Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What's new in Spring Data?

What's new in Spring Data?

Slides of the talk, Christoph Strobl, Thomas Darimont and me held at SpringOne2GX 2014 in Dallas, TX. Introducting the latest features of the Spring Data umbrella project. @springcentral

Oliver Drotbohm

September 09, 2014
Tweet

More Decks by Oliver Drotbohm

Other Decks in Programming

Transcript

  1. © 2014 SpringOne 2GX. All rights reserved. Do not distribute

    without permission. What’s new in Spring Data? Oliver Gierke - Thomas Darimont - Christoph Strobl
  2. ! • Release coordination effort make sure modules are compatible

    • Reduce different versions into a single canonical name to refer to Release train 03/2013 Arora 09/2013 Babbage 02/2014 Codd 05/2014 Dijkstra 09/2014 Evans
  3. Spring Data Modules Core Neo4j Gemfire JPA Solr Elasticsearch REST

    Cassandra Couchbase Redis MongoDB Community
 modules Core
 modules
  4. Module setup - Codd Core Neo4j Gemfire JPA Solr Elasticsearch

    REST Cassandra Couchbase Redis MongoDB Community
 modules Core
 modules
  5. Module setup - Dijkstra / Evans Core Neo4j Gemfire JPA

    Solr Elasticsearch REST Cassandra Couchbase Redis MongoDB Community
 modules Core
 modules
  6. Spring Data Evans - Major themes • Upgrade to Spring

    4.0 • Support for top/first keywords in derived queries • Support for MongoDB 2.6 features like text search • SpEL support for Spring Data JPA (Spring Security integration) • Redis Sentinel support • ALPS and excerpt projections for Spring Data REST • Improved multi-store configuration • Asciidoctor for reference documentation
  7. Improved multi-store configuration ! • Triggered if multiple Spring Data

    modules are detected • Modules only register for interfaces that a assigned to the store • Annotations on domain types (@Entity, @Document) • Store specific repository base interface (not recommended)
  8. Debug output … DEBUG … - Multiple Spring Data modules

    found, entering strict repository configuration mode! ! … DEBUG … - Spring Data JPA - Could not safely identify store assignment for repository candidate interface ….OrderRepository. ! … DEBUG … - Spring Data JPA - Registering repository:
 Interface: ….CustomerRepository Factory: ….JpaRepositoryFactoryBean
  9. Slices ! • Pagination • Additional query to calculate the

    total number of elements ! • Slices • Reads one more element than necessary to find out about presence of next slice (optional) • Store-specific optimization
  10. Slices and Optional example interface SampleRepository implements Repository<User, Long> {

    Slice<User> findByLastname(String lastname, Pageable page); ! Optional<User> findByEmailAddress(EmailAddress email); ! Optional<User> findByLastname(String lastname); ! default Optional<Customer> findByLastname(Customer c) { return findByLastname(c == null ? null : c.lastname); } }
  11. Limiting result sets ! • Previous options • Use Pageable/Page

    to dynamically restrict results • Additional keywords to statically restrict results interface SampleRepository implements Repository<User, Long> { List<User> findTop10ByNameLike(String name, Sort sort); }
  12. JPA Improvements ! • JPA 2.1 support • Execution of

    stored procedures • Support for entity graph definitions ! • Integration with Spring Security • Out of the box support coming with Spring Security 4.1
  13. Aggregation Framework ! • System Variables • $$ROOT • $$CURRENT

    Aggregation aggregation = Aggregation.newAggregation( group(„foo"). push(Aggregation.ROOT).as("users"));
  14. Query Modifiers • Define output and behavior of query •

    $comment • $maxTimeMS • … interface SampleRepository implements Repository<User, Long> { @Meta(comment=“s2gx2014”) List<User> findByFirstname(String firstname); }
  15. Text Search ! • Supported since MongoDB 2.6 • Multiple

    stemmers • Different languages interface SampleRepository implements Repository<User, Long> { List<User> findAllBy(TextCriteria criteria); }
  16. SCAN Support • Non-blocking alternative • KEYS • SMEMBERS Cursor<String>

    keys = redisConnection.scan(); ! while(cursor.hasNext()) { cursor.next(); }
  17. Sentinel Support ! • Monitoring and failover • Currently only

    available using Jedis @Bean public RedisSentinelConfiguration sentinelConfig() { return new RedisSentinelConfiguration().master("mymaster") .sentinel("localhost", 26379) .sentinel("localhost", 26380); }
  18. Deep pagination ! • Performance boost when going deep •

    Uses cursor Cursor<User> cursor = template.queryForCursor(q, User.class); ! while(cursor.hasNext()) { User user = cursor.next(); }
  19. Schema Support ! • Usage of Schema Solr REST API

    • Add new fields to existing schema. @Configuration @EnableSolrRepositories(schemaCreationSupport = true) class SolrConfiguration { ! }
  20. Spring Data REST • Implements common patterns on top of

    repositories • Collection / item resources • Association resources • Search resources • Leverages hypermedia and internet standards • URI Templates (RFC 6570) • application/hal+json • text/uri-list (RFC 2483) • profile link relation (RFC 6906)
  21. ALPS support & excerpt projections ! • Application Level Profile

    Semantics • Spring Data REST exposes resources describing the service ! • Interface-based programming model to define custom projections • Configuration to define excerpt projections
  22. Spring Data Related Talks • Cassandra / Couchbase - Tue,

    4:30 pm • Cassandra, Couchbase and Spring Data in the Enterprise • Spring Data BOF - Tue, 9:00 pm • REST - Wed, 8:30 am • Spring Data REST - Data Meets Hypermedia • Neo4j - Wed, 10:30 am • Artistic Spring Data Neo4j 3.0 with Spring Boot and Van Goch • GORM - Wed, 12:45 pm • Advanced GORM – Beyond Relational