Create a Data Access Object for Halo Service Desk Data using JDBI

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
A brief overview of creating a SQL Object API for Halo Service Desk data in JDBI.

JDBI is a SQL convenience library for Java that exposes two different style APIs, a fluent style and a SQL object style. The CData JDBC Driver for Halo Service Desk integrates connectivity to live Halo Service Desk data in Java applications. By pairing these technologies, you gain simple, programmatic access to Halo Service Desk data. This article explains how to build a basic Data Access Object (DAO) and the accompanying code to read Halo Service Desk data.

Create a DAO for the Halo Service Desk Assets Entity

The interface below declares the desired behavior for the SQL object to create a single method for each SQL statement to be implemented.


public interface MyAssetsDAO {
  //request specific data from Halo Service Desk (String type is used for simplicity)
  @SqlQuery("SELECT InventoryNumber FROM Assets WHERE ClientId = :clientId")
  String findInventoryNumberByClientId(@Bind("clientId") String clientId);

  /*
   * close with no args is used to close the connection
   */
  void close();
}

Open a Connection to Halo Service Desk

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Halo Service Desk.

Start by setting the Profile connection property to the location of the HaloServiceDesk Profile on disk (e.g. C:\profiles\HaloServiceDesk.apip). Next, set the ProfileSettings connection property to the connection string for HaloServiceDesk (see below).

HaloServiceDesk API Profile Settings

HaloServiceDesk uses API key authentication. You can find or create API keys in HaloServiceDesk under Administration > Integrations > Halo API.

Set the following connection properties to connect:

  • AuthScheme: Set this to APIKey.
  • APIKey: Set this to the API key from your HaloServiceDesk account.
  • Domain: Set this to the hostname of your HaloServiceDesk instance (e.g. yourcompany.haloservicedesk.com).

Built-in Connection String Designer

For assistance in constructing the JDBC URL, use the connection string designer built into the Halo Service Desk JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.


java -jar cdata.jdbc.api.jar

Fill in the connection properties and copy the connection string to the clipboard.

Using the built-in connection string designer to generate a JDBC URL (Salesforce is shown.)

A connection string for Halo Service Desk will typically look like the following:

jdbc:api:Profile=C:\profiles\HaloServiceDesk.apip;AuthScheme=APIKey;ProfileSettings='APIKey=your_api_key;Domain=yourcompany.haloservicedesk.com';

Use the configured JDBC URL to obtain an instance of the DAO interface. The particular method shown below will open a handle bound to the instance, so the instance needs to be closed explicitly to release the handle and the bound JDBC connection.


DBI dbi = new DBI("jdbc:api:Profile=C:\profiles\HaloServiceDesk.apip;AuthScheme=APIKey;ProfileSettings='APIKey=your_api_key;Domain=yourcompany.haloservicedesk.com';");
MyAssetsDAO dao = dbi.open(MyAssetsDAO.class);

//do stuff with the DAO

dao.close();

Read Halo Service Desk Data

With the connection open to Halo Service Desk, simply call the previously defined method to retrieve data from the Assets entity in Halo Service Desk.


//disply the result of our 'find' method
String inventoryNumber = dao.findInventoryNumberByClientId("1");
System.out.println(inventoryNumber);

Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for Halo Service Desk by integrating with the CData JDBC Driver for Halo Service Desk. Download a free trial and work with live Halo Service Desk data in custom Java applications today.

Ready to get started?

Connect to live data from Halo Service Desk with the API Driver

Connect to Halo Service Desk