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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Data Engineering
  3. Databases
  4. Jakarta EE: Generation IV — A New Hope

Jakarta EE: Generation IV — A New Hope

With the brand-new name Jakarta EE — this brings a new hope for Enterprise Java.

Otavio Santana user avatar by
Otavio Santana
CORE ·
Aug. 15, 19 · Presentation
Like (10)
Save
Tweet
Share
13.12K Views

Join the DZone community and get the full member experience.

Join For Free

Image title

Java Enterprise Edition (Java EE) is an umbrella that holds specifications and APIs with enterprise features, like distributed computing and web services. Widely used in Java, Java EE runs on reference runtimes that can be anything from microservices to application servers that handle transactions, security, scalability, concurrency, and management for the components it’s deploying.

Now that Enterprise Java has been standardized under the Eclipse Foundation — with the brand-new name Jakarta EE — this brings a new hope for Enterprise Java. This post will show a similar solution to Spring MVC with MongoDB on the Jakarta EE community side.

For this project, we’ll need some assistance. To triumph over the imperial forces, these three projects can help us:

  • Eclipse Krazo. An implementation of action-based MVC specified by MVC 1.0 (JSR-371). Eclipse Krazo builds on top of JAX-RS and currently contains support for RESTEasy, Jersey, and CXF with a well-defined SPI for other implementations.

  • Jakarta NoSQL. A framework to help developers create enterprise-grade applications using Java and NoSQL technologies. Jakarta NoSQL enables devs to create scalable applications while maintaining low coupling with the underlying NoSQL technology. 

  •   Bean Validation, JSR 380. A specification that creates its own annotations and validation, and ensures that the properties of a class match specific criteria, using annotations such as @NotNull, @Min, and  @Max.

Show Me the Force  Code

The first step, as usual, is to create a Maven project where we define the dependencies in the pom.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.superbiz</groupId>
<artifactId>mvc-cxf</artifactId>
<packaging>war</packaging>

<name>OpenEJB :: Examples :: MVC (CXF-based)</name>
<description>OpenEJB :: Web Examples :: MVC 1.0 - Jakarta NoSQL</description>
<version>0.0.1-SNAPSHOT</version>
<url>http://tomee.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <tomee.version>8.0.0-M3</tomee.version>
    <version.krazo>1.0.0-SNAPSHOT</version.krazo>
    <jnosql.version>0.1.0-SNAPSHOT</jnosql.version>
    <http.port>8888</http.port>
</properties>

<build>
    <finalName>ROOT</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.2</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <packagingExcludes>pom.xml</packagingExcludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.tomee.maven</groupId>
            <artifactId>tomee-maven-plugin</artifactId>
            <version>${tomee.version}</version>
            <configuration>
                <tomeeHttpPort>${http.port}</tomeeHttpPort>
            </configuration>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>oss.sonatype.org-snapshot</id>
        <url>http://oss.sonatype.org/content/repositories/snapshots</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>jakarta.enterprise</groupId>
        <artifactId>jakarta.enterprise.cdi-api</artifactId>
        <version>2.0.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jakarta.ws.rs</groupId>
        <artifactId>jakarta.ws.rs-api</artifactId>
        <version>2.1.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jakarta.validation</groupId>
        <artifactId>jakarta.validation-api</artifactId>
        <version>2.0.1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>sh.platform</groupId>
        <artifactId>config</artifactId>
        <version>2.2.2-SNAPSHOT</version>
    </dependency>

    <!--Eclipse JNoSQL-->
    <dependency>
        <groupId>org.jnosql.artemis</groupId>
        <artifactId>artemis-document</artifactId>
        <version>${jnosql.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jnosql.diana</groupId>
        <artifactId>mongodb-driver</artifactId>
        <version>${jnosql.version}</version>
    </dependency>

    <!-- MVC 1.0(JSR 371) -->
    <dependency>
        <groupId>org.eclipse.krazo</groupId>
        <artifactId>krazo-core</artifactId>
        <version>${version.krazo}</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.krazo</groupId>
        <artifactId>krazo-cxf</artifactId>
        <version>${version.krazo}</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

</dependencies>
</project>


One crucial point to remember is that with the Jakarta EE specification, we can use several vendors without impacting the application. In this tutorial, we’ll use Apache TomEE.

The next step is to define the user model. To make this all smoother, this user just has a country, state, name, age, JUG, and description tags as information. So, two classes:

  • The Person class: name, age, JUG, and any description

  • The Address class: country and state

As with any simple register page, the user information comes through in a page form, so the MVC frameworks come with the FormParam annotation. This way, the developer can connect the form with any input field once the annotation matches the input tag exactly.

The MongoDB integration with the model is easy, too; JNoSQL has annotations that look like those of the JPA, so the developer defines the Entity , the Column , and the ID  using the Entity, Column, and Id annotations, respectively.

One difference with MongoDB is that we can store the Address class information as a field instead of making it a relationship, as we usually do with SQL technology. So, we’ll use the Address as a subdocument of the Person entity, which is faster because it reduces the number of joins and is more natural to query.

@Entity
public class Person {

@Id
@FormParam("id")
@Convert(ObjectIdConverter.class)
private String id;

@FormParam("name")
@NotEmpty(message = "can not be empty")
@Size(min = 1, max = 20)
@MvcBinding
@Column
private String name;

@FormParam("age")
@MvcBinding
@Min(18)
@Column
private int age;

@BeanParam
@Valid
@Column
private Address address;

@FormParam("server")
@NotNull
@MvcBinding
@Column
private String server;

@FormParam("description")
@NotEmpty(message = "can not be empty")
@MvcBinding
@Size(min = 10)
@Column
private String description;
}

@Entity
public class Address {

@FormParam("country")
@NotEmpty(message = "can not be empty")
@MvcBinding
@Column
private String country;

@FormParam("state")
@NotEmpty(message = "can not be empty")
@MvcBinding
@Column
private String state;
}


The repository is a DDD pattern that acts as a mediator between the domain and data mapping layers using a collection-like interface for accessing domain objects. To create a Person repository, we need an interface that extends Repository. That’s all; JNoSQL will handle the implementation for you.

Here’s the method with a query whose whole point is to let the Java developer create any method using the JNoSQL convention. Then, the framework will implement it.

public interface PersonRepository extends Repository<Person, String> {

Optional<Person> findById(Long id);

List<Person> findAll();
}


The controller is the bridge to connect the view and the model. Models is a map of the name-to-model instances used by ViewEngine to process a view. Viewable is an abstraction that encapsulates information about a view. The other points are clear enough. Use the GET annotation to define access and POST to define the PATH that establishes a URL path.

Happy Jakarta-ing!

Database

Published at DZone with permission of Otavio Santana, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Building a Real-Time App With Spring Boot, Cassandra, Pulsar, React, and Hilla
  • How To Choose the Right Streaming Database
  • gRPC on the Client Side
  • Full Lifecycle API Management Is Dead

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: