JNoSQL API 1.0.0-b3: What's New in This New Version
In this article, we'll explore more about the new API, 1.0.0-b3, of JNoSQL, a framework to create enterprise-grade applications using Java and NoSQL technologies.
Join the DZone community and get the full member experience.Join For Free
The Eclipse JNoSQL is a framework to help developers create enterprise-grade applications using Java and NoSQL technologies. It helps them create scalable applications while maintaining low coupling with the underlying NoSQL technology. This version has some features and a break-compatibility where it will talk about in this post.
At this version, there is break compatibility. This change was in the package name and not in the API itself, and it is similar to Jakarta EE big bang in version 9. Briefly, the names 'Diana' and 'Artemis' have been replaced with 'communication' and 'mapping' respectively. It will include both the package name and the project name.
To illustrate it, we'll upgrade a simple Couchbase database application. The first step is to start a database instance where we can do it easily with Docker in a single command.
The next step on Couchbase is going to http://localhost:8091/ URL and set up the name, user, and password. Please hold this once we'll need to use it to give access to the application. In this hello world, we'll set as:
- Cluster Name:
- Admin Username:
The next step is to go to the bucket section to create a 'heroes' bucket.
The database configuration is set up; let's go to the application itself. As with any maven project, we'll set the dependencies in JNoSQL, where we'll add the Mapping dependency and the Couchbase's driver. Remind that there is a break compatibility thing where all 'artemis' and 'diana' will be replaced by 'communication' and 'mapping' respectively.
All particular behavior matters in the NoSQL database, and that's why JNoSQL has the extension projects. Those extensions will provide particular behaviors beyond standard ones. Couchbase is a multi-model database, so it has support to key-value and document database. Thus this extension will provide support to both of those. It will follow in the other extensions as well, such as Cassandra with UDT and CQL.
The credentials are fundamental when we talk about databases, mainly to put those necessary credentials such as user and password. The Twelve factor App discusses this point.
JNoSQL uses the MicroProfile Configuration as a configuration engine, where we'll define the host, user, password, database, and provider using a properties file.
The more significant benefit is that it is possible to overwrite all configurations, so we'll set this database to run locally and overthrow it on production, so the developer team does even need to know about it.
The entity model, as the bucket name spoiler it, will a hero entity. Once this point involves only the Jakarta NoSQL API, there is not break compatibility.
The code is ready to run, so let's hack it with a classic
static void main method.
The Couchbase extension allows us to use particular behavior from Couchbase; this extension has the
CouchbaseTemplate that is an interface that extends from
DocumentTemplate with several methods such as index search. We'll explore it, but before we need to create a heroes-index, the UI has the Search option to make this index in the heroes bucket.
The next step is the creation of one more entity to explore the key-value API.
Key-value databases are usually faster but with fewer features to search information in the database; that is a trade-off that the developer needs to consider when deciding on any NoSQL database. We'll create a service class to explore these strategies with this kind of persistence technology.
Besides the KeyValueTemplate, we have two collections. However, those data are not in the Java memory. They are in the Redis database instead.
Wait! Why Doesn't It Upgrade the API to Use Jakarta EE 9?
JNoSQL has a dependency on MicroProfile Configuration, so while MicroProfile Config does not upgrade to Jakarta EE 9, JNoSQL is not enabled to do it.
The good news, there is the CN4J, where there is a conversation about integration between MicroProfile and Jakarta EE that includes the upgrade to Jakarta EE 9 on the MicroProfile side.
This tutorial explores the potential of the first Jakarta spec, where the goal is to integrate NoSQL databases with Java. This API brings features to make it easier to handle this kind of database in the enterprise architecture with Java using both: Jakarta EE and Microprofile.
Demo code: https://github.com/JNOSQL/demos
Opinions expressed by DZone contributors are their own.