Modern Persistence with Spring Data 3

VMware Tanzu
VMware TanzuVMware Tanzu
│©2022 VMware, Inc.
Modern Persistence
With Spring Data 3
People Standing on Platform of a Subway Station - Niklas Jeromin - https://www.pexels.com/
Baseline
Java 17
Framework 6
Jakarta EE 9
Baseline
Framework 6
/*
* Extend Future with the capability to accept completion callbacks.
* @deprecated as of 6.0, in favor of CompletableFuture
*/
@Deprecated(since = "6.0")
public interface ListenableFuture<T> extends Future<T> { ... }
future.addCallback(
it -> { ... },
exception -> { ... }
);
future.whenComplete(
(it, exception) -> { ... }
);
Minimum Baseline
Java 17
Framework 6
Jakarta EE 9
/*
* Extend Future with the capability to accept completion callbacks.
* @deprecated as of 6.0, in favor of CompletableFuture
*/
@Deprecated(since = "6.0")
public interface ListenableFuture<T> extends Future<T> { ... }
future.addCallback(it -> { ... }, exception -> { ... });
future.whenComplete((it, exception) -> { ... });
RxJava1 & RxJava2 support
discontinued
import io.reactivex.Maybe;
interface RxPersonRepository extends RxJava2CrudRepository {
Maybe<Person> findPersonById(Long id);
}
import io.reactivex.rxjava3.core.Maybe;
interface RxPersonRepository extends RxJava3CrudRepository {
Maybe<Person> findPersonById(Long id);
}
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
Baseline
Jakarte EE 9
-Drewrite.activeRecipes=org.openrewrite.java.migrate.JavaxMigrationToJakarta
$> java -jar spring-boot-migrator.jar
jee-project:> apply initialize-spring-boot-migration
SBM
$> find * -name '*.java' | xargs perl -pi -e "s/javax.persistence./jakarta.persistence./g"
Bash
OSS Support
extended
In October 2022, the Apache Geode project failed to secure at
least three voting members on the PMC required to maintain
and manage the Apache Geode Project, after which it was
moved to the foundations Attic.
Spring Data for Apache Geode
discontinued
Spring Data for Apache Geode
digital mixer, public domain cc0 - https://www.rawpixel.com/image/5920690
Modern Persistence with Spring Data 3
Modern Persistence with Spring Data 3
jar
native - image
Modern Persistence with Spring Data 3
@Bean
public MongoManagedTypes managedTypes() {
return MongoManagedTypes.from(Customer.class, Order.class);
}
From Spring Native to Boot 3
Thursday, Jan 26 ‘23
Modern Persistence with Spring Data 3
Micrometer
integtration
Apache Cassandra
MongoDB
Redis
Traces Metrics
Logs
Observability of Your Application
Wednesday, Jan 25 ‘23
Modern Persistence with Spring Data 3
management.metrics.mongo.command.enabled=false
Observability
Data MongoDB
< 3.1
@SpringBootApplication
public class SpringDataMongodbObservabilityApplication {
@Bean
CommandLineRunner initDatabase(EmployeeRepository repository, ObservationRegistry registry) {
// ...
}
@Bean
MongoClientSettingsBuilderCustomizer mongoContextProvider(ObservationRegistry registry) {
return (clientSettingsBuilder) ->
clientSettingsBuilder.contextProvider(ContextProviderFactory.create(registry))
.addCommandListener(new MongoObservationCommandListener(registry));
}
}
Observability
Data MongoDB
@SpringBootApplication
public class SpringDataMongodbObservabilityApplication {
@Bean
CommandLineRunner initDatabase(EmployeeRepository repository, ObservationRegistry registry) {
return args -> {
Observation.createNotStarted("init-database", registry).observe(() -> {
repository.save(new Employee("Frodo", "ring bearer"));
repository.save(new Employee("Bilbo", "burglar"));
});
};
}
@Bean
MongoClientSettingsBuilderCustomizer mongoContextProvider(ObservationRegistry registry) {
return (clientSettingsBuilder) ->
clientSettingsBuilder.contextProvider(ContextProviderFactory.create(registry))
.addCommandListener(new MongoObservationCommandListener(registry));
}
}
Observability
Data MongoDB
Modern Persistence with Spring Data 3
Data JPA
@Query(value = "select u.* from User u", queryRewriter = TenantQRW.class)
List<User> findUsers(Pageable pageable);
static class TenantQRW implements QueryRewriter {
@Override
public String rewrite(String query, Sort sort) {
return query + " WHERE u.tenantId = " + context.getTenantId();
}
}
Data JPA
Query Rewriter
Data JDBC
@Query("SELECT * FROM person WHERE username = :#{ principal?.username }")
Person findActiveUser();
Data JDBC
SpEL Expressions
@EnableJdbcRepositories
static class AppConfiguration {
// ...
@Bean
BeforeConvertCallback<Person> idGenerator() {
return p -> p.withId(UUID.randomUUID());
}
}
Data JDBC
Lifecycle Events & Callbacks
Data JDBC
Operation Batching
A B
Data JDBC
Operation Batching
A B
Data MongoDB
template.createView("firstYears", Student.class, match(where("year").is(1)));
Data MongoDB
Views
Person existing = template.update(Person.class)
.matching(where("firstname").is("Harry"))
.apply(new Update().inc("age", 1))
.findAndModifyValue();
@Update("{ '$inc' : { 'age' : ?1 } }")
Person findAndIncrementAgeByFirstname(String firstname, int increment);
Data MongoDB
findAndModify
Data MongoDB
Aggregations
Aggregation.stage(search(exists(fieldPath("age"))));
Data MongoDB
Aggregations
spring-data
mongodb-driver
Data Redis
public class User {
@JsonView(Basic.class)
private int id;
@JsonView(Basic.class)
private String name;
@JsonView(Detailed.class)
private String email;
}
Data Redis
Object Mapping
new GenericJackson2JsonRedisSerializer(objectMapper, JacksonObjectReader.create(),
(mapper, source) -> mapper.writerWithView(Basic.class).writeValueAsBytes(source)
);
What’s next?
Single Select
queries
A
B C
⋈
naïve join
Single Select
queries
A
B C
⋈
analytic join
public class Person {
String id;
String name;
@EncryptedField(algorithm = SHA_512_Deterministic)
String ssn;
@EncryptedField(algorithm = SHA_512_Random, altKeyName = "secretKey")
String wallet;
@EncryptedField(algorithm = SHA_512_Random, altKeyName = "/name")
Address address;
}
Encryption
client side
public class Person {
String id;
String name;
@EncryptedField(algorithm = SHA_512_Deterministic)
String ssn;
@EncryptedField(algorithm = SHA_512_Random, altKeyName = "secretKey")
String wallet;
@EncryptedField(algorithm = SHA_512_Random, altKeyName = "/name")
Address address;
}
Encryption
client side
{
"_id": "ff3-4567-ee",
"name": "chris",
"ssn": {
"$binary": {
"base64": "AVpT0rwbK0P
"subType": "06"
}
},
"wallet": {
"$binary": {
"base64": "AlpT0rwbK0P
"subType": "06"
}
},
"address": {
"$binary": {
"base64": "+T3C+n4HOBF
"subType": "06"
}
},
"_class": ”example.Person"
}
Modern Persistence with Spring Data 3
1 of 43

