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
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

Enterprise AI Trend Report: Gain insights on ethical AI, MLOps, generative AI, large language models, and much more.

2024 Cloud survey: Share your insights on microservices, containers, K8s, CI/CD, and DevOps (+ enter a $750 raffle!) for our Trend Reports.

PostgreSQL: Learn about the open-source RDBMS' advanced capabilities, core components, common commands and functions, and general DBA tasks.

AI Automation Essentials. Check out the latest Refcard on all things AI automation, including model training, data security, and more.

Related

  • Unveiling the Power of Helidon 4: A Dive Into New Features
  • Demystifying Virtual Thread Performance: Unveiling the Truth Beyond the Buzz
  • Powering Enterprise Applications: Unleashing the Java-MongoDB Synergy
  • Eclipse JNoSQL 1.0.2: Empowering Java With NoSQL Database Flexibility

Trending

  • Elevate Your Terminal Game: Hacks for a Productive Workspace
  • Enhancing Performance With Amazon Elasticache Redis: In-Depth Insights Into Cluster and Non-Cluster Modes
  • Understanding Kernel Monitoring in Windows and Linux
  • Automated Data Extraction Using ChatGPT AI: Benefits, Examples
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Unlocking the Power of Oracle NoSQL With Quarkus: Seamless Integration for Cloud-Age Applications

Unlocking the Power of Oracle NoSQL With Quarkus: Seamless Integration for Cloud-Age Applications

Learn how to integrate Oracle NoSQL with Quarkus using JNoSQL for seamless cloud-native application development. Check out the source code for hands-on exploration.

By 
Otavio Santana user avatar
Otavio Santana
DZone Core CORE ·
Feb. 26, 24 · Tutorial
Like (1)
Save
Tweet
Share
5.1K Views

Join the DZone community and get the full member experience.

Join For Free

In today’s digital landscape, the demand for scalable, high-performance databases that can seamlessly integrate with modern application frameworks is ever-growing. While reliable, traditional relational databases often need help keeping pace with the dynamic requirements of cloud-native applications. It has led to the rise of NoSQL databases, offering flexibility, scalability, and performance tailored to the demands of modern applications. This article delves into the synergy between Oracle NoSQL and Quarkus, exploring how their integration empowers Java developers to build robust, cloud-native applications efficiently.

Oracle NoSQL is a distributed key-value database designed for real-time, low-latency data processing at scale. It provides a flexible data model, allowing developers to store and retrieve data without the constraints of a fixed schema. Leveraging a distributed architecture, Oracle NoSQL ensures high availability, fault tolerance, and horizontal scalability, making it ideal for handling large volumes of data in cloud environments. With features like automatic sharding, replication, and tunable consistency levels, Oracle NoSQL offers the performance and reliability required for modern applications across various industries.

Quarkus is a Kubernetes-native Java framework tailored for GraalVM and OpenJDK HotSpot, optimized for fast startup time and low memory footprint. It embraces the principles of cloud-native development, offering seamless integration with popular containerization platforms and microservices architectures. Quarkus boosts developer productivity with its comprehensive ecosystem of extensions, enabling developers to build, test, and deploy Java applications with unparalleled efficiency. With its reactive programming model, support for imperative and reactive styles, and seamless integration with popular Java libraries, Quarkus empowers developers to create lightweight, scalable, and resilient applications for the cloud age.

Why Oracle NoSQL and Quarkus Together

Integrating Oracle NoSQL with Quarkus combines both technologies’ strengths, offering Java developers a powerful platform for building cloud-native applications. Here’s why they fit together seamlessly:

Performance and Scalability

Oracle NoSQL’s distributed architecture and Quarkus’ optimized runtime combine to deliver exceptional performance and scalability. Developers can scale their applications to handle growing workloads while maintaining low-latency response times.

Developer Productivity

Quarkus’ developer-friendly features, such as live coding, automatic hot reloads, and streamlined dependency management, complement Oracle NoSQL’s ease of use, allowing developers to focus on building innovative features rather than grappling with infrastructure complexities.

Cloud-Native Integration

Oracle NoSQL and Quarkus are designed for cloud-native environments, making them inherently compatible with modern deployment practices such as containerization, orchestration, and serverless computing. This compatibility ensures seamless integration with popular cloud platforms like AWS, Azure, and Google Cloud.

Reactive Programming

Quarkus’ support for reactive programming aligns well with the real-time, event-driven nature of Oracle NoSQL applications. Developers can leverage reactive paradigms to build highly responsive, resilient applications that handle asynchronous data streams and complex event processing effortlessly.

In conclusion, integrating Oracle NoSQL with Quarkus offers Java developers a compelling solution for building high-performance, scalable applications in the cloud age. By leveraging both technologies’ strengths, developers can unlock new possibilities in data management, application performance, and developer productivity, ultimately driving innovation and value creation in the digital era.

Executing the Database: Start Oracle NoSQL Database

