SlideShare a Scribd company logo
1 of 69
NoSQL Endgame
Otávio Santana
Werner Keil
Werner Keil
Jakarta EE Specification Committee Member
Let’s meet
@emilyfhjiang
@wernerwedge
Emily Jiang
Cloud Native Architect, IBM
3
5 trends in 2023
New digital trends create new technical
challenges
@emilyfhjiang
@wernerwedge
What are these challenges?
@emilyfhjiang
@wernerwedge
• Agile development process
• High performance and availability
• Manage huge data volumes
NoSQL FTW!
Advantages of NoSQL
@emilyfhjiang
@wernerwedge
• Handles large volumes of data at high-speed
• Stores unstructured, semi-structured, or structured
data
• Easy updates to schemas and fields
• Developer-friendly
• Takes advantage of the cloud to deliver zero
downtime
Why this talk
Tons of persistence frameworks
Which one performs best for your case?
JVM can cope with heavy loads
Would normally take ages to compare
NoSQL
01 Database
02 Doesn't use (semi)structure
03 No transactions
04 BASE
Four different types
05
Key-Value stores
AmazonS3
Apollo
Ares
Aphrodite
Sun
War
Love Beauty
AmazonDynamo
Hazelcast
Redis
Column-Oriented
Apollo
Aphrodite
Ares
Kratos
Duty
Duty
Duty
Dead Gods
Love, happy
Sun
War
13
Color
weapon
Sword
Row-key Columns
HBase
Scylla
SimpleDB
Cassandra
DynamoDB
Clouddata
Document stores
{
"name":"Diana",
"duty":[
"Hunt",
"Moon",
"Nature"
],
"siblings":{
"Apollo":"brother"
}
}
ApacheCouchDB
MongoDB
Couchbase
Graph databases
Apollo Ares
Kratos
was killed by was killed by
killed killed
Neo4j
InfoGrid
Sones
HyperGraphDB
Time series
InfluxDB
KairosDB
TimescaleDB
Multi-Model
01
02
03
04
OrientDB (graph, document)
Couchbase (key value, document)
Elasticsearch (document, graph)
ArangoDB (document, graph, key-value)
SQL vs NoSQL
SQL KEY-VALUE COLUMN DOCUMENTS GRAPH
Table Bucket Column family Collection
Row Key/value pair Column Documents Vertex
Column Key/value pair Key/value pair Vertex and
Edge property
Relationship Link Edge
BASE vs ACID
• Basically Available
• Soft state
• Eventual consistency
• Atomicity
• Consistency
• Isolation
• Durability
CAP
Scalability vs Complexity
Scalability
Complexity
key-value
Column
Document
Graph
Relational Application NoSQL Application
Logic Tier Logic Tier
DAO DAO
JPA
JPA
JPA
JPA
JDBC JDBC
JDBC
JDBC
Data Tier
API
API API
Data Tier
Our comparison model
JPA problem for NoSQL
01
02
03
04
05
06
Saves Async
Async Callback
Time to Live (TTL)
Consistency Level
SQL based
Diversity in NoSQL
Annotated Entities
01
02
03
Mapped Superclass
Entity
Column
@Entity(”person")
public class Person {
@Column
private String name;
@Column
private long age;
@Column
private Set<String> powers;
}
Template
Person artemis = ...;
DocumentTemplate template = …
template.insert(artemis);
template.update(artemis);
DocumentQuery query = ...
List<Person> people = template.select(query);
Repository
interface PeopleRepository extends MongoRepository<Person, String> {
List<Person> findByNameAndAge (String name, Integer age);
}
Micronaut Data
NoSQL
Repository
@MongoRepository
interface BookRepository extends CrudRepository<Book, ObjectId> {
Book find(String title);
}
Or
@MongoRepository
public abstract class AbstractBookRepository implements CrudRepository<Book, ObjectId>
{
public abstract List<Book> findByTitle(String title);
}
Entity
@MappedEntity
public class Book {
@Id
@GeneratedValue
private ObjectId id;
private String title;
private int pages;
public Book(String title, int pages) {
this.title = title;
this.pages = pages;
}
// ...
}
Query by Text
@MongoFindQuery(filter = "{title:{$regex: :t}}", sort = "{title: 1}")
List<Book> customFind(String t);
@MongoAggregateQuery("[{$match: {name:{$regex: :t}}}, {$sort: {name: 1}}, {$project:
{name: 1}}]")
List<Person> customAggregate(String t);
@MongoUpdateQuery(filter = "{title:{$regex: :t}}", update = "{$set:{name: 'tom'}}")
List<Book> customUpdate(String t);
@MongoDeleteQuery(filter = "{title:{$regex: :t}}", collation = "{locale:'en_US',
numericOrdering:true}")
void customDelete(String t);
GORM
NoSQL
Entity
@Entity
class User {
ObjectId id
String emailAddress
String password
String fullname
Date dateCreated
Date lastUpdated
static constraints = {
emailAddress email: true
password nullable: true
fullname blank: false
}
}}
@Document(collection = ”people")
public class person { … }
interface GodRepository extends
MongoRepository<Person, String> { … }
What about the Controller?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
spring.data.mongodb.database=mythology
spring.data.mongodb.port=27017
Logistics Domain
Our example
MovieEntity
MovieRepository
PersonEntity
Roles
…
Other reactive dependencies
…
<dependency>
<groupId>org.neo4j.springframework.data</groupId>
<artifactId>spring-data-neo4j-rx-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
org.neo4j.driver.uri=bolt://localhost:7687
org.neo4j.driver.authentication.username=neo4j
org.neo4j.driver.authentication.password=secret
Logistics Domain
Repository
public interface MovieRepository extends
ReactiveNeo4jRepository<MovieEntity, String> {
Mono<MovieEntity> findOneByTitle(String title);
}
Entities
@Node("Person")
public class PersonEntity {
@Id
private final String name;
private final Integer born;
}
@Node("Movie")
public class MovieEntity {
@Id
private final String title;
@Property("tagline")
private final String description;
@Relationship(type = "ACTED_IN", direction = INCOMING)
private Map<PersonEntity, Roles> actorsAndRoles =
new HashMap<>();
@Relationship(type = "DIRECTED", direction = INCOMING)
private List<PersonEntity> directors = new ArrayList<>();
}
Relationships
@RelationshipProperties
public class Roles {
private final List<String> roles;
public Roles(List<String> roles) {
this.roles = roles;
}
}
Quarkus
NoSQL
Entity
public class Person extends PanacheMongoEntity {
public String name;
public LocalDate birthDate;
public Status status;
// return name as uppercase in the model
public String getName(){
return name.toUpperCase();
}
// store all names in lowercase in the DB
public void setName(String name){
this.name = name.toLowerCase();
}
}
Repository
@ApplicationScoped
public class PersonRepository implements
PanacheMongoRepository<Person> {
// put your custom logic here as instance methods
public Person findByName(String name){
return find("name", name).firstResult();
}
public List<Person> findAlive(){
return list("status", Status.ALIVE);
}
public void deleteLoics(){
delete("name", "Loïc");
}
}
Motivation
BaseDocument baseDocument = new BaseDocument();
baseDocument.addAttribute(name, value);
Document document = new Document();
document.append(name, value);
JsonObject jsonObject = JsonObject.create();
jsonObject.put(name, value);
ODocument document = new ODocument(“collection”);
document.field(name, value);
Make NoSQL easier
@Inject
Template template;
…
template.insert(book);
List<Book> books = template.select(Book.class)
.where("title").eq("Effective Java").list();
Entity
@Entity
public class Person{
@Id
private String id;
@Column
private String name;
@Column
private String city;
}
@Entity
public record Book(@Id String id,
@Column("title") String title,
@Column("edition") int edition){}
Entity
@Entity
public class Person{
@Id
private String id;
@Column
private String name;
@Column
private String city;
}
key value
key
key
key
value
value
value
Column Family
Graph
Document
Key Value
Template
@Inject
Template template;
...
Car ferrari =
template.insert(ferrari);
Optional<Car> car = template.find(Car.class, 1L);
List<Car> cars = template.select(Car.class).where("city").eq("Rome").result();
template.delete(Car.class).where("id").eq(1L).execute();
Optional<Car> result = template.singleResult("select * from Car where id = 1");
Templates
Template
DocumentTemplate
KeyValueTemplate
VendorTemplate VendorTemplate
GraphTemplate ColumnTemplate
Now What?
Jakarta Data is to unify the data access world!
@emilyfhjiang
@wernerwedge
https://github.com/jakartaee/data
Jakarta Data
NoSQL
JPA
Rest Client
Jakarta Data
relational
database
business
logic
repository
interface
repository
interface
Jakarta Data Provider
NoSQL
database
Jakarta Data / Jakarta
NoSQL Provider
JPA or
JDBC
Jakarta Data Key Elements
ENTITY
REPOSITY
Define methods to
perform CRUD
RESTful Service
Performing CRUD
Basic Entity and Repository
▪ DataRepository doesn’t come with any built-in methods. To further simplify…
@Inject
Products products;
…
products.save(new Product(1, "$25 gift card", 25.0f));
List<Product> found = products.findByPriceLessThan(100.0f);
@Repository
public interface Products extends DataRepository<Product, Long> {
List<Product> findByPriceLessThan(float maxPrice);
void save(Product product);
...
}
public record Product(
long id,
String name,
float price
);
entity class
key type
Basic Entity and CRUD Repository
@Inject
Products products;
…
products.save(new Product(1, "$25 gift card", 25.0f));
List<Product> found = products.findByPriceLessThan(100.0f);
@Repository
public interface Products extends CrudRepository<Product, Long> {
List<Product> findByPriceLessThan(float maxPrice);
...
}
public record Product(
long id,
String name,
float price
);
entity class
key type
save(E entity);
saveAll(Iterable<E> entities);
findAll();
findById(K id);
existsById(K id);
delete(E entity);
deleteById(K id);
...
Inherited via CrudRepository:
Pageable Repository
@Repository
public interface ProductRepository extends PageableRepository<Product, Long> {
Page<Car> findByTypeOrderByName(CarType type, Pageable pageable);
}
Name-Pattern Repository Methods
Compose your own save, findBy, deleteBy, countBy & more methods by
following precise naming conventions with reserved keywords and entity
property names within the method name.
Product[] findByNameLikeAndPriceBetween(String namePattern,
float minPrice,
float maxPrice);
find...By indicates a query returning results
And keyword separates NameLike and PriceBetween conditions
Name and Price are entity property names
Like keyword is a type of condition, requires 1 parameter
Between keyword is a type of condition, requires 2 parameters
Repository with Queries
Some queries are too complex to be defined within a method name.
@Query gives you a way to supply a query written in:
JPQL (for Jakarta Persistence-based providers)
@Repository
public interface Products extends CrudRepository<Product, Long> {
@Query("UPDATE Product o SET o.price = o.price - o.price * ?1")
int discountAll(float discountRate);
}
Named Parameters
If you prefer to use named parameters, you can do that with @Param,
@Repository
public interface Products extends CrudRepository<Product, Long> {
@Query("UPDATE Product o SET o.price = o.price - o.price * :rate")
int discountAll(@Param("rate") float discountRate);
}
Sorting of Results
Reserved keywords OrderBy, Asc, and Desc enable sorting of results.
Product[] findByNameLikeAndPriceBetweenOrderByPriceDescNameAsc(String namePattern,
float minPrice,
float maxPrice);
OrderBy keyword indicates the start of the sorting criteria
Asc keyword indicates ascending sort
Desc keyword indicates descending sort
Sorting of Results – better ways
@OrderBy(value = "price", descending = true)
@OrderBy("name")
Product[] findByNameLikeAndPriceBetween(String namePattern,
float minPrice,
float maxPrice);
Method names can get a bit lengthy, so there is also
@OrderBy annotation for sorting criteria that is known in advance
Sort parameters for dynamic sorting
Product[] findByNameLikeAndPriceBetween(String namePattern,
float minPrice,
float maxPrice,
Sort...);
found = products.findByNameLikeAndPriceBetween(namePattern, 10.00f, 20.00f,
Sort.desc("price"), Sort.asc("name"));
Without Method Name Magic?
@Filter(by = "price", op = Compare.Between)
@Filter(by = "name", fn = Function.IgnoreCase, op = Compare.Contains)
@OrderBy("price")
Product[] inPriceRange(float min, float max, String namePattern);
@Filter(by = "name")
@Update(attr = "price", op = Operation.Multiply)
boolean inflatePrice(String productName, float rate);
@Delete
@Filter(by = "reviews", op = Compare.Empty)
int removeUnreviewed();
It could be possible to define queries entirely with annotations.
• This idea was deferred to post v1.0, but Open Liberty has it working in
a prototype:
Javadoc:
https://ibm.biz/JakartaData
Limiting the Number of Results
@OrderBy("price")
Product[] findFirst10ByNameLike(String namePattern);
Sometimes you don’t want to read the entire matching dataset and only
care about the first several results.
First keyword indicates the start of the sorting criteria
10 numeric value optionally indicates how many.
When absent, only the very first result is returned.
Another way:
@OrderBy("price")
Product[] findByNameLike(String namePattern, Limit limit);
found = products.findByNameLike(namePattern, Limit.of(10));
Offset Pagination
@OrderBy("price")
@OrderBy("name")
Page<Product> findByNameLikeAndPriceBetween(String namePattern,
float minPrice,
float maxPrice,
Pageable pagination);
For large datasets, you can read data in pages, defined by the Pageable parameter,
Offset pagination is convenient to users jumping multiple pages ahead or behind.
But it’s inefficient in making the database fetch unwanted results, and
if data is modified, some results might be missed or duplicated between pages!
for (Pageable p = Pageable.ofSize(50); p != null; ) {
Page<product> page = products.findByNameLikeAndPriceBetween(pattern, 40.0f, 60.0f, p);
...
p = page.nextPageable();
}
Keyset Pagination
Reduces scenarios where results are missed or duplicated across pages.
• Entity properties that serve as the sort criteria must not be modified.
Gives the Pageable awareness of cursor position from a prior page.
• Jakarta Data provider automatically adds conditions to the query
making the previous cursor the starting point for the next page.
Can be more efficient because it does not require fetching and skipping
large numbers of results. Unwanted results never match to begin with!
Keyset Pagination Examples
@OrderBy("lastName")
@OrderBy("id")
KeysetAwarePage<Employee> findByHoursWorkedGreaterThanEqual(int minHours, Pageable pagination);
Traversing all results,
Or relative to a specific position,
for (Pageable p = Pageable.ofSize(100); p != null; ) {
KeysetAwarePage<Employee> page = employees.findByHoursWorkedGreaterThanEqual(1500, p);
...
p = page.nextPageable();
}
Pageable p = Pageable.ofSize(100).afterKeyset(employee.lastName, employee.id);
page = employees.findByHoursWorkedGreaterThanEqual(1500, p);
Order of keyset keys matches
the order of sort criteria
Keyset Pagination – How it Works
@OrderBy("lastName")
@OrderBy("firstName")
@OrderBy("id")
KeysetAwarePage<Employee> findByHoursWorkedGreaterThanEqual(int minHours, Pageable pagination);
Let’s visualize what this could look like if transformed to JPQL:
SELECT o FROM Employee o WHERE (o.hoursWorked >= ?1)
AND ( (o.lastName > ?2)
OR (o.lastName = ?2 AND o.firstName > ?3)
OR (o.lastName = ?2 AND o.firstName = ?3 AND o.id > ?4) )
pagination.getKeysetCursor()
provides the values for ?2, ?3, ?4
Jakarta Data Demo on Open Liberty
@emilyfhjiang
@wernerwedge
https://github.com/OpenLiberty/sample-jakarta-data
Demo
Entity:
CrewMember
Repository:
CrewMembers
CRUD Service
CrewService
@Inject
CrewMembers crewMembers;
…
@DELETE
@Path("/{id}")
public String remove(@PathParam("id") String id)
{
crewMembers.deleteByCrewID(id);
return "";
}
@Repository
public interface CrewMembers extends
DataRepository<CrewMember, String> {
@OrderBy("crewID")
List<CrewMember> findAll();
void deleteByCrewID(String crewID);
void save(CrewMember a);
}
@Entity
public class CrewMember {
@NotEmpty(message = "All crew members must have a name!")
private String name;
@Pattern(regexp = "(Captain|Officer|Engineer)", message =
"Crew member must be one of the listed ranks!")
private String rank;
@Id
@Pattern(regexp = "^d+$", message = "ID Number must be a
non-negative integer!")
private String crewID;
▪ GitHub repositories
▪ https://github.com/OpenLiberty/sample-jakarta-data
▪ Project page
▪ http://jnosql.org
▪ Specifications
▪ Jakarta Data: https://jakarta.ee/specifications/data/
@ wernerwedge
Links
@emilyfhjiang
• Flaticon.com
• Michael Simons
• Jean Tessier
• Teo Bais
• Nathan Rauh
• Mark Swatosh
• Otavio Santana
Credits
@emilyfhjiang
@wernerwedge
Thank You!
@emilyfhjiang
@ wernerwedge

More Related Content

What's hot

Real-time Analytics with Redis
Real-time Analytics with RedisReal-time Analytics with Redis
Real-time Analytics with RedisCihan Biyikoglu
 
Mobile game architecture on GCP
Mobile game architecture on GCPMobile game architecture on GCP
Mobile game architecture on GCP명근 최
 
EDB Failover Manager - Features and Demo
EDB Failover Manager - Features and DemoEDB Failover Manager - Features and Demo
EDB Failover Manager - Features and DemoEDB
 
Redis in Practice
Redis in PracticeRedis in Practice
Redis in PracticeNoah Davis
 
Oracle zdm Migrate Amazon RDS Oracle to Oracle Autonomous 2021 Kamalesh Ramas...
Oracle zdm Migrate Amazon RDS Oracle to Oracle Autonomous 2021 Kamalesh Ramas...Oracle zdm Migrate Amazon RDS Oracle to Oracle Autonomous 2021 Kamalesh Ramas...
Oracle zdm Migrate Amazon RDS Oracle to Oracle Autonomous 2021 Kamalesh Ramas...Kamalesh Ramasamy
 
Data Lineage with Apache Airflow using Marquez
Data Lineage with Apache Airflow using Marquez Data Lineage with Apache Airflow using Marquez
Data Lineage with Apache Airflow using Marquez Willy Lulciuc
 
Introduction to the DAOS Scale-out object store (HLRS Workshop, April 2017)
Introduction to the DAOS Scale-out object store (HLRS Workshop, April 2017)Introduction to the DAOS Scale-out object store (HLRS Workshop, April 2017)
Introduction to the DAOS Scale-out object store (HLRS Workshop, April 2017)Johann Lombardi
 
Multi-Tenant Identity and Azure Resource Governance - Identity Days 2019
Multi-Tenant Identity and Azure Resource Governance - Identity Days 2019Multi-Tenant Identity and Azure Resource Governance - Identity Days 2019
Multi-Tenant Identity and Azure Resource Governance - Identity Days 2019Marius Zaharia
 
MySQL Performance Schema in Action: the Complete Tutorial
MySQL Performance Schema in Action: the Complete TutorialMySQL Performance Schema in Action: the Complete Tutorial
MySQL Performance Schema in Action: the Complete TutorialSveta Smirnova
 
Oracle RAC 19c - the Basis for the Autonomous Database
Oracle RAC 19c - the Basis for the Autonomous DatabaseOracle RAC 19c - the Basis for the Autonomous Database
Oracle RAC 19c - the Basis for the Autonomous DatabaseMarkus Michalewicz
 
Ssd 성능시험 cubrid mysql
Ssd 성능시험 cubrid mysqlSsd 성능시험 cubrid mysql
Ssd 성능시험 cubrid mysqlswkim79
 
Database in Kubernetes: Diagnostics and Monitoring
Database in Kubernetes: Diagnostics and MonitoringDatabase in Kubernetes: Diagnostics and Monitoring
Database in Kubernetes: Diagnostics and MonitoringSveta Smirnova
 
Azure active directory
Azure active directoryAzure active directory
Azure active directoryRaju Kumar
 
MongoDB performance
MongoDB performanceMongoDB performance
MongoDB performanceMydbops
 
Getting the most out of MariaDB MaxScale
Getting the most out of MariaDB MaxScaleGetting the most out of MariaDB MaxScale
Getting the most out of MariaDB MaxScaleMariaDB plc
 
Azure Machine Learning tutorial
Azure Machine Learning tutorialAzure Machine Learning tutorial
Azure Machine Learning tutorialGiacomo Lanciano
 
Less01 architecture
Less01 architectureLess01 architecture
Less01 architectureAmit Bhalla
 

What's hot (20)

Real-time Analytics with Redis
Real-time Analytics with RedisReal-time Analytics with Redis
Real-time Analytics with Redis
 
Mobile game architecture on GCP
Mobile game architecture on GCPMobile game architecture on GCP
Mobile game architecture on GCP
 
EDB Failover Manager - Features and Demo
EDB Failover Manager - Features and DemoEDB Failover Manager - Features and Demo
EDB Failover Manager - Features and Demo
 
Redis in Practice
Redis in PracticeRedis in Practice
Redis in Practice
 
Oracle zdm Migrate Amazon RDS Oracle to Oracle Autonomous 2021 Kamalesh Ramas...
Oracle zdm Migrate Amazon RDS Oracle to Oracle Autonomous 2021 Kamalesh Ramas...Oracle zdm Migrate Amazon RDS Oracle to Oracle Autonomous 2021 Kamalesh Ramas...
Oracle zdm Migrate Amazon RDS Oracle to Oracle Autonomous 2021 Kamalesh Ramas...
 
MS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTUREMS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTURE
 
Data Lineage with Apache Airflow using Marquez
Data Lineage with Apache Airflow using Marquez Data Lineage with Apache Airflow using Marquez
Data Lineage with Apache Airflow using Marquez
 
Introduction to the DAOS Scale-out object store (HLRS Workshop, April 2017)
Introduction to the DAOS Scale-out object store (HLRS Workshop, April 2017)Introduction to the DAOS Scale-out object store (HLRS Workshop, April 2017)
Introduction to the DAOS Scale-out object store (HLRS Workshop, April 2017)
 
Multi-Tenant Identity and Azure Resource Governance - Identity Days 2019
Multi-Tenant Identity and Azure Resource Governance - Identity Days 2019Multi-Tenant Identity and Azure Resource Governance - Identity Days 2019
Multi-Tenant Identity and Azure Resource Governance - Identity Days 2019
 
MySQL Performance Schema in Action: the Complete Tutorial
MySQL Performance Schema in Action: the Complete TutorialMySQL Performance Schema in Action: the Complete Tutorial
MySQL Performance Schema in Action: the Complete Tutorial
 
Oracle RAC 19c - the Basis for the Autonomous Database
Oracle RAC 19c - the Basis for the Autonomous DatabaseOracle RAC 19c - the Basis for the Autonomous Database
Oracle RAC 19c - the Basis for the Autonomous Database
 
UML
UMLUML
UML
 
Ssd 성능시험 cubrid mysql
Ssd 성능시험 cubrid mysqlSsd 성능시험 cubrid mysql
Ssd 성능시험 cubrid mysql
 
Database in Kubernetes: Diagnostics and Monitoring
Database in Kubernetes: Diagnostics and MonitoringDatabase in Kubernetes: Diagnostics and Monitoring
Database in Kubernetes: Diagnostics and Monitoring
 
Active Directory
Active DirectoryActive Directory
Active Directory
 
Azure active directory
Azure active directoryAzure active directory
Azure active directory
 
MongoDB performance
MongoDB performanceMongoDB performance
MongoDB performance
 
Getting the most out of MariaDB MaxScale
Getting the most out of MariaDB MaxScaleGetting the most out of MariaDB MaxScale
Getting the most out of MariaDB MaxScale
 
Azure Machine Learning tutorial
Azure Machine Learning tutorialAzure Machine Learning tutorial
Azure Machine Learning tutorial
 
Less01 architecture
Less01 architectureLess01 architecture
Less01 architecture
 

Similar to NoSQL Endgame: Key Advantages of NoSQL Databases

NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020Thodoris Bais
 
NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020Thodoris Bais
 
NoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualNoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualWerner Keil
 
NoSQL, no Limits, lots of Fun!
NoSQL, no Limits, lots of Fun!NoSQL, no Limits, lots of Fun!
NoSQL, no Limits, lots of Fun!Otávio Santana
 
EclipseCon 2021 NoSQL Endgame
EclipseCon 2021 NoSQL EndgameEclipseCon 2021 NoSQL Endgame
EclipseCon 2021 NoSQL EndgameThodoris Bais
 
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)Masaki Oshikawa
 
Easy data-with-spring-data-jpa
Easy data-with-spring-data-jpaEasy data-with-spring-data-jpa
Easy data-with-spring-data-jpaStaples
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...tdc-globalcode
 
Let's talk about NoSQL Standard
Let's talk about NoSQL StandardLet's talk about NoSQL Standard
Let's talk about NoSQL StandardOtávio Santana
 
Let's talk about NoSQL Standard
Let's talk about NoSQL StandardLet's talk about NoSQL Standard
Let's talk about NoSQL StandardOtavio Santana
 
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...DicodingEvent
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Oliver Gierke
 
Intro to GraphQL on Android with Apollo DroidconNYC 2017
Intro to GraphQL on Android with Apollo DroidconNYC 2017Intro to GraphQL on Android with Apollo DroidconNYC 2017
Intro to GraphQL on Android with Apollo DroidconNYC 2017Mike Nakhimovich
 
NoSQL Endgame JCON Conference 2020
NoSQL Endgame JCON Conference 2020NoSQL Endgame JCON Conference 2020
NoSQL Endgame JCON Conference 2020Thodoris Bais
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5Mahmoud Ouf
 
Next-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNext-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNikolas Burk
 

Similar to NoSQL Endgame: Key Advantages of NoSQL Databases (20)

NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020
 
NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020
 
NoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualNoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 Virtual
 
NoSQL, no Limits, lots of Fun!
NoSQL, no Limits, lots of Fun!NoSQL, no Limits, lots of Fun!
NoSQL, no Limits, lots of Fun!
 
EclipseCon 2021 NoSQL Endgame
EclipseCon 2021 NoSQL EndgameEclipseCon 2021 NoSQL Endgame
EclipseCon 2021 NoSQL Endgame
 
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)
 
Easy data-with-spring-data-jpa
Easy data-with-spring-data-jpaEasy data-with-spring-data-jpa
Easy data-with-spring-data-jpa
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
 
Let's talk about NoSQL Standard
Let's talk about NoSQL StandardLet's talk about NoSQL Standard
Let's talk about NoSQL Standard
 
Let's talk about NoSQL Standard
Let's talk about NoSQL StandardLet's talk about NoSQL Standard
Let's talk about NoSQL Standard
 
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
Intro to GraphQL on Android with Apollo DroidconNYC 2017
Intro to GraphQL on Android with Apollo DroidconNYC 2017Intro to GraphQL on Android with Apollo DroidconNYC 2017
Intro to GraphQL on Android with Apollo DroidconNYC 2017
 
NoSQL Endgame JCON Conference 2020
NoSQL Endgame JCON Conference 2020NoSQL Endgame JCON Conference 2020
NoSQL Endgame JCON Conference 2020
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 
Spring data
Spring dataSpring data
Spring data
 
Next-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNext-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and Prisma
 

Recently uploaded

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

NoSQL Endgame: Key Advantages of NoSQL Databases

  • 2. Werner Keil Jakarta EE Specification Committee Member Let’s meet @emilyfhjiang @wernerwedge Emily Jiang Cloud Native Architect, IBM
  • 4. New digital trends create new technical challenges @emilyfhjiang @wernerwedge
  • 5. What are these challenges? @emilyfhjiang @wernerwedge • Agile development process • High performance and availability • Manage huge data volumes
  • 7. Advantages of NoSQL @emilyfhjiang @wernerwedge • Handles large volumes of data at high-speed • Stores unstructured, semi-structured, or structured data • Easy updates to schemas and fields • Developer-friendly • Takes advantage of the cloud to deliver zero downtime
  • 8. Why this talk Tons of persistence frameworks Which one performs best for your case? JVM can cope with heavy loads Would normally take ages to compare
  • 9. NoSQL 01 Database 02 Doesn't use (semi)structure 03 No transactions 04 BASE Four different types 05
  • 13. Graph databases Apollo Ares Kratos was killed by was killed by killed killed Neo4j InfoGrid Sones HyperGraphDB
  • 15. Multi-Model 01 02 03 04 OrientDB (graph, document) Couchbase (key value, document) Elasticsearch (document, graph) ArangoDB (document, graph, key-value)
  • 16. SQL vs NoSQL SQL KEY-VALUE COLUMN DOCUMENTS GRAPH Table Bucket Column family Collection Row Key/value pair Column Documents Vertex Column Key/value pair Key/value pair Vertex and Edge property Relationship Link Edge
  • 17. BASE vs ACID • Basically Available • Soft state • Eventual consistency • Atomicity • Consistency • Isolation • Durability
  • 18. CAP
  • 20. Relational Application NoSQL Application Logic Tier Logic Tier DAO DAO JPA JPA JPA JPA JDBC JDBC JDBC JDBC Data Tier API API API Data Tier
  • 22. JPA problem for NoSQL 01 02 03 04 05 06 Saves Async Async Callback Time to Live (TTL) Consistency Level SQL based Diversity in NoSQL
  • 23. Annotated Entities 01 02 03 Mapped Superclass Entity Column @Entity(”person") public class Person { @Column private String name; @Column private long age; @Column private Set<String> powers; }
  • 24. Template Person artemis = ...; DocumentTemplate template = … template.insert(artemis); template.update(artemis); DocumentQuery query = ... List<Person> people = template.select(query);
  • 25. Repository interface PeopleRepository extends MongoRepository<Person, String> { List<Person> findByNameAndAge (String name, Integer age); }
  • 27. Repository @MongoRepository interface BookRepository extends CrudRepository<Book, ObjectId> { Book find(String title); } Or @MongoRepository public abstract class AbstractBookRepository implements CrudRepository<Book, ObjectId> { public abstract List<Book> findByTitle(String title); }
  • 28. Entity @MappedEntity public class Book { @Id @GeneratedValue private ObjectId id; private String title; private int pages; public Book(String title, int pages) { this.title = title; this.pages = pages; } // ... }
  • 29. Query by Text @MongoFindQuery(filter = "{title:{$regex: :t}}", sort = "{title: 1}") List<Book> customFind(String t); @MongoAggregateQuery("[{$match: {name:{$regex: :t}}}, {$sort: {name: 1}}, {$project: {name: 1}}]") List<Person> customAggregate(String t); @MongoUpdateQuery(filter = "{title:{$regex: :t}}", update = "{$set:{name: 'tom'}}") List<Book> customUpdate(String t); @MongoDeleteQuery(filter = "{title:{$regex: :t}}", collation = "{locale:'en_US', numericOrdering:true}") void customDelete(String t);
  • 31. Entity @Entity class User { ObjectId id String emailAddress String password String fullname Date dateCreated Date lastUpdated static constraints = { emailAddress email: true password nullable: true fullname blank: false } }}
  • 32. @Document(collection = ”people") public class person { … } interface GodRepository extends MongoRepository<Person, String> { … } What about the Controller? <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> spring.data.mongodb.database=mythology spring.data.mongodb.port=27017 Logistics Domain
  • 35. Repository public interface MovieRepository extends ReactiveNeo4jRepository<MovieEntity, String> { Mono<MovieEntity> findOneByTitle(String title); }
  • 36. Entities @Node("Person") public class PersonEntity { @Id private final String name; private final Integer born; } @Node("Movie") public class MovieEntity { @Id private final String title; @Property("tagline") private final String description; @Relationship(type = "ACTED_IN", direction = INCOMING) private Map<PersonEntity, Roles> actorsAndRoles = new HashMap<>(); @Relationship(type = "DIRECTED", direction = INCOMING) private List<PersonEntity> directors = new ArrayList<>(); }
  • 37. Relationships @RelationshipProperties public class Roles { private final List<String> roles; public Roles(List<String> roles) { this.roles = roles; } }
  • 39. Entity public class Person extends PanacheMongoEntity { public String name; public LocalDate birthDate; public Status status; // return name as uppercase in the model public String getName(){ return name.toUpperCase(); } // store all names in lowercase in the DB public void setName(String name){ this.name = name.toLowerCase(); } }
  • 40. Repository @ApplicationScoped public class PersonRepository implements PanacheMongoRepository<Person> { // put your custom logic here as instance methods public Person findByName(String name){ return find("name", name).firstResult(); } public List<Person> findAlive(){ return list("status", Status.ALIVE); } public void deleteLoics(){ delete("name", "Loïc"); } }
  • 41. Motivation BaseDocument baseDocument = new BaseDocument(); baseDocument.addAttribute(name, value); Document document = new Document(); document.append(name, value); JsonObject jsonObject = JsonObject.create(); jsonObject.put(name, value); ODocument document = new ODocument(“collection”); document.field(name, value);
  • 42. Make NoSQL easier @Inject Template template; … template.insert(book); List<Book> books = template.select(Book.class) .where("title").eq("Effective Java").list();
  • 43. Entity @Entity public class Person{ @Id private String id; @Column private String name; @Column private String city; } @Entity public record Book(@Id String id, @Column("title") String title, @Column("edition") int edition){}
  • 44. Entity @Entity public class Person{ @Id private String id; @Column private String name; @Column private String city; } key value key key key value value value Column Family Graph Document Key Value
  • 45. Template @Inject Template template; ... Car ferrari = template.insert(ferrari); Optional<Car> car = template.find(Car.class, 1L); List<Car> cars = template.select(Car.class).where("city").eq("Rome").result(); template.delete(Car.class).where("id").eq(1L).execute(); Optional<Car> result = template.singleResult("select * from Car where id = 1");
  • 47. Now What? Jakarta Data is to unify the data access world! @emilyfhjiang @wernerwedge https://github.com/jakartaee/data
  • 49. Jakarta Data relational database business logic repository interface repository interface Jakarta Data Provider NoSQL database Jakarta Data / Jakarta NoSQL Provider JPA or JDBC
  • 50. Jakarta Data Key Elements ENTITY REPOSITY Define methods to perform CRUD RESTful Service Performing CRUD
  • 51. Basic Entity and Repository ▪ DataRepository doesn’t come with any built-in methods. To further simplify… @Inject Products products; … products.save(new Product(1, "$25 gift card", 25.0f)); List<Product> found = products.findByPriceLessThan(100.0f); @Repository public interface Products extends DataRepository<Product, Long> { List<Product> findByPriceLessThan(float maxPrice); void save(Product product); ... } public record Product( long id, String name, float price ); entity class key type
  • 52. Basic Entity and CRUD Repository @Inject Products products; … products.save(new Product(1, "$25 gift card", 25.0f)); List<Product> found = products.findByPriceLessThan(100.0f); @Repository public interface Products extends CrudRepository<Product, Long> { List<Product> findByPriceLessThan(float maxPrice); ... } public record Product( long id, String name, float price ); entity class key type save(E entity); saveAll(Iterable<E> entities); findAll(); findById(K id); existsById(K id); delete(E entity); deleteById(K id); ... Inherited via CrudRepository:
  • 53. Pageable Repository @Repository public interface ProductRepository extends PageableRepository<Product, Long> { Page<Car> findByTypeOrderByName(CarType type, Pageable pageable); }
  • 54. Name-Pattern Repository Methods Compose your own save, findBy, deleteBy, countBy & more methods by following precise naming conventions with reserved keywords and entity property names within the method name. Product[] findByNameLikeAndPriceBetween(String namePattern, float minPrice, float maxPrice); find...By indicates a query returning results And keyword separates NameLike and PriceBetween conditions Name and Price are entity property names Like keyword is a type of condition, requires 1 parameter Between keyword is a type of condition, requires 2 parameters
  • 55. Repository with Queries Some queries are too complex to be defined within a method name. @Query gives you a way to supply a query written in: JPQL (for Jakarta Persistence-based providers) @Repository public interface Products extends CrudRepository<Product, Long> { @Query("UPDATE Product o SET o.price = o.price - o.price * ?1") int discountAll(float discountRate); }
  • 56. Named Parameters If you prefer to use named parameters, you can do that with @Param, @Repository public interface Products extends CrudRepository<Product, Long> { @Query("UPDATE Product o SET o.price = o.price - o.price * :rate") int discountAll(@Param("rate") float discountRate); }
  • 57. Sorting of Results Reserved keywords OrderBy, Asc, and Desc enable sorting of results. Product[] findByNameLikeAndPriceBetweenOrderByPriceDescNameAsc(String namePattern, float minPrice, float maxPrice); OrderBy keyword indicates the start of the sorting criteria Asc keyword indicates ascending sort Desc keyword indicates descending sort
  • 58. Sorting of Results – better ways @OrderBy(value = "price", descending = true) @OrderBy("name") Product[] findByNameLikeAndPriceBetween(String namePattern, float minPrice, float maxPrice); Method names can get a bit lengthy, so there is also @OrderBy annotation for sorting criteria that is known in advance Sort parameters for dynamic sorting Product[] findByNameLikeAndPriceBetween(String namePattern, float minPrice, float maxPrice, Sort...); found = products.findByNameLikeAndPriceBetween(namePattern, 10.00f, 20.00f, Sort.desc("price"), Sort.asc("name"));
  • 59. Without Method Name Magic? @Filter(by = "price", op = Compare.Between) @Filter(by = "name", fn = Function.IgnoreCase, op = Compare.Contains) @OrderBy("price") Product[] inPriceRange(float min, float max, String namePattern); @Filter(by = "name") @Update(attr = "price", op = Operation.Multiply) boolean inflatePrice(String productName, float rate); @Delete @Filter(by = "reviews", op = Compare.Empty) int removeUnreviewed(); It could be possible to define queries entirely with annotations. • This idea was deferred to post v1.0, but Open Liberty has it working in a prototype: Javadoc: https://ibm.biz/JakartaData
  • 60. Limiting the Number of Results @OrderBy("price") Product[] findFirst10ByNameLike(String namePattern); Sometimes you don’t want to read the entire matching dataset and only care about the first several results. First keyword indicates the start of the sorting criteria 10 numeric value optionally indicates how many. When absent, only the very first result is returned. Another way: @OrderBy("price") Product[] findByNameLike(String namePattern, Limit limit); found = products.findByNameLike(namePattern, Limit.of(10));
  • 61. Offset Pagination @OrderBy("price") @OrderBy("name") Page<Product> findByNameLikeAndPriceBetween(String namePattern, float minPrice, float maxPrice, Pageable pagination); For large datasets, you can read data in pages, defined by the Pageable parameter, Offset pagination is convenient to users jumping multiple pages ahead or behind. But it’s inefficient in making the database fetch unwanted results, and if data is modified, some results might be missed or duplicated between pages! for (Pageable p = Pageable.ofSize(50); p != null; ) { Page<product> page = products.findByNameLikeAndPriceBetween(pattern, 40.0f, 60.0f, p); ... p = page.nextPageable(); }
  • 62. Keyset Pagination Reduces scenarios where results are missed or duplicated across pages. • Entity properties that serve as the sort criteria must not be modified. Gives the Pageable awareness of cursor position from a prior page. • Jakarta Data provider automatically adds conditions to the query making the previous cursor the starting point for the next page. Can be more efficient because it does not require fetching and skipping large numbers of results. Unwanted results never match to begin with!
  • 63. Keyset Pagination Examples @OrderBy("lastName") @OrderBy("id") KeysetAwarePage<Employee> findByHoursWorkedGreaterThanEqual(int minHours, Pageable pagination); Traversing all results, Or relative to a specific position, for (Pageable p = Pageable.ofSize(100); p != null; ) { KeysetAwarePage<Employee> page = employees.findByHoursWorkedGreaterThanEqual(1500, p); ... p = page.nextPageable(); } Pageable p = Pageable.ofSize(100).afterKeyset(employee.lastName, employee.id); page = employees.findByHoursWorkedGreaterThanEqual(1500, p); Order of keyset keys matches the order of sort criteria
  • 64. Keyset Pagination – How it Works @OrderBy("lastName") @OrderBy("firstName") @OrderBy("id") KeysetAwarePage<Employee> findByHoursWorkedGreaterThanEqual(int minHours, Pageable pagination); Let’s visualize what this could look like if transformed to JPQL: SELECT o FROM Employee o WHERE (o.hoursWorked >= ?1) AND ( (o.lastName > ?2) OR (o.lastName = ?2 AND o.firstName > ?3) OR (o.lastName = ?2 AND o.firstName = ?3 AND o.id > ?4) ) pagination.getKeysetCursor() provides the values for ?2, ?3, ?4
  • 65. Jakarta Data Demo on Open Liberty @emilyfhjiang @wernerwedge https://github.com/OpenLiberty/sample-jakarta-data
  • 66. Demo Entity: CrewMember Repository: CrewMembers CRUD Service CrewService @Inject CrewMembers crewMembers; … @DELETE @Path("/{id}") public String remove(@PathParam("id") String id) { crewMembers.deleteByCrewID(id); return ""; } @Repository public interface CrewMembers extends DataRepository<CrewMember, String> { @OrderBy("crewID") List<CrewMember> findAll(); void deleteByCrewID(String crewID); void save(CrewMember a); } @Entity public class CrewMember { @NotEmpty(message = "All crew members must have a name!") private String name; @Pattern(regexp = "(Captain|Officer|Engineer)", message = "Crew member must be one of the listed ranks!") private String rank; @Id @Pattern(regexp = "^d+$", message = "ID Number must be a non-negative integer!") private String crewID;
  • 67. ▪ GitHub repositories ▪ https://github.com/OpenLiberty/sample-jakarta-data ▪ Project page ▪ http://jnosql.org ▪ Specifications ▪ Jakarta Data: https://jakarta.ee/specifications/data/ @ wernerwedge Links @emilyfhjiang
  • 68. • Flaticon.com • Michael Simons • Jean Tessier • Teo Bais • Nathan Rauh • Mark Swatosh • Otavio Santana Credits @emilyfhjiang @wernerwedge