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

What's new in Spring Data Lovelace

What's new in Spring Data Lovelace

Have a comprehensive look at new features in Spring Data release train Lovelace. Including selected new features, enhancements, compatibility improvements and language extensions for Kotlin.

Christoph Strobl

September 26, 2018
Tweet

More Decks by Christoph Strobl

Other Decks in Programming

Transcript

  1. 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)
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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=
  11. 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
  12. 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
  13. 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<Lego, Integer> { @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<ModelReport> 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
  14. 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
  15. 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<Integer> deleted = databaseClient.inTransaction(db !-> { Mono<Void> insert = db.insert() .into(Lego.class) .using(legoSet) .then(); Mono<Integer> 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
  16. 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
  17. 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
  18. 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
  19. 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<Object> values = template.query(Inventory.class) .distinct("size") .all(); List<String> 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 } }
  20. 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<ChangeStreamDocument<Document>, 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<ChangeStreamEvent<User!>> 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
  21. 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
  22. 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!
  23. 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
  24. 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<Person, String>, QueryByExampleExecutor<Person> { } spring-projects/spring-data-examples redis/repositories Example<Person> example = Example.of(new Person().withLastname("stark")); Iterable<Person> starks = repository.findAll(example);
  25. 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); } }
  26. 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<Long> publish = template.convertAndSend("channel-1", "message"); template.listenToChannel("channel-1").doOnNext(msg !-> { !// message processing !!... }).subscribe(); ReactiveRedisConnectionFactory factory = … ReactiveRedisMessageListenerContainer container = new ReactiveRedisMessageListenerContainer(factory); Flux<ChannelMessage<String, String!>> stream = container.receive(ChannelTopic.of("channel-1")); Flux<ChannelMessage<String, String!>> 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
  27. 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<List<ByteBuffer!>> keys = connection.keyCommands().keys(…); ReactiveRedisConnection connection = … Flux<ByteBuffer> keys = connection.keyCommands().scan(…); Under the Hood of Reactive
 3:20pm | National Harbor 4-5
  28. 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
  29. 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<Person> { @Override public void onBeforeSave(BeforeSaveEvent<Person> event) { !// does some auditing manipulation, set timestamps, whatever } }
  30. 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<User> result = template.query(User.class) .matching(query(where("jedi").is(true))) .all()
  31. 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<User>() .matching(query(where("jedi").isEqualTo(true))) .all()
  32. 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
  33. 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
  34. > Stay Connected. Spring Data Lovelace out now! 
 Check

    it out with Boot 2.1.M4 #springone @s1p 6:30 pm Fitness Center
 Level P
  35. 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