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 Bugzilla Data using JDBI
A brief overview of creating a SQL Object API for Bugzilla 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 Bugzilla integrates connectivity to live Bugzilla data in Java applications. By pairing these technologies, you gain simple, programmatic access to Bugzilla data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read Bugzilla data.
Create a DAO for the Bugzilla Bugs 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 MyBugsDAO {
//request specific data from Bugzilla (String type is used for simplicity)
@SqlQuery("SELECT Summary FROM Bugs WHERE Creator = :creator")
String findSummaryByCreator(@Bind("creator") String creator);
/*
* close with no args is used to close the connection
*/
void close();
}
Open a Connection to Bugzilla
Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Bugzilla.
You can authenticate to your Bugzilla account using two parameters:
- URL: The URL of your Bugzilla developer's page (the Home page).
- ApiKey: API Keys can be generated from the Preferences -> API Keys section of your Bugzilla developer's page.
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the Bugzilla JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.bugzilla.jar
Fill in the connection properties and copy the connection string to the clipboard.
A connection string for Bugzilla will typically look like the following:
jdbc:bugzilla:Url=http://yourdomain/Bugzilla;APIKey=abc123;
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:bugzilla:Url=http://yourdomain/Bugzilla;APIKey=abc123;");
MyBugsDAO dao = dbi.open(MyBugsDAO.class);
//do stuff with the DAO
dao.close();
Read Bugzilla Data
With the connection open to Bugzilla, simply call the previously defined method to retrieve data from the Bugs entity in Bugzilla.
//disply the result of our 'find' method
String summary = dao.findSummaryByCreator("user@domain.com");
System.out.println(summary);
Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for Bugzilla by integrating with the CData JDBC Driver for Bugzilla. Download a free trial and work with live Bugzilla data in custom Java applications today.