Skip to content

Latest commit

 

History

History
92 lines (68 loc) · 3.61 KB

introduction.adoc

File metadata and controls

92 lines (68 loc) · 3.61 KB

Introduction

One Mapping API, Multiple Databases

Jakarta NoSQL is a Java framework that streamlines the integration of Java applications with NoSQL databases.

However, it uses the same annotations to map Java objects. Therefore, with just these annotations, whose names match those from the Jakarta Persistence specification, there is support for more than twenty NoSQL databases.

@Entity
public class Deity {

    @Id
    private String id;

    @Column
    private String name;

    @Column
    private String power;
 //...
}

Developers must consider vendor lock-in and low cognitive load when choosing a NoSQL database for their applications. For example, if there is a need to switch out a database, considerations include the time spent on the change; the learning curve of a new database API; the code that will be lost; the persistence layer that needs to be replaced, etc. Jakarta NoSQL avoids most of these issues through the Mapping API.

Jakarta NoSQL also provides template classes that apply the Template Method design pattern to all database operations.

Beyond Jakarta Persistence (JPA)

The Jakarta Persistence specification is an excellent API for object-relational mapping and has established itself as a Jakarta EE standard. It would be ideal to use the same API for both SQL and NoSQL, but there are behaviors in NoSQL that SQL does not cover, such as time-to-live and asynchronous operations. Jakarta Persistence was simply not designed to handle those features.

ColumnTemplate template = // instance; a template to document NoSQL operations
Deity diana = Deity.builder()
        .withId("diana")
        .withName("Diana")
        .withPower("hunt")
        .build();

Duration ttl = Duration.ofSeconds(1);
template.insert(diana, ttl);

A Fluent API

Jakarta NoSQL is a fluent API for Java developers to more easily create queries that either retrieve or delete information in a Document database type. For example:

DocumentTemplate template = // instance; a template to document NoSQL operations
Deity diana = Deity.builder()
        .withId("diana")
        .withName("Diana")
        .withPower("hunt")
        .build();

template.insert(diana);// insert an entity

List<Deity> deities = template.select(Deity.class)
        .where("name")
        .eq("Diana").result(); // SELECT Deity WHERE name equals “Diana”

template.delete(Deity.class).where("name")
        .eq("Diana").execute();

Key Features

  • Simple APIs that support all well-known NoSQL storage types: Key-Value, Column Family, Document databases

  • Use of Convention Over Configuration

  • Easy-to-implement API Specification and Technology Compatibility Kit (TCK) for NoSQL Vendors

  • The APIs focus is on simplicity and ease-of-use. Developers should only have to know a minimal set of artifacts to work with Jakarta NoSQL.