Slide 1

Slide 1 text

©2022 VMware, Inc. Persistence with Spring Data what it is and what comes next Christoph Strobl (he/him) Staff Engineer March 2022

Slide 2

Slide 2 text

©2022 VMware, Inc. 2 MongoDB Redis Elasticsearch Cassandra MariaDB DynamoDB Neo4j Couchbase CouchDB Greenplum Hazelcast H2 SQL Server Oracle Db2 Areospike OrientDB MySQL PostgreSQL ©2022 VMware, Inc.

Slide 3

Slide 3 text

©2022 VMware, Inc. 3 SELECT e FROM employee e WHERE e.firstName = :name JPA create().select().from(EMPLOYEE) .where(EMPLOYEE.FIRST_NAME).eq(name) .fetch() JOOQ db.employee.find({ first_name : name }) NoSQL SELECT * FROM employee WHERE first_name = %1 SQL MATCH (n:Employee) WHERE n.firstName = ’...’ query: { match: { first_name: '...' } }

Slide 4

Slide 4 text

©2022 VMware, Inc. 4 List findByFirstName(String name) Spring Data JPA JDBC Redis Neo4j R2DBC MongoDB ArangoDB Couchbase Cosmos DB yugabyteDB Elasticsearch Apache Geode Apache Cassandra ...

Slide 5

Slide 5 text

©2022 VMware, Inc. 5 No Magic

Slide 6

Slide 6 text

©2022 VMware, Inc. 6 Anatomy Entity Manager Database Driver Template API Mapping Conversion Resource & Transaction Management native store format <> domain type eg. enum -> string Default Implementation Repository Interface List findByFirstName(String name)

Slide 7

Slide 7 text