More Related Content

More from VMware Tanzu(20)

tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptx
VMware Tanzu153 views
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - French
VMware Tanzu13 views

Recently uploaded(20)

We aint got no time - Droidcon NairobiWe aint got no time - Droidcon Nairobi
We aint got no time - Droidcon Nairobi
Danny Preussler41 views
Future Telecoms Challenges & OpportunitiesFuture Telecoms Challenges & Opportunities
Future Telecoms Challenges & Opportunities
University of Hertfordshire46 views
AI Science AI Science
AI Science
Melanie Swan33 views
9C Monthly Newsletter - NOV 20239C Monthly Newsletter - NOV 2023
9C Monthly Newsletter - NOV 2023
PublishingTeam945 views
LLM App Hacking (AVTOKYO2023)LLM App Hacking (AVTOKYO2023)
LLM App Hacking (AVTOKYO2023)
Shota Shinogi212 views
SQLSatOregon_kgorman_keynote_NIAIMLEC.pptxSQLSatOregon_kgorman_keynote_NIAIMLEC.pptx
SQLSatOregon_kgorman_keynote_NIAIMLEC.pptx
Kellyn Pot'Vin-Gorman38 views
Ontology Repositories and Semantic Artefact Catalogues with the OntoPortal Te...Ontology Repositories and Semantic Artefact Catalogues with the OntoPortal Te...
Ontology Repositories and Semantic Artefact Catalogues with the OntoPortal Te...
INRAE (MISTEA) and University of Montpellier (LIRMM)52 views
Onewheel e-skateboard recallOnewheel e-skateboard recall
Onewheel e-skateboard recall
Bisnar Chase Personal Injury Attorneys23 views
GoTech_SustainableAI_DebmalyaBiswas.pdfGoTech_SustainableAI_DebmalyaBiswas.pdf
GoTech_SustainableAI_DebmalyaBiswas.pdf
Debmalya Biswas16 views
Serverless at LifestageServerless at Lifestage
Serverless at Lifestage
BATbern16 views
SIG-NOC Tools SurveySIG-NOC Tools Survey
SIG-NOC Tools Survey
CSUC - Consorci de Serveis Universitaris de Catalunya47 views
IDEAS Products 2023IDEAS Products 2023
IDEAS Products 2023
Dirk Meier40 views

Modern Persistence with Spring Data 3