DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Navigating NoSQL: A Pragmatic Approach for Java Developers
  • Eclipse JNoSQL 1.0.0: Streamlining Java and NoSQL Integration With New Features and Bug Fixes
  • Jakarta NoSQL 1.0.0-b5: How To Make Your Life Easier Around Enterprise Java and NoSQL Databases
  • Introducing Graph Concepts in Java With Eclipse JNoSQL

Trending

  • Enforcing Architecture With ArchUnit in Java
  • Tired of Spring Overhead? Try Dropwizard for Your Next Java Microservice
  • Using Python Libraries in Java
  • The Smart Way to Talk to Your Database: Why Hybrid API + NL2SQL Wins
  1. DZone
  2. Data Engineering
  3. Databases
  4. Simplify NoSQL Database Integration in Java With Eclipse JNoSQL 1.1.3

Simplify NoSQL Database Integration in Java With Eclipse JNoSQL 1.1.3

Eclipse JNoSQL 1.1.3 simplifies NoSQL for Java with enhanced Redis, ArangoDB, Oracle NoSQL, and more. Easily switch databases using Jakarta specs.

By 
Otavio Santana user avatar
Otavio Santana
DZone Core CORE ·
Dec. 03, 24 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
6.6K Views

Join the DZone community and get the full member experience.

Join For Free

NoSQL databases have become a cornerstone of modern application development, offering scalability and flexibility for handling diverse data types. However, for many Java developers, integrating with NoSQL databases can be complex and time-consuming. This is where Eclipse JNoSQL comes in, providing a seamless and standardized way to connect your Java applications to various NoSQL databases.

This article explores how Eclipse JNoSQL 1.1.3 simplifies database integration, enhances developer productivity, and offers flexibility across different databases. We’ll also walk you through a practical example using Quarkus and ArangoDB to demonstrate its features.

Why Java Developers Should Care About Eclipse JNoSQL

For many developers, working with NoSQL databases involves learning database-specific APIs, which can lead to fragmented, non-portable code. Eclipse JNoSQL eliminates these challenges by offering:

  • Ease of Use: With intuitive annotations like @Entity, @Id, and @Column, you can map Java objects to NoSQL collections in seconds.
  • Flexibility: Switch between NoSQL databases (e.g., Redis, MongoDB, ArangoDB, Oracle NoSQL) without changing your application code.
  • Standards Compliance: Implements the Jakarta Data and Jakarta NoSQL specifications, ensuring a future-proof, portable solution.
  • Integration-Ready: Works seamlessly with Jakarta EE and MicroProfile components, leveraging CDI for dependency injection and configuration management.

What’s New in Eclipse JNoSQL 1.1.3

Eclipse JNoSQL has just released version 1.1.3, bringing new features, bug fixes, and performance improvements to its already robust ecosystem. This release is a significant milestone in smoothing Java developers’ interactions with NoSQL databases. In this article, we’ll explore the goals of Eclipse JNoSQL and the new features introduced in this version and provide a practical example of how to use it with Quarkus and ArangoDB.

Eclipse JNoSQL aims to simplify the integration of Java applications with NoSQL databases by providing a unified API and architecture. By adhering to Jakarta EE specifications, JNoSQL empowers developers to work seamlessly with various NoSQL databases — be they key-value, document, graph, or column-family databases.

  • Interoperability: This abstraction abstracts database-specific complexities, making it easy to switch between databases like MongoDB, Redis, ArangoDB, and Oracle NoSQL.
  • Specification-Driven: Implements Jakarta Data and Jakarta NoSQL specifications, offering a standardized way to work with NoSQL databases.
  • Integration with Java Ecosystem: Leverages CDI for dependency injection and Eclipse MicroProfile for configuration, ensuring compatibility with modern Java frameworks like Quarkus and Spring Boot.

Limitations and Considerations for Eclipse JNoSQL

While Eclipse JNoSQL provides significant benefits for NoSQL database integration, it's essential to consider a few drawbacks:

  1. Learning Curve for New Standards: Developers unfamiliar with Jakarta EE or MicroProfile may need time to understand and adapt to the specifications and APIs used by JNoSQL.
  2. Database-Specific Features: While JNoSQL abstracts common NoSQL operations, it may not fully support advanced, database-specific capabilities without additional customization.
  3. Community and Ecosystem: As a relatively specialized tool, its ecosystem and community support are smaller than broader Java frameworks like Hibernate or Spring Data.
  4. Performance Tuning: Generalized APIs may introduce a slight performance overhead compared to native, database-specific libraries, especially for high-performance applications.

Understanding these limitations helps developers make informed decisions and consider where JNoSQL best fits their projects.

Jakarta EE Specifications Supported By Eclipse JNoSQL

Eclipse JNoSQL supports Jakarta Data and Jakarta NoSQL, two critical specifications in the Jakarta EE ecosystem.

Jakarta Data 

It provides a standard API for accessing and managing data repositories, enabling developers to perform CRUD operations easily. It focuses on simplifying pagination, sorting, and dynamic queries.

Jakarta NoSQL 

It defines a uniform API for NoSQL database interactions. It provides annotations like @Entity, @Id, and @Column for mapping Java classes to NoSQL collections and simplifying database operations.

These specifications reduce boilerplate code and promote portability across databases, making them essential for Java developers.

The latest release, version 1.1.3, focuses on improving reliability, security, and performance while introducing exciting new features:

  • Redis: Enhanced support for Redis Sentinel for improved availability.
  • ArangoDB: Security and key management updates.
  • Oracle NoSQL: New credentials options for better integration.
  • JNoSQL Lite: Added support for recording, improving traceability.
  • Driver Updates: Improved drivers for various NoSQL databases.
  • CDI Lite: Now it has support for Java record

