本記事では CData サポート担当からこんなことを聞かれたらどこを確認すべきか?という観点で、よく頂くお問合せ内容をご紹介します。
記事はこちら →JDBI は、Fluent スタイルとSQL オブジェクトスタイルという2つの異なるスタイルAPI を公開する、Java 用のSQL コンビニエンスライブラリです。CData JDBC Driver for AAS は、Java アプリケーションとリアルタイムAzure Analysis Services data のデータ連携を実現します。これらの技術を組み合わせることによって、Azure Analysis Services data へのシンプルなコードアクセスが可能になります。ここでは、基本的なDAO(Data Access Object )とそれに付随するAzure Analysis Services data の読み書きのためのコードの作成について説明します。
以下のインターフェースは、実装されるSQL ステートメントごとに単一のメソッドを作成するためのSQL オブジェクトの正しい動作を宣言します。
public interface MyCustomerDAO {
//request specific data from Azure Analysis Services (String type is used for simplicity)
@SqlQuery("SELECT Education FROM Customer WHERE Country = :country")
String findEducationByCountry(@Bind("country") String country);
/*
* close with no args is used to close the connection
*/
void close();
}
必要な接続プロパティを収集し、Azure Analysis Services に接続するための適切なJDBC URL を作成します。
To connect to Azure Analysis Services, set the Url property to a valid server, for instance, asazure://southcentralus.asazure.windows.net/server, in addition to authenticating. Optionally, set Database to distinguish which Azure database on the server to connect to.
Azure Analysis Services uses the OAuth authentication standard. OAuth requires the authenticating user to interact with Azure Analysis Services using the browser. You can connect without setting any connection properties for your user credentials. See the Help documentation for more information.
JDBC URL の構成については、Azure Analysis Services JDBC Driver に組み込まれている接続文字列デザイナーを使用してください。JAR ファイルのダブルクリック、またはコマンドラインからJAR ファイルを実行します。
java -jar cdata.jdbc.aas.jar
接続プロパティを入力し、接続文字列をクリップボードにコピーします。
Azure Analysis Services の接続文字列は、通常次のようになります。
jdbc:aas:URL=asazure://REGION.asazure.windows.net/server;InitiateOAuth=GETANDREFRESH
構成済みのJDBC URL を使用して、DAO インターフェースのインスタンスを取得します。以下に示す特定のメソッドはインスタンスにバインドされたハンドルを開くため、ハンドルとバインドされたJDBC 接続を開放するには、インスタンスを明示的に閉じる必要があります。
DBI dbi = new DBI("jdbc:aas:URL=asazure://REGION.asazure.windows.net/server;InitiateOAuth=GETANDREFRESH");
MyCustomerDAO dao = dbi.open(MyCustomerDAO.class);
//do stuff with the DAO
dao.close();
Azure Analysis Services への接続を開いた状態で以前定義したメソッドを呼び出すだけで、Azure Analysis Services のCustomer エンティティからデータを取得できます。
//disply the result of our 'find' method
String education = dao.findEducationByCountry("Australia");
System.out.println(education);
JDBI ライブラリはJDBC 接続を処理できるため、CData JDBC Driver for AAS と統合することで、SQL Object API for AAS を簡単に作成できます。今すぐ無料トライアルをダウンロードし、Java アプリケーションでライブAzure Analysis Services を操作しましょう。