エンティティセレクション内のエンティティの処理

Deeplからの自動翻訳

FIRST RECORDLAST RECORDNEXT RECORDPREVIOUS RECORD、思い当たる節はありませんか?きっとそうだろう。あなたはすでにこれらのメソッドを使用して選択を行っているはずです。ORDAは、エンティティセレクションでエンティティをナビゲートするための便利でよく知られたメソッドを提供します。

まず、通常はテーブルごとに1つの「カレントセレクション」しか管理できないのに対し、複数のエンティティセレクションを同時に処理し、それらを 独立してナビゲートすることができます。このブログでは、まさにこの点を説明します。

データストアに問い合わせると、エンティティセレクションが返されることは既に説明しました。ORDAはエンティティセレクション内のエンティティに非常に簡単にアクセスする手段を提供します。

ORDAはエンティティセレクションのエンティティを処理する

エンティティセレクションの作成と充填

空のエンティティセレクションを作成するには newSelection()メソッドで作成します。また、エンティティをそれに追加するには add()メソッドで追加することもできます。

C_OBJECT

($employee;$es)
C_TEXT ($name)

//Create a new empty entity selection $es :=ds.Employee.newSelection()
Repeat $name :=Request("Which employee?")
If (ok=1)
//Get the first employee whose last name is $name
$employee :=ds.Employee.query("lastName=:1";$name).first
()
//Add the entity to the new entity selection $es
If ($employee#Null)
$es .add($employee)
End if
End if Until (ok=0)
alert (String($es.length) + " 従業員は新しいエンティティ選択に追加されました")

エンティティセレクションのエンティティにアクセスする

を使用すると、エンティティセレクション内のエンティティを繰り返し処理することができます。 for eachループを使用します。以下に簡単な例を示しますが、このブログ記事もご覧ください。

C_OBJECT($employeesParis;$employee;$status)

// Get employees working in Paris
$employeesParis :=ds.Employee.query("city='Paris'")
//Iterate through each employee
For each ($employee;$employeesParis)
$employee.lastName:=Uppercase($employee.lastName)
$status:=$employee.save()
End for each

また、インデックスを持つエンティティをエンティティセレクションに読み込むこともできます(インデックスは0から始まります)。以下はその例です。

C_OBJECT($gamers)
//Get all the gamers sorted by rank
$gamers :=ds.Gamer.all().orderBy("rank")
if ($gamers.length >=3)
ALERT ("The first three are:"+Char(13) \
+$gamers[0].lastName+Char(13)+$gamers[1]
lastName+Char(13)+$gamers[2]lastName)
End if

最初と最後のエンティティ

この例では first()last()メソッドを使用すると、 エンティティ選択の最初と最後のエンティティを取得することができます。これらのメソッドは、エンティティセレクションが空の場合、Null を返すことがあります。

以下の例では、$gamers のエンティティセレクションで最初のエンティティを取得します。

C_OBJECT// Get the first entity of the $gamers entity selection ($gamers;$first)
// Get the gamers whose last name starts with "H"
$gamers :=ds.Gamer.query("lastName='H@'")

$first :=$gamers.first()
If ($first#Null)
ALERT ("The first gamer has been found")
Else
ALERT ("the entity selection $gamers is empty")
End if

前のエンティティ、次のエンティティ

エンティティは、エンティティ選択に属することもあります。この場合は previous()next()メソッドを使用します。

この例では、ゲーマーのリストを表示するためにフォームを使用しています。ユーザーは、Previous Nextボタンを使って各ゲーマーの詳細について移動することができます。

Nextボタンは次のオブジェクトメソッドを持っています。

//Form.gamer is an entity, edited on the form. It belongs to an entity selection which is the entire list of gamers.
If ( . . ()# ) . := . . () FormgamernextNull
//Edit the next entity of the entity selection to which the Form.gamer entity belongs.
FormgamerFormgamernext
End if

エンティティに関する情報

これだけではありません。任意のエンティティについて、それが由来するエンティティセレクションを取得することができます。例えば、あるエンティティがあるエンティティセレクションに属しているかどうか、あるエンティティセレクションでの位置を取得する、などです。

ここでは、2 つのエンティティ選択 ($employeesParis$employeesNY) があります。selectedEmployeeメソッドは、そのうちの 1 つに含まれる従業員を選択します。次に、 この従業員がどちらのエンティティセレクションに属しているかを contains()メソッドで判断できます。

C_OBJECT
// The method selectedEmployee returns an employee in one of the two given entity selections ($employeesParis;$employeesNY;$employee)
// Get employees working in Paris
$employeesParis :=ds.Employee.query("city='Paris'")
// Get employees working in New York $employeesNY :=ds.Employee.query("city='New York'")

$employee :=selectedEmployee($employeesParis;$employeesNY)

Case of
: ($employeesParis.contains($employee))
ALERT ("この従業員はエンティティ選択 $employeesParis に所属しています")
: ($employeesNY.contains($employee))
ALERT ("この従業員はエンティティセレクション $employeesNY に所属しています")
End case

 

ここでは、エンティティセレクション($employeesParis)があります。selectedEmployeeメソッドは、その中から従業員を選択します。エンティティセレクションにおける従業員のインデックスを 取得するには、次のメソッドを使用します。 indexOf()メソッドで取得できます。

C_OBJECT // The method selectedEmployee returns an employee in the given entity selection($employeesParis;$employee)
// Get employees working in Paris
$employeesParis :=ds.Employee.query("city='Paris'")

$employee :=selectedEmployee ($employeesParis)
ALERT ("The index of the selected employee is " +String($employee.indexOf()))

データベースの例を見れば、このテーマについてすべてわかるはずです!

Avatar
- プロダクトオーナー - Marie-Sophie Landrieu-Yvertは、2017年にプロダクトオーナーとして4Dプロダクトチームに参加しました。プロダクトオーナーとして、彼女はユーザーストーリー(ユーザーが期待する新機能とその使用法)を書き、それを具体的な機能仕様に変換する役割を担っています。また彼女の役割は、実装された機能が顧客のニーズを満たしているかどうかを確認することでもあります。彼女は1995年にESIGELEC Engineering Schoolを卒業し、IBMでエンジニアとしてのキャリアをスタートさせました。様々なプロジェクト(保守や新規のプロジェクト)に参加し、Cobolのデベロッパーとして働きました。その後、UMLデザイナーおよびJavaデベロッパーとして勤務。最近は、機能要件の分析・記述、ビジネスチームと開発チームの調整などを主に担当しています。