- Oracle JDeveloper 11gR2 Cookbook
- Nick Haralabidis
- 392字
- 2021-08-20 15:53:05
Using doDML() to enforce a detail record for a new master record
In this recipe, we will consider a simple technique that we can use to enforce having detailed records when inserting a new master record in an entity association relationship. The use case demonstrates how to enforce creating at least one employee at the time when a new department is created.
Getting ready
We will use the HR
database schema and the HRComponents
workspace that we have created in previous recipes in this chapter.
How to do it...
- Open the
DepartmentImpl
custom entity implementation class and override thedoDML()
method using the Override Methods dialog. - Add the following code to the
doDML()
method before the call tosuper.doDML()
:// check for insert if (DML_INSERT == operation) { // get the department employees accessor RowIterator departmentEmployees = this.getDepartmentEmployees(); // check for any employees if (!departmentEmployees.hasNext()) { // avoid inserting the department if there are no employees for it throw new ExtJboException("00006"); } }
How it works...
In the overridden doDML()
, we only check for insert operations. This is indicated by comparing the DML operation
flag which is passed as a parameter to doDML()
to the DML_INSERT
flag. Then we get the department employees from the DepartmentEmployees
accessor by calling getDepartmentEmployees()
. The DepartmentEmployees
accessor was set up during the creation of the HRComponents
workspace earlier in this chapter. We check whether the RowIterator
returned has any rows by calling hasNext()
on it. If this is not the case, that is, there are no employees associated with the specific department that we are about to insert, we alert the user by throwing an ExtJboException
exception. The ExtJboException
exception is part of the SharedComponets
workspace and it was developed in the Using a custom exception class recipe back in Chapter 1, Pre-requisites to Success: ADF Project Setup and Foundations.
When testing the application module with the ADF Model Tester, we get the following error message when we try to insert a new department without any associated employees:

- Android應用程序開發(fā)與典型案例
- C語言程序設計(第3版)
- 編程珠璣(續(xù))
- Web Application Development with R Using Shiny(Second Edition)
- MATLAB定量決策五大類問題
- iOS編程基礎:Swift、Xcode和Cocoa入門指南
- 速學Python:程序設計從入門到進階
- The Professional ScrumMaster’s Handbook
- Scratch3.0趣味編程動手玩:比賽訓練營
- Python項目實戰(zhàn)從入門到精通
- Node.js開發(fā)指南
- Spring技術內(nèi)幕:深入解析Spring架構與設計原理(第2版)
- 零基礎學C語言(升級版)
- Python計算機視覺和自然語言處理
- C語言編程魔法書:基于C11標準