Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What’s new in Spring Data? Christoph Strobl, Software Engineer, Pivotal Software Inc. @stroblchristoph
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Agenda 2 Overview Core Themes Store Specifics Outlook / Q&A
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Modules 5 Commons Neo4j Gemfire JPA Solr ElasticSearch REST Cassandra Couchbase Redis MongoDB Community modules Core modules
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Release train ! Similar to the eclipse release model ! Modules still versioned independently ! Single canonical name —> Evans ! Communicate compatibility between modules ! Helps to avoid confusion with versions ! Now used by Spring Boot 7
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Release train BOM <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-releasetrain</artifactId> <version>Evans-SR2</version> <scope>import</scope> <type>pom</type> </dependency> ! 8
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Working with Spring Data 10
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The Goal… “Spring Data Repositories abstraction provides a uniform interface to access data from various data stores.” 11
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Interface based programming model 12 interface PersonRepository extends Repository<Person, Long> {}
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Interface based programming model 12 interface PersonRepository extends CrudRepository<Person, Long> {}
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Interface based programming model 12 interface PersonRepository extends PagingAndSortingRepository<Person, Long> {}
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Query Derivation 13 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } List<Person> findByFirstnameAndLastname(String firstname, String lastname); @Query("select u from User u where u.firstname = ?0 and u.lastname = ?1")
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Query Derivation 13 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } Page<Person> findByFirstname(String firstname, Pageable page); List<Person> findByFirstnameAndLastname(String firstname, String lastname); @Query("select u from User u where u.firstname = ?0 and u.lastname = ?1")
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ QueryDSL Integration* 14 ! ! ! } Page<Person> findByFirstname(String firstname, Pageable page); List<Person> findByFirstnameAndLastname(String firstname, String lastname); , QueryDslPredicateExecutor { interface PersonRepository extends CrudRepository<Person, Long> @Query("select u from User u where u.firstname = ?0 and u.lastname = ?1")
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Optional<T> 18 For both Java 8 and Google Guava! interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } Optional<Person> findByLastname(String lastname); // ... personRepository.findByLastname("targaryen").orElse(johnDoe);
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Derived DeleteBy 22 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } Long deleteByLastname(String lastname); @Modifying @Transactional @Query("delete from Person p where p.lastname = ?1") void removeByLastname(String lastname); the simple alternative to @Modifying @Query
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Generic Query creation with SpEL 24 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } @Modifying @Query("update #{#entityName} p set p.active= :activeState") void updateActiveState(@Param("activeState") boolean state); use the power of Spring Expression Language
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Multi-Store configuration enhancements 25 … 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
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ And more…. ! Type safe Sort with QueryDSL ! CDI Improvements ! Common GeoSpatial Types ! Null Handling for Sort 26
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Lazy Loading DBRefs 36 class Person { ! ! } @DBRef(lazy = true) User coworker;
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Additional Query Data 37 Set timeouts, comments and more! interface PersonRepository extends CrudRepository<Person, Long> { ! ! } @Meta(comment="voxxed-days-vienna15") List<Person> findByLastnameLike(String lastname);
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Text Search 38 Simple and powerful full text search! interface PersonRepository extends CrudRepository<Person, Long> { ! ! } ! Page<Person> findAllBy(TextCriteria fullText, Pageable page);
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ SCAN Support 40 ! ScanOptions options = ScanOptions.scanOptions().count(99).build(); Cursor<String> cursor = setOperations.scan(key, options); ! while(cursor.hasNext()){ process(cursor.next()); } The non blocking alternative!
Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Redis Sentinel 41 Redis Master Redis Slave1 Redis Slave2 Sentinel Node1 Sentinel Node2 Sentinel Node3 for high availability systems!
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Schema Support ! Usage of Schema Solr REST API ! Add new fields to existing schema. 43 @Configuration @EnableSolrRepositories(schemaCreationSupport = true) class SolrConfiguration { ! //...
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Outlook Core Themes for Fowler 49
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What will Fowler be all about… 50 GemFire 8 Performance REST Projections JSR-310 Improvements MongoDB Script Execution GeoJson Support Redis HyperLogLog Solr Stats Solr Realtime Get JPA Access Type Map Backed Interfaces CDI Support for SD Cassandra GemFire AsyncEventQueues RedisCache improvements @Version support for REST