DEV Community

Cover image for JNoSQL CriteriaQuery API preview
amoscatelli
amoscatelli

Posted on

6 3

JNoSQL CriteriaQuery API preview

Have you ever heard of Jakarta NoSQL ?

Since JavaEE adoption and rebranding by Eclipse Foundation, I consider it the most exciting feature for the upcoming Jakarta EE 10.

By splitting the NoSQL databases in four different abstractions (Column, Key-Value, Graph and Document), it allows agnostic coding with such technologies. So, for example, you could access both MongoDB and ElasticSearch with the same codebase, for they are both categorized and exposed as Document databases.

Cool, isn't it ?

Personally, I already adopted it even if both specification and default implementation, JNoSQL, are in preview state and may lack some functionalities.

For example, I found myself struggling with the absence of a proper Criteria API, allowing us to build up a criteria query object programmatically, where we could apply different kinds of filtration rules and logical conditions.

Also, following the JPA example, I would expect such Criteria API to be used in combination with an automatically generated Metamodel attributes.

Typos and backend don't get on well, do they ?

So I decided to contribute myself and, with the support of Otavio Santana, JNoSql Lead, this functionality has been delivered in the brand-new 1.0.0-b4 version.

Looking for a concrete example ?
Here you are :

CriteriaQuery<Person> personQuery = template.createQuery(Person.class);

EntityQueryResult<Person> executeQuery = template.executeQuery(
        personQuery.select().where(
                personQuery.from().get(
                        Person_.name
                ).equal(
                        "Poliana"
                ).or(
                        personQuery.from().get(
                                Person_.age
                        ).greaterThanOrEqualTo(17)
                )
        )
);

Stream<Person> stream = executeQuery.getEntities();
Enter fullscreen mode Exit fullscreen mode

For the moment, it has been published as a MongoDB extension but, with the community approval and once it's stable enough, it will brought to the main API and will work with every other Document NoSQL databases.

There are still many features to add and possibilities to explore.
For example, I strongly believe that Criteria API should also support update and delete operations too.
Also, wouldn't it be nice to have this working with other NoSQL abstractions (Column) ?

What do you think ?

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay