Jetty の接続プールから Foursquare のデータ に接続
CData JDBC Driver for Foursquare は、Java Web アプリケーションへの統合が簡単です。この記事では、接続プールを設定することで Jetty から Foursquare のデータ に効率的に接続する方法を説明します。Jetty で Foursquare 用の JNDI リソースを設定していきましょう。
Salesforce 用の JDBC Driver を JNDI データソースとして設定
以下のステップで Jetty から Salesforce に接続します。
Jetty ベースで JNDI モジュールを有効にします。次のコマンドは、コマンドラインから JNDI を有効にします。
java -jar ../start.jar --add-to-startd=jndi
- インストールディレクトリの lib サブフォルダにある CData およびライセンスファイルを、コンテキストパスの lib サブフォルダに追加します。
-
リソースとそのスコープを宣言します。リソース宣言に必要な接続プロパティを入力します。次の例では、WEB-INF\jetty-env.xml に Web アプリレベルで Foursquare データソースを宣言しています。
<Configure id='foursquaredemo' class="org.eclipse.jetty.webapp.WebAppContext"> <New id="foursquaredemo" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg><Ref refid="foursquaredemo"/></Arg> <Arg>jdbc/foursquaredb</Arg> <Arg> <New class="cdata.jdbc.api.APIDriver"> <Set name="url">jdbc:api:</Set> <Set name="Profile">C:\profiles\Foursquare.apip</Set> <Set name="AuthScheme">APIKey</Set> <Set name="ProfileSettings">'APIKey</Set> </New> </Arg> </New> </Configure>API キー認証の設定
Foursquare Places API は Service Key(Bearer トークン)認証を使用します。Service Key を取得するには、以下のステップで進めます:
- https://foursquare.com/developers/ の Foursquare Developer Console にアクセスします
- 新しいプロジェクトを作成するか、既存のプロジェクトを選択します
- API Keys セクションに移動します
- Places API 用に新しい Service Key を生成します
以下の接続プロパティを設定して接続を確立してください:
- AuthScheme:APIKey に設定します。
- ServiceKey:Developer Console から取得した Foursquare の Service Key に設定します。
- XPlacesApiVersion:(オプション)API バージョンの日付に設定します。デフォルトは 2025-06-17 です。
API キー接続文字列の例
Profile=C:\profiles\Foursquare.apip;AuthScheme=APIKey;ProfileSettings='APIKey=your_personal_access_token';
-
Web.xml でリソースを設定します。
jdbc/foursquaredb javax.sql.DataSource Container
-
これで、java:comp/env/jdbc/foursquaredb をルックアップして Foursquare にアクセスできます。
InitialContext ctx = new InitialContext(); DataSource myfoursquare = (DataSource)ctx.lookup("java:comp/env/jdbc/foursquaredb");
Jetty 統合の詳細
上記のステップでは、シンプルな接続プールのシナリオでドライバーを設定する方法を説明しました。その他のユースケースや詳細については、Jetty ドキュメントのWorking with Jetty JNDI の章を参照してください。