Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

演習

以下の演習では、Jalapeño を使用して単純な銀行業務アプリケーションを作成する手順について説明します。

手順 I

3 つの POJO クラス AccountAddress、および Customer を定義します。Jalapeño アノテーションを使用して、POJO クラスと Caché オブジェクト・スキーマの間の対応を定義します。以下のテーブルは POJO メンバと Caché メンバの関係を示しています。

Account
POJO Caché スキーマ

long number

Property number As %Integer

String type

Property type As %String

指定可能な値は、“checking” および “savings” です。

float balance

Property balance As %Float

Customer owner

Relationship owner As customer

Cardinality=one, inverse=accounts

この Caché Account スキーマは number にインデックスを持ちます。このインデックスは主キーです。

Address
POJO Caché スキーマ

String mCity

City As %String

String mState

State As %String

String mStreet

Street As %String

String mZip

Zip As %String

Caché Address クラスはシリアル (埋め込み可能) クラスです。

Customer
POJO Caché スキーマ

String idPlaceHolder

システムによって割り当てられたデータベース ID を表します。

 

Address primaryAddress

Property primaryAddress As address

String ssn

Property ssn As %String

指定可能な値は、3N1"-"2N1"-"4N1 のパターンに制限されています。

List <Account>accounts.

Relationship accounts As account

Cardinality=many, inverse=owner

この Caché Customer スキーマは ssn にインデックスを持ちます。このインデックスは主キーです。

手順 II

DBService という Java クラスを定義し、POJO の永続性を管理します。DBService は以下のメソッドを実装します。

DBService
メソッド 説明

saveCustomer

新規 Customer を挿入するか、既存の Customer を更新します。

allCustomers

データベース内のすべての Customer オブジェクトを表す一連の Customer POJO の反復子を返します。

customerByName

指定された name 値を持つデータベース・オブジェクトに対応する Customer POJO を返します。

customerBySSN

指定された ssn 値を持つデータベース・オブジェクトに対応する Customer POJO を返します。

手順 III

以下を実行する Java Test クラスを作成します。

  1. DBService saveCustomer メソッドを使用して複数の CustomerAccount、および Address オブジェクトをデータベースに追加します。

  2. DBService allCustomerscustomerByName、および customerBySSN メソッドをテストします。

Note:

サンプル・コードは、Caché の標準インストールに含まれています。これは、<cache-install>\dev\tutorials\pojo にあります。

FeedbackOpens in a new tab