Create a Data Access Object for Oracle Eloqua Reporting 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 Oracle Eloqua Reporting integrates connectivity to live Oracle Eloqua Reporting data in Java applications. By pairing these technologies, you gain simple, programmatic access to Oracle Eloqua Reporting data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read Oracle Eloqua Reporting data.
Create a DAO for the Oracle Eloqua Reporting 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 MyDAO {
//request specific data from Oracle Eloqua Reporting (String type is used for simplicity)
@SqlQuery("SELECT FROM WHERE = :")
String findBy(@Bind("") String );
/*
* close with no args is used to close the connection
*/
void close();
}
Open a Connection to Oracle Eloqua Reporting
Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Oracle Eloqua Reporting.
Oracle Eloqua Reporting supports the following authentication methods:
- Basic authentication (User and Password)
- OAuth 2.0 code grant flow
- OAuth 2.0 password grant flow
Basic Authentication (User and Password)
To perform authentication with a user and password, specify these properties:
- AuthScheme: Basic.
- Company: The company name associated with your Oracle Eloqua Reporting account.
- User: Your login account name.
- Password: Your login password.
OAuth Authentication (Code Grant Flow)
To authenticate with the OAuth code grant flow, you must set AuthScheme to OAuth and create a custom OAuth application. For information about how to create a custom OAuth application, see the Help documentation.
Then set the following properties:
- InitiateOAuth: GETANDREFRESH. Used to automatically get and refresh the OAuthAccessToken.
- OAuthClientId: The client Id assigned when you registered your application.
- OAuthClientSecret: The client secret that was assigned when you registered your application.
- CallbackURL: The redirect URI that was defined when you registered your application.
When you connect, the driver opens Oracle Eloqua Reporting's OAuth endpoint in your default browser. Log in and grant permissions to the application. When the access token expires, the driver refreshes it automatically.
OAuth Authentication (Password Grant Flow)
With the OAuth password grant flow, you can use your OAuth application's credentials alongside your user credentials to authenticate without the need to grant permission manually via a browser prompt. You must create an OAuth app (see the Help documentation) to use this authentication method.
Set the following properties:
- AuthScheme: OAuthPassword
- Company: The company's unique identifier.
- User: Your login account name.
- Password: Your login password.
- OAuthClientId: The client Id assigned when you registered your custom OAuth application.
- OAuthClientSecret: The client secret assigned when you registered your custom OAuth application.
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the Oracle Eloqua Reporting JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.oracleeloquareporting.jar
Fill in the connection properties and copy the connection string to the clipboard.
A connection string for Oracle Eloqua Reporting will typically look like the following:
jdbc:oracleeloquareporting:AuthScheme=Basic;User=user;Password=password;Company=MyCompany;
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:oracleeloquareporting:AuthScheme=Basic;User=user;Password=password;Company=MyCompany;");
MyDAO dao = dbi.open(MyDAO.class);
//do stuff with the DAO
dao.close();
Read Oracle Eloqua Reporting Data
With the connection open to Oracle Eloqua Reporting, simply call the previously defined method to retrieve data from the entity in Oracle Eloqua Reporting.
//disply the result of our 'find' method
String = dao.findBy("");
System.out.println();
Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for Oracle Eloqua Reporting by integrating with the CData JDBC Driver for Oracle Eloqua Reporting. Download a free trial and work with live Oracle Eloqua Reporting data in custom Java applications today.