JDBI からFinancialForce Data のデータアクセスオブジェクトを作成

JDBI でFinancialForce data 用のSQL オブジェクトAPIを作成する方法を概説します。

JDBI は、Fluent スタイルとSQL オブジェクトスタイルという2つの異なるスタイルAPI を公開する、Java 用のSQL コンビニエンスライブラリです。CData JDBC Driver for FinancialForce は、Java アプリケーションとリアルタイムFinancialForce data のデータ連携を実現します。これらの技術を組み合わせることによって、FinancialForce data へのシンプルなコードアクセスが可能になります。ここでは、基本的なDAO(Data Access Object )とそれに付随するFinancialForce data の読み書きのためのコードの作成について説明します。

FinancialForce Account Entity のDAO を作成

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 MyAccountDAO { //insert new data into FinancialForce @SqlUpdate("INSERT INTO Account (Industry, Name) values (:industry, :name)") void insert(@Bind("industry") String industry, @Bind("name") String name); //request specific data from FinancialForce (String type is used for simplicity) @SqlQuery("SELECT Name FROM Account WHERE Industry = :industry") String findNameByIndustry(@Bind("industry") String industry); /* * close with no args is used to close the connection */ void close(); }

FinancialForce への接続を開く

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to FinancialForce.

There are several authentication methods available for connecting to FinancialForce: login credentials, SSO, and OAuth.

Authenticating with a Login and Token

Set the User and Password to your login credentials. Additionally, set the SecurityToken. By default, the SecurityToken is required, but you can make it optional by allowing a range of trusted IP addresses.

To disable the security token:

  1. Log in to FinancialForce and enter "Network Access" in the Quick Find box in the setup section.
  2. Add your IP address to the list of trusted IP addresses.

To obtain the security token:

  1. Open the personal information page on FinancialForce.com.
  2. Click the link to reset your security token. The token will be emailed to you.
  3. Specify the security token in the SecurityToken connection property or append it to the Password.

Authenticating with OAuth

If you do not have access to the user name and password or do not want to require them, use the OAuth user consent flow. See the OAuth section in the Help for an authentication guide.

Connecting to FinancialForce Sandbox Accounts

Set UseSandbox to true (false by default) to use a FinancialForce sandbox account. Ensure that you specify a sandbox user name in User.


For assistance in constructing the JDBC URL, use the connection string designer built into the FinancialForce JDBC Driver.Either double-click the JAR file or execute the jar file from the command-line.

java -jar cdata.jdbc.financialforce.jar

Fill in the connection properties and copy the connection string to the clipboard.

A connection string for FinancialForce will typically look like the following:

jdbc:financialforce:User=myUser;Password=myPassword;Security Token=myToken;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:financialforce:User=myUser;Password=myPassword;Security Token=myToken;InitiateOAuth=GETANDREFRESH"); MyAccountDAO dao = dbi.open(MyAccountDAO.class); //do stuff with the DAO dao.close();

FinancialForce Data について

With the connection open to FinancialForce, simply call the previously defined method to retrieve data from the Account entity in FinancialForce.

//disply the result of our 'find' method String name = dao.findNameByIndustry("Floppy Disks"); System.out.println(name);

FinancialForce Data の書き方

It is also simple to write data to FinancialForce, using the previously defined method.

//add a new entry to the Account entity dao.insert(newIndustry, newName);

Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for FinancialForce by integrating with the CData JDBC Driver for FinancialForce.Download a free trial and work with live FinancialForce data in custom Java applications today.