+ All Categories
Transcript
Page 1: What's new in spring data

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

What’s new in Spring Data?Oliver Gierke - Thomas Darimont - Christoph Strobl

Page 2: What's new in spring data

Agenda

Overview Repositories

Store modules Q&A

Page 3: What's new in spring data

Release train

Page 4: What's new in spring data

!• 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

Page 5: What's new in spring data

Spring Data Modules

Core

Neo4j Gemfire

JPA

Solr

Elasticsearch

REST

CassandraCouchbase

Redis

MongoDB

Communitymodules

Coremodules

Page 6: What's new in spring data

Module setup - Codd

Core

Neo4j Gemfire

JPA

Solr

Elasticsearch

REST

CassandraCouchbase

Redis

MongoDB

Communitymodules

Coremodules

Page 7: What's new in spring data

Module setup - Dijkstra / Evans

Core

Neo4j Gemfire

JPA

Solr

Elasticsearch

REST

CassandraCouchbase

Redis

MongoDB

Communitymodules

Coremodules

Page 8: What's new in spring data

Evans GA!Hooray! \o/

Page 9: What's new in spring data
Page 10: What's new in spring data

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

Page 11: What's new in spring data

Spring DataRepositories

Pragmatic data access APIs

Page 12: What's new in spring data

Multi-storeconfiguration

We know what you were thinking!

Page 13: What's new in spring data

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)

Page 14: What's new in spring data

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

Page 15: What's new in spring data

Query methods

Page 16: What's new in spring data

SlicesPaging without the overhead

Page 17: What's new in spring data

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

Page 18: What's new in spring data

(Optional) supportNo more NullPointerExceptions with Java 8 or Guava

Page 19: What's new in spring data

Default methods

Page 20: What's new in spring data

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); } }

Page 21: What's new in spring data

Limiting result setsYou’r only interested in the top ones anyway, right?

Page 22: What's new in spring data

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); }

Page 23: What's new in spring data

Deriveddelete queries

Page 24: What's new in spring data

Demo

Page 25: What's new in spring data

Miscellaneous

Page 26: What's new in spring data

CDI improvementsEager instantiation and custom implementations

Page 27: What's new in spring data

Commongeo-spatial types

Page 28: What's new in spring data

NullsFirst /NullsLast

Page 29: What's new in spring data

Store moduleimprovements

Page 30: What's new in spring data

JPAJava Persistence API 2.1 support

Page 31: What's new in spring data

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

Page 32: What's new in spring data

Demo

Page 33: What's new in spring data

MongoDB

Page 34: What's new in spring data

Aggregationgo on with system variables

Page 35: What's new in spring data

Aggregation Framework

!• System Variables

• $$ROOT

• $$CURRENT

Aggregation aggregation = Aggregation.newAggregation( group(„foo"). push(Aggregation.ROOT).as("users"));

Page 36: What's new in spring data

Query ModifiersAlter query behavior

Page 37: What's new in spring data

Query Modifiers

• Define output and behavior of query

• $comment

• $maxTimeMS

• …

interface SampleRepository implements Repository<User, Long> { @Meta(comment=“s2gx2014”) List<User> findByFirstname(String firstname); }

Page 38: What's new in spring data

Full $text searchSimple - Powerful - Easy

Page 39: What's new in spring data

Text Search

!• Supported since MongoDB 2.6

• Multiple stemmers

• Different languages

interface SampleRepository implements Repository<User, Long> { List<User> findAllBy(TextCriteria criteria); }

Page 40: What's new in spring data

Redis

Page 41: What's new in spring data

SCANThe non-blocking alternative

Page 42: What's new in spring data

SCAN Support

• Non-blocking alternative

• KEYS

• SMEMBERS

Cursor<String> keys = redisConnection.scan(); !while(cursor.hasNext()) { cursor.next(); }

Page 43: What's new in spring data

SentinelMonitoring & failover for your cluster

Page 44: What's new in spring data

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); }

Page 45: What's new in spring data

Sentinel support

Redis

Page 46: What's new in spring data

Sentinel support

Redis Redis Redis

Page 47: What's new in spring data

Sentinel support

Redis Redis Redis

Sentinel Sentinel Sentinel

Page 48: What's new in spring data

Sentinel support

Redis Redis Redis

Sentinel Sentinel Sentinel

Page 49: What's new in spring data

Sentinel support

Redis Redis Redis

Sentinel Sentinel Sentinel

Page 50: What's new in spring data

Sentinel support

Redis Redis Redis

Sentinel Sentinel Sentinel

Page 51: What's new in spring data

Sentinel support

Redis Redis Redis

Sentinel Sentinel Sentinel

Page 52: What's new in spring data

Sentinel support

Redis Redis Redis

Sentinel Sentinel Sentinel

Page 53: What's new in spring data

Sentinel support

Redis Redis Redis

Sentinel Sentinel Sentinel

Page 54: What's new in spring data

Solr

Page 55: What's new in spring data

Deep paginationGo deep at top speed

Page 56: What's new in spring data

Deep pagination

!• Performance boost when going deep

• Uses cursor

Cursor<User> cursor = template.queryForCursor(q, User.class); !while(cursor.hasNext()) { User user = cursor.next(); }

Page 57: What's new in spring data

Schema SupportClient side schema management

Page 58: What's new in spring data

Schema Support

!• Usage of Schema Solr REST API

• Add new fields to existing schema.

@Configuration @EnableSolrRepositories(schemaCreationSupport = true) class SolrConfiguration { !}

Page 59: What's new in spring data

Spring Data REST

Page 60: What's new in spring data

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)

Page 61: What's new in spring data

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

Page 62: What's new in spring data

Demo

Page 63: What's new in spring data

Related talks

Page 64: What's new in spring data

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

Page 65: What's new in spring data

Sample codehttps://github.com/SpringOne2GX-2014/whats-new-in-spring-data

Page 66: What's new in spring data

Questions?


Top Related