To showcase the power of Eclipse JNoSQL 1.1.3, we’ll create a Quarkus application that manages “Goals” using ArangoDB. Thanks to the Jakarta EE specifications, switching to other NoSQL databases like MongoDB or Oracle NoSQL can be done with minimal changes.

Step-by-Step

Step 1: Setting Up Quarkus

Start your Quarkus project using the Quarkus Starter UI, selecting the following extensions:

  • REST
  • JSON
  • ARC (CDI Lite)
  • ArangoDB Driver

Your pom.xml Should include:

XML
 
<dependencies>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-rest-jsonb</artifactId>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-arc</artifactId>
    </dependency>
    <dependency>
        <groupId>io.quarkiverse.jnosql</groupId>
        <artifactId>quarkus-jnosql-document-arangodb</artifactId>
        <version>3.3.2</version>
    </dependency>
    <!-- Test dependencies -->
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-junit5</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>


Step 2: Implementing Database Connectivity

Set your database connection in application.properties:

Properties files
 
jnosql.arangodb.host=localhost:8529
jnosql.document.database=goals
jnosql.keyvalue.database=goals


Run an ArangoDB instance locally using Docker:

Shell
 
docker run -e ARANGO_NO_AUTH=1 -d --name arangodb-instance -p 8529:8529 -d arangodb/arangodb


Create a database named goals and a collection Goal in the ArangoDB web UI.

Step 3: Modeling Your Data

Use Java’s record feature with CDI Lite:

Java
 
import jakarta.json.bind.annotation.JsonbProperty;
import jakarta.json.bind.annotation.JsonbPropertyOrder;
import jakarta.nosql.Column;
import jakarta.nosql.Entity;
import jakarta.nosql.Id;

import java.util.List;

@JsonbPropertyOrder({"id", "title", "description", "priority", "tasks"})
@Entity
public record Goal(
        @Id @JsonbProperty("id") String id,
        @JsonbProperty("title") @Column String title,
        @JsonbProperty("description") @Column String description,
        @JsonbProperty("priority") @Column int priority,
        @JsonbProperty("tasks") @Column List<String> tasks) {}


Step 4: Setting Up a Repository

Define a repository using Jakarta Data:

Java
 
@Repository
public interface NewYearWishes extends BasicRepository<Goal, String> {}


Step 5: Implementing a Service Layer

Create a service layer to manage business logic:

Java
 
@ApplicationScoped
public class GoalService {

    private final NewYearWishes newYearWishes;

    @Inject
    public GoalService(@Database(DatabaseType.DOCUMENT) NewYearWishes newYearWishes) {
        this.newYearWishes = newYearWishes;
    }

    public List<Goal> findGoals(int page, int size) {
        PageRequest pageRequest = PageRequest.ofPage(page).size(size);
        return newYearWishes.findAll(pageRequest, Order.by(Sort.asc("priority"))).content();
    }

    public Goal save(Goal goal) {
        return newYearWishes.save(goal);
    }

    public Optional<Goal> findById(String id) {
        return newYearWishes.findById(id);
    }
}


Step 6: Creating REST Endpoints

Define a REST resource:

Java
 
@Path("/goals")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class GoalResource {

    private final GoalService goalService;

    @Inject
    public GoalResource(GoalService goalService) {
        this.goalService = goalService;
    }

    @GET
    public List<Goal> goals(@QueryParam("page") int page, @QueryParam("size") int size) {
        return goalService.findGoals(page, size);
    }

    @POST
    public Goal create(Goal goal) {
        return goalService.save(goal);
    }

    @GET
    @Path("{id}")
    public Goal findById(@PathParam("id") String id) {
        return goalService.findById(id).orElseThrow(() -> new WebApplicationException("Goal not found", 404));
    }
}


Step 7: Testing the Application

Here’s how to test your application using curl:

Shell
 
curl -X POST -H "Content-Type: application/json" \
-d '{
      "title": "Learn JNoSQL",
      "description": "Master NoSQL with JNoSQL",
      "priority": 1,
      "tasks": ["Read documentation", "Write sample code"]
    }' \
http://localhost:8080/goals

curl -X POST -H "Content-Type: application/json" \
-d '{
      "title": "Get Fit",
      "description": "Adopt a healthier lifestyle",
      "priority": 2,
      "tasks": ["Exercise daily", "Eat balanced meals", "Stay hydrated"]
    }' \
http://localhost:8080/goals

curl -X POST -H "Content-Type: application/json" \
-d '{
      "title": "Learn Quarkus",
      "description": "Explore Quarkus framework features",
      "priority": 3,
      "tasks": ["Set up Quarkus", "Create REST endpoints", "Integrate JNoSQL"]
    }' \
http://localhost:8080/goals


List Goals:

Shell
 
curl http://localhost:8080/goals?page=1&size=10


Conclusion

Eclipse JNoSQL 1.1.3 showcases its commitment to making NoSQL database interactions seamless for Java developers. Enhanced features and integration capabilities empower developers to build flexible and scalable applications. For more details, check out the complete example on GitHub.

Database Eclipse NoSQL Java (programming language) Integration

Opinions expressed by DZone contributors are their own.

Related

  • Navigating NoSQL: A Pragmatic Approach for Java Developers
  • Eclipse JNoSQL 1.0.0: Streamlining Java and NoSQL Integration With New Features and Bug Fixes
  • Jakarta NoSQL 1.0.0-b5: How To Make Your Life Easier Around Enterprise Java and NoSQL Databases
  • Introducing Graph Concepts in Java With Eclipse JNoSQL

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!