Slide 1

Slide 1 text

What’s new in SpringData Christoph Strobl @stroblchristoph Lovelace 30min

Slide 2

Slide 2 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/nacht/astronomie-galaxie-himmel-dunkel-daemmerung-konstellation-dunkel-nacht
 License: PD 2 Augusta Ada King (Ada Lovelace) was an English mathematician known for her work 
 on Charles Babbage’s proposed mechanical general-purpose computer, the Analytical Engine. (1815-1852)

Slide 3

Slide 3 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/nacht/astronomie-galaxie-himmel-dunkel-daemmerung-konstellation-dunkel-nacht
 License: PD 3 352 Days 900+ Issues 16 Modules JDBC Transactions Reactive Performance Client Sessions Change Streams Distinct Queries Fluent API Kotlin Extensions JCache Cluster SCAN Pub/Sub Vavr

Slide 4

Slide 4 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 4 Image: https://pixnio.com/de/landschaften/wald/holz-natur-sommer-pflanzen-rasen-dawn-farn-landschaft-baum-blatt-umwelt License: PD Data Commons

Slide 5

Slide 5 text

Methods that create a clone but with one changed field. 5 Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Immutable Setters (Wither Methods) class ValueClass { final @Nullable String id; final String value; ValueClass(@Nullable String id, String value) { this.id = id; this.value = value; } ValueClass withId(String id) { return new ValueClass(id, this.value); } String getId() { return this.id; } String getValue() { return this.value } } https://pixnio.com/de/landschaften/steinformationen/felsen-himmel-steinen# 
 License: PD

Slide 6

Slide 6 text

Methods that create a clone but with one changed field. 6 Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ class ValueClass { final @Nullable String id; final String value; ValueClass(@Nullable String id, String value) { this.id = id; this.value = value; } ValueClass withId(String id) { return new ValueClass(id, this.value); } String getId() { return this.id; } String getValue() { return this.value } } class ValueClass { @Nullable String id; final String value; ValueClass(String value) { this.value = value; } String getId() { return this.id; } String getValue() { return this.value } } ! Immutable Setters (Wither Methods) https://pixnio.com/de/landschaften/steinformationen/felsen-himmel-steinen# 
 License: PD

Slide 7

Slide 7 text

7 Repository Initialization Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 0 10 20 30 40 Default Deferred Lazy Bootstrap Time (less is better) https://pixnio.com/de/landschaften/himmel/vogel-flug-tageslicht-blauer-himmel-wolke-wind-klima
 License: PD

Slide 8

Slide 8 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 8 JPA https://pixnio.com/de/landschaften/meer/meer-natur-dawn-wasser-meer-sonne-sonnenuntergang-dammerung-himmel-strand 
 License: PD

Slide 9

Slide 9 text

https://pixnio.com/de/landschaften/himmel/vogel-flug-tageslicht-blauer-himmel-wolke-wind-klima
 License: PD Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JPA Repository Initialization 9 Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 0 10 20 30 40 Default Deferred Lazy Bootstrap Time (less is better) for JPA
 infrastructure spring-projects/spring-data-examples jpa/deferred

Slide 10

Slide 10 text

https://pixnio.com/de/landschaften/himmel/vogel-flug-tageslicht-blauer-himmel-wolke-wind-klima
 License: PD Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JPA Repository Initialization 10 0 10 20 30 40 Default Deferred Lazy Bootstrap Time (less is better) for JPA
 infrastructure @Configuration @EnableJpaRepositories class JpaRepositoryConfiguration { } spring-projects/spring-data-examples jpa/deferred

Slide 11

Slide 11 text

https://pixnio.com/de/landschaften/himmel/vogel-flug-tageslicht-blauer-himmel-wolke-wind-klima
 License: PD Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Deferred JPA Repository Initialization 11 0 10 20 30 40 Default Deferred Lazy Bootstrap Time (less is better) for JPA
 infrastructure @Configuration @EnableJpaRepositories(bootstrapMode = BootstrapMode.DEFERRED) class LazyJpaRepositoryConfiguration { } @Bean LocalContainerEntityManagerFactoryBean entityManagerFactory(JpaVendorAdapter vendorAdapter,… ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); threadPoolTaskExecutor.setDaemon(true); threadPoolTaskExecutor.afterPropertiesSet(); LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); emf.setBootstrapExecutor(threadPoolTaskExecutor); emf.setDataSource(dataSource); emf.setJpaVendorAdapter(jpaVendorAdapter); emf.setPackagesToScan("com.example"); return emf; } spring-projects/spring-data-examples jpa/deferred spring.data.jpa.repositories.bootstrap-mode=

