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.

Your backend application should have property configured database connection using JPA. For more details see  JPA integration.

Installation

Add JSQL artifactory into your maven repositories in your project.

For Maven setup:

<repositories>
    <repository>
        <id>maven</id>
        <url>http://46.41.135.99:8081/artifactory/libs-release-local/</url>
    </repository>
</repositories>

For Gradle setup:

repositories {

    mavenCentral()
    maven{
        url "http://46.41.135.99:8081/artifactory/libs-release-local"
    }

}

Then add jsql-java-ee-plugin dependency:

Releases list

For Maven setup:

<dependency>
    <groupId>it.jsql.connector.javaee</groupId>
    <artifactId>jsql-java-ee-plugin</artifactId>
    <version>1.0.0.</version>
</dependency>

For Gradle setup:

compile(group: 'it.jsql.connector.javaee', name: 'jsql-java-ee-plugin', version: '1.0.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 JSQLService.

Example REST controller inheriting JSQLController:

import it.jsql.connector.controller.JSQLController;
import it.jsql.connector.service.IJSQLService;
import it.jsql.connector.service.JSQLService;

@Path("/example")
public class ExampleRestService extends JSQLController { }

Now we have to implement the getJsqlService method and return the JSQLService instance from it:

@Override
public IJSQLService getJsqlService() {
  return new JSQLService(entityManager, API_KEY, DEV_KEY);
}

To the JSQLService constructor we need to pass the EntityManager, API_KEY and DEV_KEY.

The EntityManager we can get using @PersistanceContext annotation:

@PersistenceContext(unitName = "primary")
private EntityManager entityManager;

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.service.IJSQLService;
import it.jsql.connector.service.JSQLService;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.Path;

@Path("/example")
public class ExampleRestService extends JSQLController {

    @PersistenceContext(unitName = "primary")
    private EntityManager entityManager;

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

    @Override
    public IJSQLService getJsqlService() {
        return new JSQLService(entityManager, API_KEY, DEV_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/jsql/select' -H 'Accept: application/json' -H 'Content-Type: application/json' 
--data-binary '{"token":"select * from person","params":{}}' --compressed

What next?

Close Menu