Create a Data Access Object for UKG Pro HCM Data using 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 UKG Pro HCM integrates connectivity to live UKG Pro HCM data in Java applications. By pairing these technologies, you gain simple, programmatic access to UKG Pro HCM data. This article explains how to build a basic Data Access Object (DAO) and the accompanying code to read UKG Pro HCM data.
Create a DAO for the UKG Pro HCM UserDetails 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 MyUserDetailsDAO {
//request specific data from UKG Pro HCM (String type is used for simplicity)
@SqlQuery("SELECT UserName FROM UserDetails WHERE UserStatus = :userStatus")
String findUserNameByUserStatus(@Bind("userStatus") String userStatus);
/*
* close with no args is used to close the connection
*/
void close();
}
Open a Connection to UKG Pro HCM
Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to UKG Pro HCM.
Start by setting the Profile connection property to the location of the UKGProHCM Profile on disk (e.g. C:\profiles\UKGProHCM.apip). Next, set the ProfileSettings connection property to the connection string for UKGProHCM (see below).
UKGProHCM API Profile Settings
UKG Pro HCM uses Basic authentication combined with a customer API key to authorize access to the API. To connect, you will need your UKG Pro HCM credentials and a customer API key issued by UKG.
Set the following connection properties to authenticate:
- AuthScheme: Set this to Basic.
- User: Set this to your UKG Pro HCM username.
- Password: Set this to your UKG Pro HCM password.
- ProfileSettings: Set this to a semicolon-separated list containing:
- Host: Your UKG Pro HCM tenant hostname (e.g., yourcompany.ultipro.com).
- CustomerAPIKey: Your UKG customer API key. This is passed as the US-CUSTOMER-API-KEY request header on each API call.
To obtain your customer API key, contact your UKG Pro HCM administrator or refer to the UKG Developer Portal at https://developer.ukg.com.
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the UKG Pro HCM 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.
A connection string for UKG Pro HCM will typically look like the following:
jdbc:api:Profile=C:\profiles\UKGProHCM.apip;AuthScheme=Basic;User=your_username;Password=your_password;ProfileSettings='Host=yourcompany.ultipro.com;CustomerAPIKey=your_customer_api_key';
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\UKGProHCM.apip;AuthScheme=Basic;User=your_username;Password=your_password;ProfileSettings='Host=yourcompany.ultipro.com;CustomerAPIKey=your_customer_api_key';");
MyUserDetailsDAO dao = dbi.open(MyUserDetailsDAO.class);
//do stuff with the DAO
dao.close();
Read UKG Pro HCM Data
With the connection open to UKG Pro HCM, simply call the previously defined method to retrieve data from the UserDetails entity in UKG Pro HCM.
//disply the result of our 'find' method
String userName = dao.findUserNameByUserStatus("A");
System.out.println(userName);
Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for UKG Pro HCM by integrating with the CData JDBC Driver for UKG Pro HCM. Download a free trial and work with live UKG Pro HCM data in custom Java applications today.