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 Aerospike Hazelcast Crate Incubating
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Working with Spring Data 8
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The Goal… “…provide a familiar and consistent Spring based programming model retaining store specific features and capabilities” (O.Gierke) 9
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Query Derivation 11 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* 12 ! ! ! } 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/ 14 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 Spring Data Fowler Java 8
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Java 8 Steams 15 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } Stream<Person> findPersonBy(); …for JPA and MongoDB @Query("select p from Person p") Stream<Person> streamAllPersons(); Always make sure to close the Stream. try (Stream<Customer> stream = repo.findPersonBy()) { //...
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Slice and Page support map 16 Page<String> page = .... Page<Integer> converted = page.map(new Converter<String, Integer>() { @Override public Integer convert(String source) { return source.length(); } }); …result transformation made easy. Page<Integer> converted = page.map(String::length); Converter is a @FunctionalInterface
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Performance tweaks 19 …getting the most out of it. ops/sec 0 600.000 1.200.000 1.800.000 2.400.000 Read Write Evans Fowler higher is better
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ And more…. § Add support for NotContaining keyword § Performance enhancements for RepositoryInterfaceAwareBeanPostProcessor. § DefaultCrudMethods now exposes accessible methods. § Introduced a Range value type § Allow transaction behavior to be configurable. 20
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JPA Fetch Graphs 23 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! ! } …also for base repository methods @EntityGraph(type = EntityGraphType.LOAD, value = "Person.overview") List<Person> findAll(); ! Person findOne(Long id); @EntityGraph(type = EntityGraphType.LOAD, value = "Person.address") @EntityGraph(attributePaths = {"roles", "colleagues.roles"}) List<Person> findAll(); More to come for Gosling
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ SpEL Enhancements 24 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! ! ! ! ! ! ! ! ! } …everything at your fingertips. @Query("..where u.email like ?#{hasRole('ROLE_ADMIN') ? '%' : principal.em...") List<BusinessObject> findBusinessObjectsForCurrentUser(); @Query("select p from #{#entityName} p where p.first = ?#{[0]} and p.last = ?#{[1]}") List<Person> findUsersWithEntityExpression(String first, String last); @Query( value = "select * from (select rownum() as RN, p.* from Person p) where RN between ?#{ #pageable.offset -1} and ?#{#pageable.offset + #pageable.pageSize}", countQuery = "select count(p.id) from Person p", nativeQuery = true) Page<Person> findAllWithNativePagination(Pageable pageable);
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ And more…. § Avoid query creation in PagedExecution if count query returns 0. § javax.persistence.Version (honored) § Allow composite keys to be used in SimpleJpaRepository.findAll(Iterable<ID>). § Added support for REF_CURSOR output parameters for stored procedures. 25
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ MongoDB 3.0 28 …driver and database compatibility D e p r e cat e d <mongo:mongo host="127.0.0.1" port="27017"> <mongo:options connections-per-host="${mongo.connectionsPerHost}" <mongo:mongo-client host="127.0.0.1" port="27017"> <mongo:client-options write-concern="NORMAL" The upcoming Gosling release will provide more sophisticated support for MongoDB 3.0 Features.
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Geospatial enhancements 29 dedicated types for GeoJSON. interface StoreRepository extends CrudRepository<Store, Long> { ! ! } List<Store> findByLocationWithin(Polygon polygon); class Store { ! String id; @GeospatialIndexed Point location; } location :[ x, y ] legacy coordinate format
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ And more…. § Explicitly annotated Field should not be considered Id. § $mul, $bit, $position for Update § $minDistance for geoNear § Containing now searches inside strings and collections. § Add support for fast insertion via MongoRepository.insert(... 34
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ HyperLogLog Support 36 …or count distinct. hllOps.add("hll2", "x", "y", "z"); hllOps.union("hll3", "hll", "hll2"); redis> PFADD hll a b c d e f g (integer) 1 redis> PFCOUNT hll (integer) 7 redis> pfadd hll2 x y z (integer) 1 redis> pfmerge hll3 hll hll2 (integer) 1 redis> pfcount hll3 (integer) 10 hllOps = redisTemplate.opsForHyperLogLog(); hllOps.add("hll", "a", "b", "c",... hllOps.size("hll");
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Gemfire 8 38 Cluster setup revised. <gfe:cache use-cluster-configuration="true" • Read Cluster Configuration from Network Locator • Keeps your members sane when joining the cluster
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ @Version based ETags 40 …as simple as it should be. class Customer { ! @Version Long version; @LastModifiedDate LocalDate lastModifiedDate; } curl -v http://…/customers/1 ! Etag: 1 Last-Modified: Tue, 24 Mar 2015 12:34:56 GMT
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Realtime Get 43 // realtime-get fetches uncommitted document template.getById(document.getId(), Document.class); …read uncommitted changes. // add document but delay commit for 3 seconds template.saveBean(document, 3000); // document will not be returned hence not yet committed to the index template.queryForObject(query, Document.class);
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Oh, wait… There’s more - sneak peak on what’s to come! 46
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Key/Value 47 …for any kind of identifiable pairs. interface KeyValueAdapter { put(id, value, keyspace) get(id, keyspace) delete(id, keyspace) } class KeyValueTemplate { } class QueryEngine { execute(query, keyspace) } interface KeyValueRepository { … } MapKeyValueAdapter available by default SpELQueryEngine use with compiled SpEL -D spring.expression.compiler.mode KeyValueTemplate(keyValueAdapter)
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Key/Value 48 …for any kind of identifiable pairs. interface PersonRepository extends CrudRepository<Person, Long> { ! } List<Person> findByAgeGreaterThan(int age); @Configuration @EnableMapRepositories class Config {} @Autowired PersonRepository repository; Person person = repository.save(new Person("Dave", "Matthews", 47)); List<Person> result = repository.findByAgeGreaterThan(18);
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Redis Cluster (outlook) 49 postponed to Gosling 0-5460 5461-10922 10923-16383 Slots: MOVED 8712 127.0.0.1:6380 key Key calculation and node assignment are part of the driver library.
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Some additional themes for Gosling (more to come!) 50 QueryDSL 4 4.1 Spring Base Redis Cluster Reactive Repositories SpEL enhancements ZRANGEBYLEX Dynamic Projections Key Value Store Support Custom Implementation 2.0 Dynamic JPA Fetch Graphs
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 51 Learn More. Stay Connected. Twitter: twitter.com/springcentral YouTube: spring.io/video LinkedIn: spring.io/linkedin Google Plus: spring.io/gplus