Module jakarta.nosql.core


module jakarta.nosql.core
Jakarta NoSQL

Jakarta NoSQL is designed specifically for Java developers who need to build scalable, database-agnostic applications using NoSQL technologies. With Jakarta NoSQL, developers can seamlessly map Java objects to NoSQL databases using familiar paradigms, enabling them to focus on business logic without worrying about database-specific implementation details.

Overview

Modern applications often require highly scalable and flexible storage solutions. NoSQL databases address these needs with their diverse data models (e.g., document, key-value, column-family, and graph). However, interacting with such databases in a type-safe, database-agnostic way has historically been challenging. Jakarta NoSQL solves this problem by offering:

  • A standard API for NoSQL database interactions.
  • Comprehensive support for mapping Java objects to NoSQL data models.
  • Seamless integration with Java frameworks and runtime environments.
Annotations

Jakarta NoSQL introduces several annotations to make it easier for Java developers to define mappings between Java objects and NoSQL databases. These include:

  • Entity: Marks a class as a NoSQL entity, representing a top-level record in the database.
  • Id: Specifies the primary key or unique identifier for an entity.
  • Column: Maps a field or property to a column or attribute in the database.
  • Convert: Specifies a custom converter for handling complex or non-standard data types.
  • Embeddable: Denotes a reusable embedded structure for entities.
  • DiscriminatorColumn and DiscriminatorValue: Enable inheritance mapping for NoSQL entities.
  • MappedSuperclass: Defines a superclass that provides shared mapping information for its subclasses.
Purpose and Advantages

Jakarta NoSQL was created with the following goals in mind:

  1. Standardization: Provide a consistent API across different NoSQL database types, enabling portability and reducing vendor lock-in.
  2. Ease of Use: Allow Java developers to interact with NoSQL databases using familiar paradigms like annotations and type-safe APIs.
  3. Flexibility: Support diverse NoSQL database models and allow developers to extend functionality through custom converters and mappings.
  4. Productivity: Reduce boilerplate code and simplify common operations like queries, updates, and object mapping.
Features
  • Object Mapping: Define how Java objects map to NoSQL database structures using annotations like @Entity, @Column, and @Id.
  • Custom Conversions: Handle complex data types with the @Convert annotation and the AttributeConverter interface.
  • Inheritance Support: Use @MappedSuperclass, @DiscriminatorColumn, and @DiscriminatorValue to model entity inheritance.
  • Seamless Integration: Integrates with Java EE/Jakarta EE environments and modern frameworks, ensuring compatibility and ease of adoption.
Example Usage

Below is an example of a typical entity using Jakarta NoSQL annotations and a simple template integration to perform basic operations:

 
 @Entity
 public class Product {

     @Id
     private String id;

     @Column
     private String name;

     @Column
     private Category category;
 }
 public enum Category {
    TECH, FOOD, CLOTHING
 }

 @Inject
 private Template template;

 public void performOperations() {
     Product product = Product.builder().id("1").name("Laptop").category(Category.TECH).build();

     // Insert operation
     template.insert(product);

     // Find operation
     Optional<Product> foundProduct = template.find(Product.class, "1");

     // Delete operation
     template.delete(Product.class, "1");

     List<Product> products = template.select(String.class).where("category").eq(Category.TECH).result();
 }
 
 
  • Packages Link icon

    Exports
    Package
    Description
    Provides classes and interfaces for integrating Java applications with various NoSQL databases.