fbpx

Java Enterprise Edition integration

Find out how to integrate JSQL with Java EE

Stack requirements

The JSQL Java EE library will not work without an account in the JSQL cloud and a backend application written in Java EE. To learn more see overview.

Installation

Add JSQL artifactory into your maven repositories in your project.

For Maven setup:

<repositories>
<repository>
<id>maven</id>
<url>https://nexus.jsql.it/nexus/content/repositories/releases/</url>
</repository>
</repositories>

For Gradle setup:

repositories {

    mavenCentral()
    maven{
        url "https://nexus.jsql.it/nexus/content/repositories/releases/"
    }

}

Then add jsql-javaee-plugin dependency:

Releases list

For Maven setup:

<dependency>
<groupId>jsql</groupId>
<artifactId>javaee-plugin</artifactId>
<version>1.1.0</version>
<type>pom</type>
</dependency>

For Gradle setup:

compile "jsql:javaee-plugin:1.1.0"

Integration

The JSQL plugin for Java EE has the same integration principle as the Spring Boot or Spring 5 plugin. All you need to do is create a controller that will inherit from JSQLController and initiate JSQLConfig.

Example REST controller inheriting JSQLController:

import it.jsql.connector.controller.JSQLController;

@Path("/api/jsql") public class ExampleRestController extends JSQLController { }

Now we have to override the getConfig method and return the JSQLConfig instance from it:

@Override
public JSQLConfig getConfig() {
return new JSQLConfig("YOUR_API_KEY", "YOUR_PRODUCTION_KEY");
}

The API_KEY and DEV_KEY we can get from JSQL Admin Panel, see FAQ for details.

We can save them as protected final fields or store in file:

protected final String API_KEY = "==iSqF8rKvVeSgqudKDOXpjiFgGMJh1PbeouIz9IW/YQ==9CI8ox66gogpoSXm6yr";
protected final String DEV_KEY = "Z6kEovODxAv2I5hKekMyUw==";

Let’s show whole REST controller class implementation:

import it.jsql.connector.controller.JSQLController;
import it.jsql.connector.dto.JSQLConfig;

import javax.ws.rs.Path;

@Path("/api/jsql")
public class ExampleRestController extends JSQLController {

    protected final String API_KEY = "==iSqF8rKvVeSgqudKDOXpjiFgGMJh1PbeouIz9IW/YQ==9CI8ox66gogpoSXm6yrU";
    protected final String DEV_KEY = "Z6kEovODxAv2I5hKekMyUw==";

    @Override
public JSQLConfig getConfig() {
return new JSQLConfig("YOUR_API_KEY", "YOUR_PRODUCTION_KEY");
} }

Usage

If your application is integrated using the JSQL plugin, you can start it and try to call the query using CURL:

curl 'http://localhost:8080/api/jsql/select' -H 'Accept: application/json' -H 'Content-Type: application/json' 
--data-binary '{"token":"f83njsus7ednjd38dnas8j3n","params":{}}' --compressed

What next?

Close Menu