機械翻訳について

単一行の取得による存在のテスト

少なくとも1つの行が特定の基準に一致するかどうかを確認する必要がある場合は、最適なパフォーマンスを得るには、主キー・フィールドと結果の最初の行のみを選択します。 nullでない場合、存在テストは成功します。

オブジェクト関数: Boolean employeeExistsInDepartmentWithJob( Long department, String jobCode)

def employees = newView('StaffMember')
addBindVariable(employees,'Job','Text')
addBindVariable(employees,'Dept','Number')
// Make sure that either JobId or DepartmentId is indexed!
employees.appendViewCriteria('JobId = :Job and DepartmentId = :Dept')
// Retrieve only the primary key field
selectAttributesBeforeQuery(employees,['EmployeeId'])
setBindVariable(employees,'Job',jobCode)
setBindVariable(employees,'Dept',department)
employees.executeQuery()
// Retrieve just the first row!
return employees.first() != null

「ビジネス・ロジック問合せの簡略化」で説明されているqueryMap()またはqueryRow()ヘルパー関数を使用すると、前述の例で同じ最適化された問合せを実行でき、次のようなコード行が少なくなります:

オブジェクト関数: Boolean employeeExistsInDepartmentWithJob( Long department, String jobCode)
// Retrieve only the primary key field and just the first row
return adf.util.queryRow(select:'EmployeeId',
                           from: 'StaffMember',
                          where: 'JobId = :Job and DepartmentId = :Dept',
                          binds:[Job:jobCode,Dept:department]) != null
employeeExistsInDepartmentWithJob()ヘルパー関数を設定すると、StaffMemberオブジェクトのビジネス・ロジックは次のように使用できます:
if (employeeExistsInDepartmentWithJob(50,'SH_CLERK')) { /* etc. */ }