JDBI でBusiness b-ridge data 用のSQL オブジェクトAPIを作成する方法を概説します。
JDBI は、Fluent スタイルとSQL オブジェクトスタイルという2つの異なるスタイルAPI を公開する、Java 用のSQL コンビニエンスライブラリです。CData JDBC Driver for Business b-ridge は、Java アプリケーションとリアルタイムBusiness b-ridge data のデータ連携を実現します。これらの技術を組み合わせることによって、Business b-ridge data へのシンプルなコードアクセスが可能になります。ここでは、基本的なDAO(Data Access Object )とそれに付随するBusiness b-ridge data の読み書きのためのコードの作成について説明します。
Business b-ridge CDATA Entity のDAO を作成
以下のインターフェースは、実装されるSQL ステートメントごとに単一のメソッドを作成するためのSQL オブジェクトの正しい動作を宣言します。
public interface MyCDATADAO {
//request specific data from Business b-ridge (String type is used for simplicity)
@SqlQuery("SELECT StructureId FROM CDATA WHERE ItemTypeId = :itemTypeId")
String findStructureIdByItemTypeId(@Bind("itemTypeId") String itemTypeId);
/*
* close with no args is used to close the connection
*/
void close();
}
Business b-ridge への接続を開く
必要な接続プロパティを収集し、Business b-ridge に接続するための適切なJDBC URL を作成します。
When connecting to Business b-ridge, CompanyKey, ProjectKey, and SubscriptionKey are required.
To obtain the SubscriptionKey, follow the steps below:
- Log in to Business b-ridge API Protal and go to "Profile" in the "Your name" menu.
- In your subscription section click "Main Key" to retrieve their respective values.
Authenticate to Business b-ridge Account
Set the following connection properties to connect:
- CompanyKey: Set the Business b-ridge Company Key of the connection destination.
- ProjectKey: Set the Business b-ridge Project Key of the connection destination.
- SubscriptionKey: Set the value "Subscription Key".
ビルトイン接続文字列デザイナー
JDBC URL の構成については、Business b-ridge JDBC Driver に組み込まれている接続文字列デザイナーを使用してください。JAR ファイルのダブルクリック、またはコマンドラインからJAR ファイルを実行します。
java -jar cdata.jdbc.businessbridge.jar
接続プロパティを入力し、接続文字列をクリップボードにコピーします。

Business b-ridge の接続文字列は、通常次のようになります。
jdbc:businessbridge:InitiateOAuth=GETANDREFRESH
構成済みのJDBC URL を使用して、DAO インターフェースのインスタンスを取得します。以下に示す特定のメソッドはインスタンスにバインドされたハンドルを開くため、ハンドルとバインドされたJDBC 接続を開放するには、インスタンスを明示的に閉じる必要があります。
DBI dbi = new DBI("jdbc:businessbridge:InitiateOAuth=GETANDREFRESH");
MyCDATADAO dao = dbi.open(MyCDATADAO.class);
//do stuff with the DAO
dao.close();
Business b-ridge Data について
Business b-ridge への接続を開いた状態で以前定義したメソッドを呼び出すだけで、Business b-ridge のCDATA エンティティからデータを取得できます。
//disply the result of our 'find' method
String structureId = dao.findStructureIdByItemTypeId("1");
System.out.println(structureId);
JDBI ライブラリはJDBC 接続を処理できるため、CData JDBC Driver for Business b-ridge と統合することで、SQL Object API for Business b-ridge を簡単に作成できます。今すぐ無料トライアルをダウンロードし、Java アプリケーションでライブBusiness b-ridge を操作しましょう。