Before diving into the code, we must ensure an Oracle NoSQL instance is running. Docker provides a convenient way to run Oracle NoSQL in a container for local development. Here’s how you can start the Oracle NoSQL instance using Docker:

Shell
 
docker run -d --name oracle-instance -p 8080:8080 ghcr.io/oracle/nosql:latest-ce


This command will pull the latest Oracle NoSQL Community Edition version from the GitHub Container Registry (ghcr.io) and start it as a Docker container named “oracle-instance” on port 8080.

Generating Code Structure With Quarkus

Quarkus simplifies the process of generating code with its intuitive UI. Follow these steps to generate the code structure for your Quarkus project:

  1. Open the Quarkus code generation tool in your web browser.
  2. Configure your project dependencies, extensions, and other settings as needed.
  3. Click the “Generate your application” button to download the generated project structure as a zip file.

Configuring MicroProfile Config Properties

Once your Quarkus project is generated, you must configure the MicroProfile Config properties to connect to the Oracle NoSQL database. Modify the microprofile-config.properties file in your project’s src/main/resources directory to include the database configuration and change the port to avoid conflicts:

Properties files
 
# Configure Oracle NoSQL Database
jnosql.keyvalue.database=olympus
jnosql.document.database=olympus
jnosql.oracle.nosql.host=http://localhost:8080

# Change server port to avoid conflict
server.port=8181


In this configuration:

  • jnosql.keyvalue.database and jnosql.document.database specify the database names for key-value and document stores, respectively.
  • jnosql.oracle.nosql.host specifies the host URL for connecting to the Oracle NoSQL database instance running locally on port 8080.
  • server.port changes the Quarkus server port to 8181 to avoid conflicts with the Oracle NoSQL database on port 8080.

With these configurations in place, your Quarkus application will be ready to connect seamlessly to the Oracle NoSQL database instance. You can now develop your application logic, leveraging the power of Quarkus and Oracle NoSQL to build robust, cloud-native solutions.

We’ll need to configure the dependencies appropriately to integrate Eclipse JNoSQL with Oracle NoSQL driver into our Quarkus project. Since Quarkus avoids using reflection solutions, we’ll utilize the lite version of Eclipse JNoSQL, which allows us to generate the necessary source code without requiring the reflection engine at runtime. Here’s how you can configure the dependencies in your pom.xml file:

XML
 
