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

  • Architecture and Code Design, Pt. 1: Relational Persistence Insights to Use Today and On the Upcoming Years
  • Making Your Life Easier Around Data With Java and Jakarta EE
  • Exploring the New Eclipse JNoSQL Version 1.1.0: A Dive Into Oracle NoSQL
  • Eclipse JNoSQL 1.0.2: Empowering Java With NoSQL Database Flexibility

Trending

  • Vector Tutorial: Conducting Similarity Search in Enterprise Data
  • How To Get Started With New Pattern Matching in Java 21
  • How to Submit a Post to DZone
  • Service Mesh Unleashed: A Riveting Dive Into the Istio Framework
  1. DZone
  2. Data Engineering
  3. Databases
  4. Navigating NoSQL: A Pragmatic Approach for Java Developers

Navigating NoSQL: A Pragmatic Approach for Java Developers

Eclipse JNoSQL 1.0.3 empowers Java devs with ArangoDB. Simplify NoSQL integration and persist data effortlessly. Explore hands-on code sessions!

By 
Otavio Santana user avatar
Otavio Santana
DZone Core CORE ·
Dec. 04, 23 · Tutorial
Like (3)
Save
Tweet
Share
4.4K Views

Join the DZone community and get the full member experience.

Join For Free

In the dynamic landscape of data management, NoSQL databases have emerged as a crucial component, offering flexibility and scalability that traditional relational databases sometimes struggle to provide. Understanding the significance of NoSQL and its synergy with Java is pivotal for developers seeking efficient solutions for modern, data-intensive applications.

Why NoSQL Matters: Unraveling the Complexities

NoSQL databases have gained prominence due to their easy handling of unstructured and semi-structured data. Unlike traditional relational databases, NoSQL embraces a schema-less approach, allowing developers to adapt swiftly to evolving data structures. It proves invaluable in scenarios where data types and relationships are not predefined or may change frequently.

The scalability of NoSQL databases is another noteworthy feature. With the rise of applications requiring high throughput and low-latency responses, NoSQL databases excel in distributing data across clusters, ensuring optimal performance even as data volumes grow.

Moreover, the diversity within the NoSQL realm caters to specific use cases, such as document-oriented databases (like MongoDB), key-value stores (like Redis), and graph databases (like Neo4j). This diversity empowers developers to choose the right tool for the job, tailoring their database choice to the unique requirements of their applications.

Java and NoSQL: A Synergistic Alliance

Java, renowned for its platform independence and robustness, seamlessly integrates with NoSQL databases, making it an ideal choice for developers. The compatibility between Java and NoSQL stems from Java’s versatility and the fact that many NoSQL databases provide Java APIs or drivers.

Developers leveraging Java with NoSQL can harness the language’s object-oriented paradigm to map data structures directly to code, simplifying the development process. Additionally, Java’s multi-threading capabilities align well with NoSQL databases’ distributed and parallel nature, facilitating efficient data handling in resource-intensive applications.

Eclipse JNoSQL: Bridging the Gap for Java Developers

Enter Eclipse JNoSQL—a powerful open-source solution to streamline NoSQL database interactions within Java applications. Eclipse JNoSQL provides a consistent and vendor-agnostic API, abstracting the complexities of different NoSQL databases and enabling developers to switch databases effortlessly without extensive code changes.

Developers benefit from Eclipse JNoSQL’s modular architecture, allowing them to choose the components that suit their application requirements. Whether working with document-oriented databases, key-value stores, or graph databases, Eclipse JNoSQL ensures a unified and intuitive developer experience.

Unveiling Eclipse JNoSQL Version 1.0.3: What’s Inside?

The latest release of Eclipse JNoSQL, version 1.0.3, introduces a series of database upgrades and project enhancements aimed at delivering tangible value to developers:

  • Database Upgrades: Stay current with the latest NoSQL technologies by leveraging upgraded drivers for MongoDB, Hazelcast, Apache Solr, Jedis, OrientDB, Elasticsearch, DynamoDB, Couchbase, and ArangoDB. These upgrades ensure compatibility and unlock the latest features offered by these databases.
  • Project Fixes and Enhancements: Addressing user feedback, Eclipse JNoSQL 1.0.3 includes fixes in Eclipse JNoSQL Lite and enhances update methods, contributing to a smoother and more robust developer experience.
  • Upcoming Features: The Eclipse JNoSQL roadmap includes plans to improve support for Jakarta Data version 1.0.0-M2 and enhance support for JPMS. These additions will further empower developers to build scalable and modular Java applications.

Show Me the Code

Let’s dive into the hands-on coding session, where we’ll create a Java SE application using Eclipse JNoSQL and ArangoDB. This walkthrough assumes you have Docker installed and running, which allows you to easily set up an ArangoDB instance.

Start by running the following Docker command to set up an ArangoDB instance with minimal configuration:

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


This command pulls the official ArangoDB Docker image, starts an arangodb-instance container, and exposes the ArangoDB web interface on port 8529.

Ensure your Maven pom.xml includes the necessary Eclipse JNoSQL, CDI, JSON-B, ArangoDB driver, and Data Faker dependencies. Add the following dependencies:

XML
 
