- Oracle JDeveloper 11gR2 Cookbook
- Nick Haralabidis
- 368字
- 2021-08-20 15:53:04
Using getPostedAttribute() to determine the posted attribute's value
There are times when you need to get the original database value of an entity object atttribute, such as when you want to compare the attribute's current value to the original database value. In this recipe, we will illustrate how to do this by utilizing the getPostedAttribute()
method.
Getting ready
We will be working on the SharedComponets
workspace. We will add a helper method to the custom entity framework class.
How to do it...
- Start by opening the
SharedComponets
workspace. If needed, follow the steps in the referenced recipe to create it. - Locate the custom entity framework class and open it into the source editor.
- Add the following code to the custom entity framework class:
/** * Check if attribute's value differs from its posted value * @param attrIdx the attribute index * @return */ public boolean isAttrValueChanged(int attrIdx) { // get the attribute's posted value Object postedValue = getPostedAttribute(attrIdx); // get the attribute's current value Object newValue = getAttributeInternal(attrIdx); // return true if attribute value differs from its posted value return isAttributeChanged(attrIdx) &&((postedValue == null && newValue != null) ||(postedValue != null && newValue == null) ||(postedValue != null && newValue != null &&!newValue.equals(postedValue))); }
How it works...
We added a helper method called isAttrValueChanged()
to the our custom entity framework class. This method accepts the attribute's index. The attribute index is generated and maintained by JDeveloper itself. The method first calls getPostedAttribute()
specifying the attribute index to retrieve the attribute value that was posted to the database. This is the attribute's database value. Then it calls getAttributeInternal()
using the same attribute index to determine the current attribute value. The two values are then compared. The method isAttributeChanged()
returns true
if the attribute value was changed in the current transaction.
The following is an example of calling isAttrValueChanged()
from an entity implementation class to determine whether the current value of the employee's last name differs from the value that was posted to the database:
super.isAttrValueChanged(this.LASTNAME);
- 實戰(zhàn)Java程序設計
- 數(shù)據(jù)結(jié)構(gòu)案例教程(C/C++版)
- 精通Python自動化編程
- 從Java到Web程序設計教程
- NetBeans IDE 8 Cookbook
- HTML 5與CSS 3權(quán)威指南(第3版·上冊)
- Spring Boot+MVC實戰(zhàn)指南
- JavaScript動態(tài)網(wǎng)頁編程
- Oracle數(shù)據(jù)庫編程經(jīng)典300例
- Serverless Web Applications with React and Firebase
- 并行編程方法與優(yōu)化實踐
- C#面向?qū)ο蟪绦蛟O計(第2版)
- Akka入門與實踐
- Python Social Media Analytics
- 百萬在線:大型游戲服務端開發(fā)