Create a Data Access Object for UKG Pro WFM 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 WFM integrates connectivity to live UKG Pro WFM data in Java applications. By pairing these technologies, you gain simple, programmatic access to UKG Pro WFM data. This article explains how to build a basic Data Access Object (DAO) and the accompanying code to read UKG Pro WFM data.
Create a DAO for the UKG Pro WFM Employees 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 MyEmployeesDAO {
//request specific data from UKG Pro WFM (String type is used for simplicity)
@SqlQuery("SELECT UserName FROM Employees WHERE PersonId = :personId")
String findUserNameByPersonId(@Bind("personId") String personId);
/*
* close with no args is used to close the connection
*/
void close();
}
Open a Connection to UKG Pro WFM
Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to UKG Pro WFM.
Start by setting the Profile connection property to the location of the UKGProWFM Profile on disk (e.g. C:\profiles\UKGProWFM.apip). Next, set the ProfileSettings connection property to the connection string for UKGProWFM (see below).
UKGProWFM API Profile Settings
UKG Pro Workforce Management uses OAuth 2.0 with the Resource Owner Password Credentials grant (grant_type=password) to authorize access to the API. Unlike most OAuth-based profiles, this does not use a browser redirect/authorization-code step: the driver exchanges your UKG Pro WFM username, password, client ID, and client secret directly for an access token.
Set the following connection properties to authenticate:
- AuthScheme: Set this to OAuthPassword.
- Host: Set this to the hostname of your UKG Pro Workforce Management datacenter/tenant (for example, yourcompany.mykronos.com). Do not include the protocol (https://) or a trailing slash.
- OAuthClientId: Set this to the client ID issued for your UKG Pro Workforce Management OAuth application.
- OAuthClientSecret: Set this to the client secret issued for your UKG Pro Workforce Management OAuth application.
- User: Set this to your UKG Pro Workforce Management username.
- Password: Set this to your UKG Pro Workforce Management password.
Access tokens are obtained from https://{Host}/api/authentication/access_token. Refresh tokens issued by UKG Pro Workforce Management expire after 7 days; if a refresh attempt fails because the refresh token itself has expired, the driver must re-authenticate with your User/Password credentials to obtain a new access token.
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the UKG Pro WFM 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 WFM will typically look like the following:
jdbc:api:Profile=C:\profiles\UKGProWFM.apip;AuthScheme=OAuthPassword;ProfileSettings='Host=yourcompany.mykronos.com;User=your_username;Password=your_password;';OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;
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\UKGProWFM.apip;AuthScheme=OAuthPassword;ProfileSettings='Host=yourcompany.mykronos.com;User=your_username;Password=your_password;';OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;");
MyEmployeesDAO dao = dbi.open(MyEmployeesDAO.class);
//do stuff with the DAO
dao.close();
Read UKG Pro WFM Data
With the connection open to UKG Pro WFM, simply call the previously defined method to retrieve data from the Employees entity in UKG Pro WFM.
//disply the result of our 'find' method
String userName = dao.findUserNameByPersonId("12345");
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 WFM by integrating with the CData JDBC Driver for UKG Pro WFM. Download a free trial and work with live UKG Pro WFM data in custom Java applications today.