Slide 12

Slide 12 text

https://pixnio.com/de/landschaften/himmel/vogel-flug-tageslicht-blauer-himmel-wolke-wind-klima
 License: PD Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Lazy JPA Repository Initialization 12 Bootstrap Time (less is better) for JPA
 infrastructure 0 10 20 30 40 Default Deferred Lazy @Configuration @EnableJpaRepositories(bootstrapMode = BootstrapMode.LAZY) class DeferredJpaRepositoryConfiguration { } @Bean LocalContainerEntityManagerFactoryBean entityManagerFactory(JpaVendorAdapter vendorAdapter,… ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); threadPoolTaskEx … } spring-projects/spring-data-examples jpa/deferred How Fast is Spring?
 tomorrow 10:30am

Slide 13

Slide 13 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 13 JDBC https://pixnio.com/de/landschaften/sonnenschein/sonnenschein-landschaft-sonnenuntergang-berg-himmel-sonne-sonnenaufgang
 License: PD

Slide 14

Slide 14 text

https://pixnio.com/de/landschaften/sonnenschein/sonnenschein-landschaft-sonnenuntergang-berg-himmel-sonne-sonnenaufgang
 License: PD Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JDBC Repositories 14 Spring Data JDBC
 2:00pm | National Harbor 4-5 interface LegoSetRepository extends CrudRepository { @Query("SELECT m.name model_name, m.description, l.name set_name FROM model m JOIN lego_set l ON m.lego_set = l.id WHERE :age BETWEEN l.min_age and l.max_age") List reportModelForAge(@Param("age") int age); @Modifying @Query("UPDATE model SET name = lower(name) WHERE name !<> lower(name)") int lowerModelName(); } spring-projects/spring-data-examples jdbc/basic

Slide 15

Slide 15 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 15 R2DBC sneak peek https://pixnio.com/de/landschaften/narrows-landschaft/wasserfall-hohle-strom-wasser-natur-fluss-landschaft-stein
 License: PD

Slide 16

Slide 16 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/narrows-landschaft/wasserfall-hohle-strom-wasser-natur-fluss-landschaft-stein
 License: PD Reactive Database Client 16 @Configuration class ReactiveDbcConfiguration { @Bean TransactionalDatabaseClient dbClient() { return TransactionalDatabaseClient.create(new PostgresqlConnectionFactory(…)); } } Flux deleted = databaseClient.inTransaction(db !-> { Mono insert = db.insert() .into(Lego.class) .using(legoSet) .then(); Mono delete = db.execute() .sql("DELETE FROM lego WHERE id = $1") .bind("$1", 42055) .fetch() .rowsUpdated(); return insert.then(delete); }); Reactive Relational Database Connectivity
 12:10pm | National Harbor 4-5 spring-projects/spring-data-examples jdbc/r2dbc

Slide 17

Slide 17 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 17 MongoDB https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD

Slide 18

Slide 18 text