<dependency>
    <groupId>org.eclipse.jnosql.databases</groupId>
    <artifactId>jnosql-oracle-nosql</artifactId>
    <version>${jnosql.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.eclipse.jnosql.mapping</groupId>
            <artifactId>jnosql-mapping-reflection</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.eclipse.jnosql.lite</groupId>
    <artifactId>mapping-lite-processor</artifactId>
    <version>${jnosql.version}</version>
    <scope>provided</scope>
</dependency>


In this configuration:

  • <dependency> with groupId as org.eclipse.jnosql.databases and artifactId as jnosql-oracle-nosql includes the Oracle NoSQL driver for Eclipse JNoSQL.
  • Inside this dependency, we have an <exclusions> block to exclude the jnosql-mapping-reflection artifact. It is to ensure that the reflection engine is not included in our project, as Quarkus does not utilize reflection solutions.
  • <dependency> with groupId as org.eclipse.jnosql.lite and artifactId as mapping-lite-processor includes the lite version of the JNoSQL mapping processor.
  • We specify <scope> as provided for the lite processor dependency. It means that the lite processor is provided during compilation to generate the necessary source code but is not included in the application’s runtime dependencies.

With these dependencies configured, Eclipse JNoSQL will be seamlessly integrated into your Quarkus project, allowing you to leverage the power of Oracle NoSQL while adhering to Quarkus’ principles of avoiding reflection solutions.

For getting to know more about Eclipse JNoSQL Lite, visit the Eclipse JNoSQL GitHub Repository.

We’ll need to make a few adjustments to migrate the entity and repository from Java SE and Helidon to a Quarkus project. Here’s the modified code for your Beer entity, BeerRepository, and BeerResource classes:

Beer Entity

Java
 
@Entity
public class Beer {

    @Id
    public String id;

    @Column
    public String style;

    @Column
    public String hop;

    @Column
    public String malt;

    @Column
    public List<String> comments;

    // Public getters and setters are explicitly included for JNoSQL access
 }


Transitioning from Helidon to Quarkus entails adapting our repository to Quarkus-compatible standards. In Quarkus, the repository can extend the BasicRepository interface, simplifying database interactions to basic operations.

Java
 

@Repository
public interface BeerRepository extends BasicRepository<Beer, String> {
}


Our RESTful resource, BeerResource, undergoes minimal modification to align with Quarkus conventions. Here’s a breakdown of annotations and changes made:

  • @Path("/beers"): Establishes the base path for beer-related endpoints
  • @RequestScoped: Specifies the scope of the resource instance to a single HTTP request, ensuring isolation
  • @Produces(MediaType.APPLICATION_JSON): Signals the production of JSON responses
  • @Consumes(MediaType.APPLICATION_JSON): Indicates consumption of JSON requests
  • @Inject: Facilitates dependency injection of BeerRepository, eliminating manual instantiation
  • @Database(DatabaseType.DOCUMENT): Qualifies the database type for JNoSQL interactions, specifying the document-oriented nature of Oracle NoSQL; Qualifiers are pivotal in scenarios with multiple interface implementations, ensuring precise dependency resolution.
Java
 
@Path("/beers")
@RequestScoped
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class BeerResource {

    @Inject
    @Database(DatabaseType.DOCUMENT)
    BeerRepository beerRepository;

    @GET
    public List<Beer> getBeers() {
        return beerRepository.findAll();
    }

    @GET
    @Path("{id}")
    public Beer getBeerById(@PathParam("id") String id) {
        return beerRepository.findById(id)
                .orElseThrow(() -> new WebApplicationException("Beer not found: " + id, Response.Status.NOT_FOUND));
    }

    @PUT
    public void insert(Beer beer) {
        beerRepository.save(beer);
    }

    @DELETE
    @Path("{id}")
    public void delete(@PathParam("id") String id) {
        beerRepository.deleteById(id);
    }
}


Testing the Beer API

After setting up the Quarkus project and integrating Oracle NoSQL with JNoSQL, it’s crucial to thoroughly test the API endpoints to ensure they function as expected. Below are the steps to execute and test the API using curl commands via the terminal:

Step 1: Run the Quarkus Project

Execute the following command in your terminal to start the Quarkus project in development mode:

Shell
 
./mvnw compile quarkus:dev


This command compiles the project and starts the Quarkus development server, allowing you to change your code and see the results in real-time.

Step 2: Testing Endpoints With cURL

You can use cURL, a command-line tool for making HTTP requests, to interact with the API endpoints. Below are the curl commands to test each endpoint:

  1. Get All Beers:
Shell
 
curl -X GET http://localhost:8181/beers


This command retrieves all beers from the database and returns a JSON response containing the beer data.

  1. Get a Specific Beer by ID:
Shell
 
curl -X GET http://localhost:8181/beers/<beer_id>


Replace <beer_id> with the actual ID of the beer you want to retrieve. This command fetches the beer with the specified ID from the database.

  1. Insert a New Beer:
Shell
 
curl --location --request PUT 'http://localhost:8181/beers' \
--header 'Content-Type: application/json' \
--data '{"style":"IPA", "hop":"Cascade", "malt":"Pale Ale", "comments":["Great beer!", "Highly recommended."]}'


This command inserts a new beer into the database with the provided details (style, hop, malt, comments).

  1. Delete a Beer by ID:
Shell
 
curl -X DELETE http://localhost:8181/beers/<beer_id>


Replace <beer_id> with the actual ID of the beer you want to delete. This command removes the beer with the specified ID from the database.

By following these steps and executing the provided cURL commands, you can effectively test the functionality of your Beer API endpoints and ensure that they interact correctly with the Oracle NoSQL database.

Conclusion

In this article, we explored the seamless integration of Oracle NoSQL with Quarkus using JNoSQL, empowering developers to build robust and scalable applications in the cloud age. We began by understanding the fundamentals of Oracle NoSQL and Quarkus, recognizing their strengths in data management and cloud-native development.

By migrating a Beer entity and repository from Java SE and Helidon to a Quarkus project, we demonstrated the simplicity of leveraging JNoSQL to interact with Oracle NoSQL databases. By adhering to Quarkus conventions and utilizing JNoSQL annotations, we ensured smooth integration and maintained data integrity throughout the migration process.

Furthermore, we tested the API endpoints using cURL commands, validating the functionality of our Beer API and confirming its seamless interaction with the Oracle NoSQL database.

For developers looking to delve deeper into the implementation details and explore the source code, the following reference provides a comprehensive source code repository:

  • Quarkus with JNoSQL and Oracle NoSQL Source Code Reference

By leveraging the capabilities of Quarkus, JNoSQL, and Oracle NoSQL, developers can unlock new possibilities in application development, enabling them to build high-performance, cloud-native solutions easily. In conclusion, integrating Oracle NoSQL with Quarkus empowers developers to embrace the cloud age, delivering innovative and scalable applications that meet the evolving demands of modern businesses.

NoSQL Quarkus Reactive programming Cloud Java (programming language) Integration

Opinions expressed by DZone contributors are their own.

Related

  • Unveiling the Power of Helidon 4: A Dive Into New Features
  • Demystifying Virtual Thread Performance: Unveiling the Truth Beyond the Buzz
  • Powering Enterprise Applications: Unleashing the Java-MongoDB Synergy
  • Eclipse JNoSQL 1.0.2: Empowering Java With NoSQL Database Flexibility

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send 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: