What's new in spring data

Post on 14-Jun-2015

1.524 views 2 download

Tags:

description

Speakers: Thomas Darimont, Oliver Gierke, Christoph Strobl Data / Integration Track This talk will give a broad overview of the new features introduced in the latest Spring Data release trains. We will cover recent additions and improvements in Spring Data Commons - the module that's shared amongst the store specific ones. We'll then delve into the latest and greatest features of individual store modules, like JPA, MongoDB, Neo4j, Solr and the community ones as well.

Transcript of 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

Agenda

Overview Repositories

Store modules Q&A

Release train

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

Spring Data Modules

Core

Neo4j Gemfire

JPA

Solr

Elasticsearch

REST

CassandraCouchbase

Redis

MongoDB

Communitymodules

Coremodules

Module setup - Codd

Core

Neo4j Gemfire

JPA

Solr

Elasticsearch

REST

CassandraCouchbase

Redis

MongoDB

Communitymodules

Coremodules

Module setup - Dijkstra / Evans

Core

Neo4j Gemfire

JPA

Solr

Elasticsearch

REST

CassandraCouchbase

Redis

MongoDB

Communitymodules

Coremodules

Evans GA!Hooray! \o/

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

Spring DataRepositories

Pragmatic data access APIs

Multi-storeconfiguration

We know what you were thinking!

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)

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

Query methods

SlicesPaging without the overhead

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

(Optional) supportNo more NullPointerExceptions with Java 8 or Guava

Default methods

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

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

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

Deriveddelete queries

Demo

Miscellaneous

CDI improvementsEager instantiation and custom implementations

Commongeo-spatial types

NullsFirst /NullsLast

Store moduleimprovements

JPAJava Persistence API 2.1 support

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

Demo

MongoDB

Aggregationgo on with system variables

Aggregation Framework

!• System Variables

• $$ROOT

• $$CURRENT

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

Query ModifiersAlter query behavior

Query Modifiers

• Define output and behavior of query

• $comment

• $maxTimeMS

• …

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

Full $text searchSimple - Powerful - Easy

Text Search

!• Supported since MongoDB 2.6

• Multiple stemmers

• Different languages

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

Redis

SCANThe non-blocking alternative

SCAN Support

• Non-blocking alternative

• KEYS

• SMEMBERS

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

SentinelMonitoring & failover for your cluster

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

Sentinel support

Redis

Sentinel support

Redis Redis Redis

Sentinel support

Redis Redis Redis

Sentinel Sentinel Sentinel

Sentinel support

Redis Redis Redis

Sentinel Sentinel Sentinel

Sentinel support

Redis Redis Redis

Sentinel Sentinel Sentinel

Sentinel support

Redis Redis Redis

Sentinel Sentinel Sentinel

Sentinel support

Redis Redis Redis

Sentinel Sentinel Sentinel

Sentinel support

Redis Redis Redis

Sentinel Sentinel Sentinel

Sentinel support

Redis Redis Redis

Sentinel Sentinel Sentinel

Solr

Deep paginationGo deep at top speed

Deep pagination

!• Performance boost when going deep

• Uses cursor

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

Schema SupportClient side schema management

Schema Support

!• Usage of Schema Solr REST API

• Add new fields to existing schema.

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

Spring Data REST

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)

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

Demo

Related talks

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

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

Questions?