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.
What’s new in SpringDataChristoph Strobl@stroblchristophLovelace30min
View Slide
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-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: PD2Augusta 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)
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-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: PD3352 Days900+ Issues16 ModulesJDBCTransactionsReactivePerformanceClient SessionsChange StreamsDistinct QueriesFluent APIKotlin ExtensionsJCacheCluster SCANPub/SubVavr
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/4Image: https://pixnio.com/de/landschaften/wald/holz-natur-sommer-pflanzen-rasen-dawn-farn-landschaft-baum-blatt-umweltLicense: PDData Commons
Methods that create a clone but with one changed field.5Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-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
Methods that create a clone but with one changed field.6Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-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
7Repository InitializationUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/010203040Default Deferred LazyBootstrap Time (less is better)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 CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/8JPAhttps://pixnio.com/de/landschaften/meer/meer-natur-dawn-wasser-meer-sonne-sonnenuntergang-dammerung-himmel-strand License: PD
https://pixnio.com/de/landschaften/himmel/vogel-flug-tageslicht-blauer-himmel-wolke-wind-klima License: PDUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/JPA Repository Initialization9Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/010203040Default Deferred LazyBootstrap Time (less is better)for JPA infrastructurespring-projects/spring-data-examplesjpa/deferred
https://pixnio.com/de/landschaften/himmel/vogel-flug-tageslicht-blauer-himmel-wolke-wind-klima License: PDUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/JPA Repository Initialization10010203040Default Deferred LazyBootstrap Time (less is better)for JPA infrastructure@Configuration@EnableJpaRepositoriesclass JpaRepositoryConfiguration { }spring-projects/spring-data-examplesjpa/deferred
https://pixnio.com/de/landschaften/himmel/vogel-flug-tageslicht-blauer-himmel-wolke-wind-klima License: PDUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/Deferred JPA Repository Initialization11010203040Default Deferred LazyBootstrap Time (less is better)for JPA infrastructure@Configuration@EnableJpaRepositories(bootstrapMode = BootstrapMode.DEFERRED)class LazyJpaRepositoryConfiguration {}@BeanLocalContainerEntityManagerFactoryBean 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-examplesjpa/deferredspring.data.jpa.repositories.bootstrap-mode=
https://pixnio.com/de/landschaften/himmel/vogel-flug-tageslicht-blauer-himmel-wolke-wind-klima License: PDUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/Lazy JPA Repository Initialization12Bootstrap Time (less is better)for JPA infrastructure010203040Default Deferred Lazy@Configuration@EnableJpaRepositories(bootstrapMode = BootstrapMode.LAZY)class DeferredJpaRepositoryConfiguration {}@BeanLocalContainerEntityManagerFactoryBean entityManagerFactory(JpaVendorAdapter vendorAdapter,…ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();threadPoolTaskEx …}spring-projects/spring-data-examplesjpa/deferredHowFast is Spring? tomorrow10:30am
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/13JDBChttps://pixnio.com/de/landschaften/sonnenschein/sonnenschein-landschaft-sonnenuntergang-berg-himmel-sonne-sonnenaufgang License: PD
https://pixnio.com/de/landschaften/sonnenschein/sonnenschein-landschaft-sonnenuntergang-berg-himmel-sonne-sonnenaufgang License: PDUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/JDBC Repositories14Spring Data JDBC 2:00pm | National Harbor 4-5interface LegoSetRepository extends CrudRepository {@Query("SELECT m.name model_name, m.description, l.name set_nameFROM model m JOIN lego_set l ON m.lego_set = l.idWHERE :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-examplesjdbc/basic
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/15R2DBCsneak peekhttps://pixnio.com/de/landschaften/narrows-landschaft/wasserfall-hohle-strom-wasser-natur-fluss-landschaft-stein License: PD
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-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: PDReactive Database Client16@Configurationclass ReactiveDbcConfiguration {@BeanTransactionalDatabaseClient 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-5spring-projects/spring-data-examplesjdbc/r2dbc
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/17MongoDBhttps://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten License: PD
https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten License: PDUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/MongoDB 4.0 Multi Document Transactions18@Configurationclass TransactionConfiguration {@BeanMongoTransactionManager 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-examplesmongodb/transactionsNext Generation MongoDB 3:20pm | National Harbor 4-5
https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten License: PDUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/Validators & Json Schema19Criteria 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-examplesmongodb/schema-validation
https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten License: PDUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/Distinct Queries20List 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 tabledb.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 }}
https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten License: PDUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/Change Streams21MessageListenerContainer 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-examplesmongodb/change-streams
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/22https://pixnio.com/de/tapeten/sonnenuntergang-sonne-sonnenuntergang-kugel-himmel-schneeflocke-frost-kristall-landschaft License: PDGemfire GeodeApache
https://pixnio.com/de/tapeten/sonnenuntergang-sonne-sonnenuntergang-kugel-himmel-schneeflocke-frost-kristall-landschaft License: PDUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/Spring Boot for Apache Geode and Pivotal GemfireHealth Indicators for• Cache• Disk Stores• Regions• Pools• Indexes• Event Queues• …23Spring Session SupportScaling Spring Boot Apps watch the replay!
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/24Redishttps://pixnio.com/de/landschaften/gletscher/hoehe-wolken-kaelte-frost-gletscher-eis-eisberg-winter License: PD
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-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: PDQuery By Example25class RedisRepository extends CrudRepository, QueryByExampleExecutor { }spring-projects/spring-data-examplesredis/repositoriesExample example = Example.of(new Person().withLastname("stark"));Iterable starks = repository.findAll(example);
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-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: PDWrite to Master read from Replica (aka Slave)26@Configurationclass WriteToMasterReadFromSlaveConfiguration {@Beanpublic RedisConnectionFactory connectionFactory() {LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder().readFrom(ReadFrom.SLAVE_PREFERRED).build();RedisStandaloneConfiguration serverConfig = new RedisStandaloneConfiguration("server", 6379);return new LettuceConnectionFactory(serverConfig, clientConfig);}}
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-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: PDReactive Pub/Sub27ReactiveRedisTemplate 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();connectionconnection1 connection each1 shared connectionconnection
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-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: PDReactive SCAN & Cluster SCAN28ReactiveRedisConnection connection = …Mono> keys = connection.keyCommands().keys(…);ReactiveRedisConnection connection = …Flux keys = connection.keyCommands().scan(…);Under the Hood of Reactive 3:20pm | National Harbor 4-5
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/29Cassandrahttps://pixnio.com/de/tiere/insekten-ungeziefer/spinnen/spinne-netz-zweig-falle-faden-insekt-tier License: PD
https://pixnio.com/de/tiere/insekten-ungeziefer/spinnen/spinne-netz-zweig-falle-faden-insekt-tier License: PDUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/Lifecycle Events30public class BeforeConvertListener extends AbstractCassandraEventListener {@Overridepublic void onBeforeSave(BeforeSaveEvent event) {!// does some auditing manipulation, set timestamps, whatever}}
https://pixnio.com/de/tiere/insekten-ungeziefer/spinnen/spinne-netz-zweig-falle-faden-insekt-tier License: PDUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/Fluent Template API31List result = template.query(User.class).matching(query(where("jedi").is(true))).all()
https://pixnio.com/de/tiere/insekten-ungeziefer/spinnen/spinne-netz-zweig-falle-faden-insekt-tier License: PDUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/Fluent Template API (with Kotlin)32val result = template.query().matching(query(where("jedi").isEqualTo(true))).all()
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/33Neo4jhttps://pixnio.com/de/universum/galaxy-abstrakt-astronomie-konstellation-dunkelheit License: PD
https://pixnio.com/de/universum/galaxy-abstrakt-astronomie-konstellation-dunkelheit License: PDUnless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/Neo4jHousekeeping - naming, structure, components, documentation34★ SpEL support in @Query★ Optimistic Locking using @Version★ Persistence Constructors \ö/★ Traverse relationships in derived queries
> Stay Connected.Spring Data Lovelace out now! Check it out with Boot 2.1.M4#springone@s1p6:30 pm Fitness Center Level P
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative CommonsAttribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/Safe Harbor StatementThe following is intended to outline the general direction of Pivotal's offerings. It is intended for information purposesonly 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 anymaterial, code, or functionality, and should not be relied upon in making purchasing decisions regarding Pivotal'sofferings. 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 thesole discretion of Pivotal. Pivotal has no obligation to update forward looking information in this presentation.36