©2022 VMware, Inc. 7 Template APIs class MongoTemplate implements MongoOperations { List find(Query query, Class entityClass) List findAndRemove(Query query, Class entityClass) T execute(Class> entityClass, CollectionCallback callback) query(where(“firstName”).is(...)) template.execute(Employee.class, collection -> { return collection.find(new Document("firstname", "...")) .into(new ArrayList()); }); Access to native driver commands

Slide 8

Slide 8 text

©2022 VMware, Inc. 8 Repositories interface Repo extends ...{ Repository CrudRepository findAll(); findById(...) count(); save(...); delete(...); ... PagingAndSorting Repository findAll(Page); findAll(Sort); Proxy Default Implementation Store Specific List findAll(); long count(); Predefined methods List findByFirstName(String name); Derived Finder Method

Slide 9

Slide 9 text

©2022 VMware, Inc. 9 Derived Find Queries List findEmployeeByFirstNameLikeOrderByAgeAsc(String name) read get query search stream Placeholder For Anything You Like matches contains lessThan startsWith greaterThan isEmpty isNull isNotNull before after ... Match Operator Sort Direction Delimiter Employee Page Slice Stream

Slide 10

Slide 10 text

©2022 VMware, Inc. 10 Derived Count | Exists | Delete Queries int countEmployeeByFirstNameLike(String name) boolean existsEmployeeByFirstNameLike(String name) Some Stores Need a Little Help @Modifying List deleteEmployeeByFirstNameLike(String name) remove void long Interested in the Operation Result?

Slide 11

Slide 11 text

©2022 VMware, Inc. 11 Data Projections List findByFirstName(String name) Closed Interface Projection interface View2 { String getFirstName(); String getLastName(); } class View1 { String firstName; String lastName; } DTO Projection interface View3 { @Value(“#{target....}”) String getName(); } Open Interface Projection Flexible View On Your Data

Slide 12

Slide 12 text

©2022 VMware, Inc. 12 Reactive Flux findByFirstName(String name) a Reactive Stream of Data

Slide 13

Slide 13 text

©2022 VMware, Inc. 13 Not one API to rule them all

Slide 14

Slide 14 text

©2022 VMware, Inc. 14 @Entity class Employee { @Id @GeneratedValue(...) Long id; @Column(name="FIRST_N") String firstName; ... } @Document class Employee { @Id Long id; @Field(name="first_n") String firstName; ... } JPA MongoDB

Slide 15

Slide 15 text

©2022 VMware, Inc. 15 class Employee { Long id; String firstName; String lastName; Manager manager; } class Manager { Long id; String name; List employees } ID Name 1000 Marvin ID FIRST_N LAST_N MANAGER_ID 1 Ford Prefect 1000 table based manager employee linking by default { _id : 1000, name : Marvin, employees : [ { id : 1, firstName : Ford, lastName : Prefect } ... document store embedding by default

Slide 16

Slide 16 text

©2022 VMware, Inc. 16 Native Queries @Query(“SELECT m, COUNT(e) FROM Manager m JOIN m.employees e GROUP BY e.name”) List listManagerWithEmployeeCount(); JPA @Aggregation(“{ $project: { id : 1, name: 1, $size : employees } }”) List listManagerWithEmployeeCount(); MongoDB

Slide 17

Slide 17 text

©2022 VMware, Inc. 17 Richer / Slimmer API Read the Documentation for store specific features @Procedure(”Employee.increaseSalary”) Integer increaseSalary(Integer raise); JPA Stored Procedure call GeoResults findByOfficeLoactionNear(Point p, Distance max) List Stream Geospatial Query @Update(”{ ... }”) Integer findAndIncreaseSalaryByName(String name, Integer raise); MongoDB Update

Slide 18

Slide 18 text

©2022 VMware, Inc. 18 interface Repo extends Repository { ... } Custom Implementations interface MyExtension { Reward beKind(Person person); } class MyExtensionImpl implements MyExtension { ExtensionImpl(EntityManager em) { ... } public Reward beKind(Person person) { ... } } , MyExtension { repository fragment

Slide 19

Slide 19 text

©2022 VMware, Inc. 19 No Silver Bullet

Slide 20

Slide 20 text

©2022 VMware, Inc. 20 Trouble Shooting Repository Metrics Logfiles Network Stats Query Planners

Slide 21

Slide 21 text

©2022 VMware, Inc. 21 Spring Data provides a Familiar & Consistent Programming Model that resprects Store Specific Traits

Slide 22

Slide 22 text

©2022 VMware, Inc. 22 What’s next? Spring Data 2.x & 3.0 The following is intended to outline the general direction of VMware's offerings. It is intended for information purposes only and may not be incorporated into any contract. Any information regarding pre-release of VMware offerings, future updates or other planned modifications is subject to ongoing evaluation by VMware 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 VMware'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 VMware's offerings in this presentation remain at the sole discretion of VMware. VMware has no obligation to update forward looking information in this presentation

Slide 23

Slide 23 text

©2022 VMware, Inc. 23 2.x – Property Converters class Person { Long id; String name; String ssn; } @WritingConverter class PersonToDocumentConverter implements Converter { public Document convert(Person source) { ... } } @ReadingConverter class DocumentToPersonConverter implements Converter { public Person convert(Document source) { ... } }

Slide 24

Slide 24 text

©2022 VMware, Inc. 24 2.x – Property Converters class Person { Long id; String name; @ValueConverter(EncryptingValueConverter.class) String ssn; } declarative PropertyValueConverterRegistrar registrar = new ... registrar.registerConverter(Person.class, Person::getSsn) .writing(utils::encrypt) .reading(utils::decrypt); programmatic new in 2.x

Slide 25

Slide 25 text

©2022 VMware, Inc. 25 3.0 - Baseline & Upgrades • Java 17 • Jakarta EE 9 • Hibernate 6 • Validation API • CDI Extensions • ...

Slide 26

Slide 26 text

©2022 VMware, Inc. 26 3.0 - API Refinements Repository CrudRepository Iterable findAll(); Iterable saveAll(...); T findById(...) long count(); void delete(...); ... PagingAndSorting Repository Page findAll(Page); ... ListCrudRepository List findAll(); List saveAll(...); T findById(...) long count(); void delete(...); ...

Slide 27

Slide 27 text

©2022 VMware, Inc. 27 3.0 - Observability AppOptics, Azure Monitor, Netflix Atlas, CloudWatch, Datadog, Dynatrace, Elastic, Ganglia, Graphite, Humio, Influx/Telegraf, JMX, KairosDB, New Relic, Prometheus, SignalFx, Google Stackdriver, StatsD, Wavefront

Slide 28

Slide 28 text

©2022 VMware, Inc. 28 3.0 - GraalVM native • static type hints • dynamic configuration processors

Slide 29

Slide 29 text

Thank You ©2022 VMware, Inc.