Showing posts with label Entity Object. Show all posts
Showing posts with label Entity Object. Show all posts

Monday, July 4, 2011

Bit #31 - Making an Entity object read-only

There are a few different ways to make an Entity object read-only, both declaratively in JDeveloper or programmatically via the ADF Business Components API. One that is suggested in OTN thread http://forums.oracle.com/forums/thread.jspa?threadID=2247578&tstart=0 is to change in the Entity's General section the Entity's Updatable property from true (the default) to false. This property can be found under the Type section in the Property Inspector.


By changing it to false, the Entity will not be updatable for all Entity-based View objects that use it. Note however that JDeveloper will still show the Entity reference as being Updatable in the View object Entity Objects page. This seems to be a bug in JDeveloper.

Some of the other ways to make the Entity read only would be to uncheck the Updatable checkbox for each View object that uses the Entity object (in the Entity Objects section), to use the isAttributeUpdatable() API to return false for all attributes or even at the attribute level to set each attribute's Updatable property to Never.

Context:
Entity Objects

Wednesday, July 14, 2010

Bit #22 - Using getPostedAttribute() to determine the posted attribute's value

Call getPostedAttribute() anywhere in your Entity Object implementation class to retrieve the posted value of an Entity attribute. The example below calls getPostedAttribute() and getAttribute() to determine the attribute value in the database (posted) and in the Entity cache (not posted yet) respectively. They are called from within an overridden doDML(). Then based on the result of comparing them, certain business logic decisions can be made. Note that we call getPostedAttribute() before calling super.doDML(). This is done because calling super.doDML() will in effect post the attribute value in the Entity cache to the database, so will not make much sense to compare them afterwards: They will be the same!

Example:

    // in your Entity Object Implementation class

    @Override
    protected void doDML(int operation, TransactionEvent e) {

        final String EMPLOYEE_ID = "EmployeeId";
      
        // get posted value of EmployeeId attribute
        Object postedEmployeeId = getPostedAttribute(this.getAttributeIndexOf(EMPLOYEE_ID));
      
        // get value of EmployeeId before re-posting
        Object employeeId = this.getAttribute(EMPLOYEE_ID);
      
        // compare and take some action based on the results of comparison
        if (employeeId != null && employeeId.equals(postedEmployeeId)) {
          // do something here
        }
      
        // finally re-post by calling super.doDML()
        super.doDML(operation, e);
    }


Context

Entity Object Implementation Class
Related Posts Plugin for WordPress, Blogger...