<dependencies>
    <!-- Eclipse JNoSQL Dependencies -->
    <dependency>
        <groupId>org.eclipse.jnosql.databases</groupId>
        <artifactId>jnosql-arangodb</artifactId>
        <version>${jnosql.version}</version>
    </dependency>  
    <!-- Data Faker Dependency -->
    <dependency>
        <groupId>net.datafaker</groupId>
        <artifactId>datafaker</artifactId>
        <version>2.0.2</version>
    </dependency>
</dependencies>


Adjust the ${jnosql.version} placeholder according to your current version.

Now, let’s define the Hero entity with its attributes—id, name, descriptor, and power. Additionally, we’ll include a static method to create a hero using Data Faker:

Java
 
import org.eclipse.jnosql.mapping.Column;
import org.eclipse.jnosql.mapping.Entity;
import org.eclipse.jnosql.mapping.Id;

import com.github.javafaker.Faker;

@Entity
public record Hero(

        @Id
        String id,

        @Column
        String name,
        
        @Column
        String descriptor,

        @Column
        String power) {

    public static Hero createFakeHero() {
        Faker faker = new Faker();
        return new Hero(faker.idNumber().valid(), faker.superhero().name(),
                faker.superhero().descriptor(), faker.superhero().power());
    }
}


Now that we’ve defined our Hero entity, let’s execute some code to persist and query hero data using Eclipse JNoSQL with ArangoDB. In this final step, we’ll explore two ways to interact with the database: the DocumentTemplate and the ArangoDB extension.

Application Using DocumentTemplate

Java
 
public class App {

    public static void main(String[] args) {

        try (SeContainer container = SeContainerInitializer.newInstance().initialize()) {
            var faker = new Faker();
            DocumentTemplate template = container.select(DocumentTemplate.class).get();

            // Insert a hero into the database
            Hero hero = template.insert(Hero.of(faker));

            // Retrieve heroes with the same name
            List<Hero> heroes = template.select(Hero.class)
                    .where("name").eq(hero.name()).result();
            System.out.println(heroes);

        }
    }

    private App() {
    }
}


In this example, we use the `DocumentTemplate` to interact with ArangoDB. We insert a hero into the database and then query for heroes with the same name. The result is printed to the console.

Application Using DocumentTemplate

Java
 
public class App {

    public static void main(String[] args) {

        try (SeContainer container = SeContainerInitializer.newInstance().initialize()) {
            var faker = new Faker();
            DocumentTemplate template = container.select(DocumentTemplate.class).get();

            // Insert a hero into the database
            Hero hero = template.insert(Hero.of(faker));

            // Retrieve heroes with the same name
            List<Hero> heroes = template.select(Hero.class)
                    .where("name").eq(hero.name()).result();
            System.out.println(heroes);

        }
    }

    private App() {
    }
}


In this example, we use the DocumentTemplate to interact with ArangoDB. We insert a hero into the database and then query for heroes with the same name. The result is printed to the console.

Application Using ArangoDBTemplate

Java
 
public class App1 {

    public static void main(String[] args) {

        try (SeContainer container = SeContainerInitializer.newInstance().initialize()) {

            var faker = new Faker();

            ArangoDBTemplate template = container.select(ArangoDBTemplate.class).get();
            
            // Insert a hero into the database
            Hero hero = template.insert(Hero.of(faker));

            // Query heroes using DocumentQuery
            DocumentQuery query = select().from("Hero").where("_key").eq("iron_man").build();
            List<Hero> heroes = template.<Hero>select(query).collect(Collectors.toList());

            // Query heroes using AQL (ArangoDB Query Language)
            List<Hero> aql = template.<Hero>aql("FOR h IN Hero FILTER  h.name == @id RETURN h",
                    Collections.singletonMap("id", hero.name()))
                    .collect(Collectors.toList());

            System.out.println(heroes);
            System.out.println(aql);

        }
    }

    private App1() {
    }
}


In this alternative approach, we utilize the ArangoDBTemplate to interact with ArangoDB. Similar to the previous example, we insert a hero into the database. We then query for heroes using both DocumentQuery and AQL, showcasing the flexibility of Eclipse JNoSQL.

For further exploration and experimentation, you can find additional examples and demos using Eclipse JNoSQL and Java SE on the official GitHub repository: demos-se.

To extend your knowledge of Eclipse MicroProfile and Jakarta EE applications, check out the demos available at demos-ee.

Feel free to adapt and enhance the code to suit your use cases. With Eclipse JNoSQL, developing Java applications that leverage NoSQL databases becomes intuitive and efficient.

Conclusion

As NoSQL databases play a pivotal role in modern application development, Java developers can confidently embrace Eclipse JNoSQL as a facilitator of seamless integration and enhanced productivity. The latest release, version 1.0.3, signifies the project’s commitment to staying at the forefront of NoSQL advancements and delivering tangible benefits to the developer community.

Explore the latest release on GitHub:

  • Eclipse JNoSQL Databases - Version 1.0.3
  • Eclipse JNoSQL - Version 1.0.3

Your journey into the world of NoSQL with Java awaits—seize the opportunity to build scalable, flexible, and efficient applications with Eclipse JNoSQL.

Database Eclipse NoSQL Relational database Java (programming language) Data Types

Opinions expressed by DZone contributors are their own.

Related

  • Architecture and Code Design, Pt. 1: Relational Persistence Insights to Use Today and On the Upcoming Years
  • Making Your Life Easier Around Data With Java and Jakarta EE
  • Exploring the New Eclipse JNoSQL Version 1.1.0: A Dive Into Oracle NoSQL
  • 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: