Use Datasources in exits

To use a previously defined Datasource in an exit, you must follow these steps:

  1. Declare an ExternalService variable and annotate it with @Autowired. The Spring container injects the implementation.

public class MyModifyFunction implements ModifyFunction

{

@Autowired

private ExternalService extService;

……

  1. Get a DataSourceService implementation from the external service:

DataSourceService dsService = extService.getDataSourceService();

  1. Create a DsQuery object and use its instance to add columns, sort and filter:

DsQuery dsQuery = dsService.newQuery()

.setColumns("ID_CUSTOMER", "CUSTOMER_NAME", "BALANCE")

.addOrderAsc("CUSTOMER_NAME")

.setFilter(dsService.newFilter()

.addEqual("BALANCE", 10))

.setDistinct(true) // will return distinct values

.setLimit(100); // fetch maximum 100 rows

The query in the example returns a list of rows. The list contains the Customer Id, the Customer Name and the Balance values. The elements are filtered by Balance value (BALANCE = 10) and sorted is ascending order by Customer Name. The query only returns distinct values and 100 rows maximum are fetched.

  1. Get the data:

List<Map<String, Object>> dsRows = dsService.query("DS", dsQuery);

Related Links