Model Context Protocol (MCP) finally gives AI models a way to access the business data needed to make them really useful at work. CData MCP Servers have the depth and performance to make sure AI has access to all of the answers.
Try them now for free →Create a Data Access Object for Adobe Target Data using JDBI
A brief overview of creating a SQL Object API for Adobe Target 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 Adobe Target integrates connectivity to live Adobe Target data in Java applications. By pairing these technologies, you gain simple, programmatic access to Adobe Target data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read Adobe Target data.
Create a DAO for the Adobe Target Activities 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 MyActivitiesDAO {
//request specific data from Adobe Target (String type is used for simplicity)
@SqlQuery("SELECT Name FROM Activities WHERE Type = :type")
String findNameByType(@Bind("type") String type);
/*
* close with no args is used to close the connection
*/
void close();
}
Open a Connection to Adobe Target
Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Adobe Target.
To connect to Adobe Target, you must provide the Tenant property along with OAuth connection properties mentioned below. Note that while other connection properties can influence processing behavior, they do not affect the ability to connect.
To determine your Tenant name:
- Log in to Adobe Experience. The URL will look similar to: "https://experience.adobe.com/#/@mycompanyname/preferences/general-section".
- Extract the value after the "/#/@". In this example, it is "mycompanyname".
- Set the Tenant connection property to that value.
User Accounts (OAuth)
You must set AuthScheme to OAuthClient for all user account flows.
Note: Adobe authentication via OAuth requires updating your token every two weeks.
All Applications
CData provides an embedded OAuth application that simplifies OAuth authentication. Alternatively, you can create a custom OAuth application. Review Creating a Custom OAuth App in the Help documentation for more information.Obtaining the OAuth Access Token
Set the following properties to connect:
- InitiateOAuth: Set to GETANDREFRESH to automatically perform the OAuth exchange and refresh the OAuthAccessToken as needed.
- OAuthClientId : Set to the client Id assigned when you registered your app.
- OAuthClientSecret : Set to the client secret assigned when you registered your app.
- CallbackURL : Set to the redirect URI defined when you registered your app. For example: https://localhost:3333
With these settings, the provider obtains an access token from Adobe Target, which it uses to request data. The OAuth values are stored in the location specified by OAuthSettingsLocation, ensuring they persist across connections.
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the Adobe Target JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.adobetarget.jar
Fill in the connection properties and copy the connection string to the clipboard.
A connection string for Adobe Target will typically look like the following:
jdbc:adobetarget:Tenant=mycompanyname;InitiateOAuth=GETANDREFRESH
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:adobetarget:Tenant=mycompanyname;InitiateOAuth=GETANDREFRESH");
MyActivitiesDAO dao = dbi.open(MyActivitiesDAO.class);
//do stuff with the DAO
dao.close();
Read Adobe Target Data
With the connection open to Adobe Target, simply call the previously defined method to retrieve data from the Activities entity in Adobe Target.
//disply the result of our 'find' method
String name = dao.findNameByType("AB");
System.out.println(name);
Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for Adobe Target by integrating with the CData JDBC Driver for Adobe Target. Download a free trial and work with live Adobe Target data in custom Java applications today.