Nov 23

 Java Integration Services

If you want more control or you are more comfortable working with Java, you can invoke various services like DB, Feed, SOAP and Security services from Java using @Autowired in the UserService.java files. The autowiring feature of spring framework enables you to inject the object dependency implicitly. It internally uses setter or constructor injection. The advantage of autowiring is, it requires the less code because we don’t need to write the code to inject the dependency explicitly.
Note: REST Services cannot be invoked.

Accessing current logged in user details

To access the Logged in user details in an app that is secured, you need to import the security service. The Security Service import can be done using the following code snippet

Accessing external Java libraries

There are two ways in which this can be achieved:

  1. Exporting the project to an IDE of your choice and changing the code as per your requirements and importing it to WaveMaker. This is possible since the code generated for WaveMaker projects is Maven complaint. Export Project
  2. Importing the jar files as external resource and using them within your app. Import Resource

Accessing Database services using Java Service

To access a database table from a Database Integrated into your app, you need to access the Java Service file corresponding to the table from the Services tab in the left panel. For example, to access the User table from hrdb, you need to access the UserService.java file from the Services subfolder from the left Files panel.

We will see:

Where to find DB Services

You can find a list of methods for User table in userservice.java like create, delete, find, update, query service, procedure service and so on.

Accessing DB Services

For working with the Database table operations such as insert, get, update in Java Service, the following generic code can be used. Here we are trying to access the User table from the sample hrdb:

Accessing different DB Services with the same name

If there are two or more beans for same class type, you need to use @Qualifier annotation along with @Autowired annotation and pass the bean name in annotation parameter.
For example, you have more than one implementation of User service, then use qualifier to inject the specific implementation of User service.

Database Transactions from Java Service

Transactions for related entities

Transactions can be used in cases where you have multiple independent statements which need to be linked together. A transaction can end in two ways: with a commit or with a rollback. When a transaction commits, the data modifications made by its statements are saved. If a statement within a transaction fails, the transaction rolls back, undoing the effects of all statements in the transaction.

Let us see a simple example of interacting with the hrdb database in Java service using Transactions.

  • Define an API that creates employee and retrieves the same from the database.
  • Create employee and retrieving employee are two independent calls to the database. When we enclose it with the transaction it will ensure that either both actions occur or neither action occurs.
  • In the below transaction code, if createEmployee is successful but retrieve employee fails, then created employee will be reverted from the database.

To see the rollback in action replace the last line with:

Accessing Query services using Java Service

Named Queries or queries that are written, tested and saved in query editor of Database Designer. Query Editor. For each and every named query, there will be a rest service generated in query execution controller and exposed. Here we are seeing two queries – Emp_Count and Total_by_City which were created from the query editor.

Invoking Imported Web Services

Various Web Service can be Integrated into WaveMaker apps. These services can be invoked from Java Services.

For Soap Service import following is the code snippet
Note: Calculator is WSDL service which was imported.

For Feed Service import following is the code snippet

For Feed With Auth Service import following is the code snippet

5. Creating Backend Services

 
We use cookies to provide you with a better experience. By using our website you agree to the use of cookies as described in our Privacy Policy.