Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Create a Data Access Object for Cvent Data using JDBI
A brief overview of creating a SQL Object API for Cvent 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 Cvent integrates connectivity to live Cvent data in Java applications. By pairing these technologies, you gain simple, programmatic access to Cvent data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read and write Cvent data.
Create a DAO for the Cvent Events 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 MyEventsDAO {
//insert new data into Cvent
@SqlUpdate("INSERT INTO Events (Virtual, Title) values (:virtual, :title)")
void insert(@Bind("virtual") String virtual, @Bind("title") String title);
//request specific data from Cvent (String type is used for simplicity)
@SqlQuery("SELECT Title FROM Events WHERE Virtual = :virtual")
String findTitleByVirtual(@Bind("virtual") String virtual);
/*
* close with no args is used to close the connection
*/
void close();
}
Open a Connection to Cvent
Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Cvent.
Before you can authenticate to Cvent, you must create a workspace and an OAuth application.
Creating a Workspace
To create a workspace:
- Sign into Cvent and navigate to App Switcher (the blue button in the upper right corner of the page) >> Admin.
- In the Admin menu, navigate to Integrations >> REST API.
- A new tab launches for Developer Management. Click on Manage API Access in the new tab.
- Create a Workspace and name it. Select the scopes you would like your developers to have access to. Scopes control what data domains the developer can access.
- Choose All to allow developers to choose any scope, and any future scopes added to the REST API.
- Choose Custom to limit the scopes developers can choose for their OAuth apps to selected scopes. To access all tables exposed by the driver, you need to set the following scopes:
event/attendees:read event/attendees:write event/contacts:read event/contacts:write event/custom-fields:read event/custom-fields:write event/events:read event/events:write event/sessions:delete event/sessions:read event/sessions:write event/speakers:delete event/speakers:read event/speakers:write budget/budget-items:read budget/budget-items:write exhibitor/exhibitors:read exhibitor/exhibitors:write survey/surveys:read survey/surveys:write
Creating an OAuth Application
After you have set up a Workspace and invited them, developers can sign up and create a custom OAuth app. See the Creating a Custom OAuth Application section in the Help documentation for more information.
Connecting to Cvent
After creating an OAuth application, set the following connection properties to connect to Cvent:
- InitiateOAuth: GETANDREFRESH. Used to automatically get and refresh the OAuthAccessToken.
- OAuthClientId: The Client ID associated with the OAuth application. You can find this on the Applications page in the Cvent Developer Portal.
- OAuthClientSecret: The Client secret associated with the OAuth application. You can find this on the Applications page in the Cvent Developer Portal.
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the Cvent JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.cvent.jar
Fill in the connection properties and copy the connection string to the clipboard.
A connection string for Cvent will typically look like the following:
jdbc:cvent:OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;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:cvent:OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;InitiateOAuth=GETANDREFRESH");
MyEventsDAO dao = dbi.open(MyEventsDAO.class);
//do stuff with the DAO
dao.close();
Read Cvent Data
With the connection open to Cvent, simply call the previously defined method to retrieve data from the Events entity in Cvent.
//disply the result of our 'find' method
String title = dao.findTitleByVirtual("true");
System.out.println(title);
Write Cvent Data
It is also simple to write data to Cvent, using the previously defined method.
//add a new entry to the Events entity
dao.insert(newVirtual, newTitle);
Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for Cvent by integrating with the CData JDBC Driver for Cvent. Download a free trial and work with live Cvent data in custom Java applications today.