https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ MongoDB 4.0 Multi Document Transactions 18 @Configuration class TransactionConfiguration { @Bean MongoTransactionManager txManager(MongoDbFactory dbFactory) { return new MongoTransactionManager(dbFactory); } } new TransactionTemplate(txManager).execute(action !-> { orderRepository.save(order); UpdateResult result = mongoOps.update(Book.class) .matching(query(where("id").is(book.id)… .apply(new Update().inc("available", -1)) !// .first(); if (result.getModifiedCount() !!= 1) { throw new BookSoldOutException(book); } return order; }); try (ClientSession session = client.startSession()) { session.startTransaction(); col.insertOne(session, order); UpdateResult result = col.updateOne(session, … if (result.getModifiedCount() !!= 1) { throw new BookSoldOutException(book); } session.commitTransaction(); } spring-projects/spring-data-examples mongodb/transactions Next Generation MongoDB
 3:20pm | National Harbor 4-5

Slide 19

Slide 19 text

https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Validators & Json Schema 19 Criteria criteria = where("name").exists(true).ne(null).type(2) .and("age").exists(true).ne(null).type(16).gte(0).lte(125); Validator validator = Validator.criteria(criteria); MongoJsonSchema schema = MongoJsonSchema.builder() .required("name", "age") .properties( string("name").minLength(1), int32("age").gte(0).lte(125) .build(); Validator validator = Validator.schema(schema); { "name" : { "$exists" : true, "$ne" : null, "$type" : 2 }, "age" : { "$exists" : true, "$ne" : null, "$type" : 16, "$gte" : 0, "$lte" : 125 } } { "type": "object", "required": [ "name", "age" ], "properties": { "name": { "type": "string", "minLength": 1 }, "age": { "bsonType": "int", "minimum" : 0, "exclusiveMinimum" : false, "maximum" : 125, "exclusiveMaximum" : false } } } spring-projects/spring-data-examples mongodb/schema-validation

Slide 20

Slide 20 text

https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Distinct Queries 20 List values = template.query(Inventory.class) .distinct("size") .all(); List values = template.query(Inventory.class) .distinct("size") .as(String.class) .all(); SELECT DISTINCT col1, col2, …
 FROM table db.inventory.distinct("size") > [ "M", "S", "L"] { name: "INV-1", size: "M" } { name: "INV-2", size: [ "S", "L" ] } { name: "INV-3", size: { "length" : 10, "height" : 10 } }

Slide 21

Slide 21 text

https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Change Streams 21 MessageListenerContainer container = new DefaultMessageListenerContainer(template); container.start(); MessageListener, User> listener = … ChangeStreamRequest request = ChangeStreamRequest.builder() .collection("user") .filter(newAggregation(match(where("status").is("active")))) .publishTo(listener) .build(); Subscription subscription = container.register(request, User.class); ChangeStreamOptions options = ChangeStreamOptions.builder() .filter(newAggregation(match(where("status").is("active"))) .build(); Flux> flux = reactiveTemplate.changeStream("user", options, User.class); $ db.oplog.rs.find() .addOption(DBQuery.Option.tailable) .addOption(DBQuery.Option.awaitData); > … spring-projects/spring-data-examples mongodb/change-streams

Slide 22

Slide 22 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 22 https://pixnio.com/de/tapeten/sonnenuntergang-sonne-sonnenuntergang-kugel-himmel-schneeflocke-frost-kristall-landschaft
 License: PD Gemfire
 Geode Apache

Slide 23

Slide 23 text

https://pixnio.com/de/tapeten/sonnenuntergang-sonne-sonnenuntergang-kugel-himmel-schneeflocke-frost-kristall-landschaft
 License: PD Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Boot for Apache Geode and Pivotal Gemfire Health Indicators for • Cache • Disk Stores • Regions • Pools • Indexes • Event Queues • … 23 Spring Session Support Scaling Spring Boot Apps
 watch the replay!

Slide 24

Slide 24 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 24 Redis https://pixnio.com/de/landschaften/gletscher/hoehe-wolken-kaelte-frost-gletscher-eis-eisberg-winter
 License: PD

Slide 25

Slide 25 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/gletscher/hoehe-wolken-kaelte-frost-gletscher-eis-eisberg-winter
 License: PD Query By Example 25 class RedisRepository extends CrudRepository, QueryByExampleExecutor { } spring-projects/spring-data-examples redis/repositories Example example = Example.of(new Person().withLastname("stark")); Iterable starks = repository.findAll(example);

Slide 26

Slide 26 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/gletscher/hoehe-wolken-kaelte-frost-gletscher-eis-eisberg-winter
 License: PD Write to Master read from Replica (aka Slave) 26 @Configuration class WriteToMasterReadFromSlaveConfiguration { @Bean public RedisConnectionFactory connectionFactory() { LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder() .readFrom(ReadFrom.SLAVE_PREFERRED) .build(); RedisStandaloneConfiguration serverConfig = new RedisStandaloneConfiguration("server", 6379); return new LettuceConnectionFactory(serverConfig, clientConfig); } }

Slide 27

Slide 27 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/gletscher/hoehe-wolken-kaelte-frost-gletscher-eis-eisberg-winter
 License: PD Reactive Pub/Sub 27 ReactiveRedisTemplate template = … Mono publish = template.convertAndSend("channel-1", "message"); template.listenToChannel("channel-1").doOnNext(msg !-> { !// message processing !!... }).subscribe(); ReactiveRedisConnectionFactory factory = … ReactiveRedisMessageListenerContainer container = new ReactiveRedisMessageListenerContainer(factory); Flux> stream = container.receive(ChannelTopic.of("channel-1")); Flux> stream = container.receive(ChannelTopic.of("channel-2")); template.listenToChannel("channel-2").doOnNext(msg !-> { !// message processing !!... }).subscribe(); connection connection 1 connection each 1 shared connection connection

Slide 28

Slide 28 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/gletscher/hoehe-wolken-kaelte-frost-gletscher-eis-eisberg-winter
 License: PD Reactive SCAN & Cluster SCAN 28 ReactiveRedisConnection connection = … Mono> keys = connection.keyCommands().keys(…); ReactiveRedisConnection connection = … Flux keys = connection.keyCommands().scan(…); Under the Hood of Reactive
 3:20pm | National Harbor 4-5

Slide 29

Slide 29 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 29 Cassandra https://pixnio.com/de/tiere/insekten-ungeziefer/spinnen/spinne-netz-zweig-falle-faden-insekt-tier
 License: PD

Slide 30

Slide 30 text

https://pixnio.com/de/tiere/insekten-ungeziefer/spinnen/spinne-netz-zweig-falle-faden-insekt-tier
 License: PD Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Lifecycle Events 30 public class BeforeConvertListener extends AbstractCassandraEventListener { @Override public void onBeforeSave(BeforeSaveEvent event) { !// does some auditing manipulation, set timestamps, whatever } }

Slide 31

Slide 31 text

https://pixnio.com/de/tiere/insekten-ungeziefer/spinnen/spinne-netz-zweig-falle-faden-insekt-tier
 License: PD Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Fluent Template API 31 List result = template.query(User.class) .matching(query(where("jedi").is(true))) .all()

Slide 32

Slide 32 text

https://pixnio.com/de/tiere/insekten-ungeziefer/spinnen/spinne-netz-zweig-falle-faden-insekt-tier
 License: PD Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Fluent Template API (with Kotlin) 32 val result = template.query() .matching(query(where("jedi").isEqualTo(true))) .all()

Slide 33

Slide 33 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 33 Neo4j https://pixnio.com/de/universum/galaxy-abstrakt-astronomie-konstellation-dunkelheit
 License: PD

Slide 34

Slide 34 text

https://pixnio.com/de/universum/galaxy-abstrakt-astronomie-konstellation-dunkelheit
 License: PD Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Neo4j Housekeeping - naming, structure, components, documentation 34 ★ SpEL support in @Query ★ Optimistic Locking using @Version ★ Persistence Constructors \ö/ ★ Traverse relationships in derived queries

Slide 35

Slide 35 text

> Stay Connected. Spring Data Lovelace out now! 
 Check it out with Boot 2.1.M4 #springone @s1p 6:30 pm Fitness Center
 Level P

Slide 36

Slide 36 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Safe Harbor Statement The following is intended to outline the general direction of Pivotal's offerings. It is intended for information purposes only and may not be incorporated into any contract. Any information regarding pre-release of Pivotal offerings, future updates or other planned modifications is subject to ongoing evaluation by Pivotal and is subject to change. This information is provided without warranty or any kind, express or implied, and is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions regarding Pivotal's offerings. These purchasing decisions should only be based on features currently available. The development, release, and timing of any features or functionality described for Pivotal's offerings in this presentation remain at the sole discretion of Pivotal. Pivotal has no obligation to update forward looking information in this presentation. 36