Basics
of ADF EO and VO classes
Entity
Object :
Entity
objects in ADF are business components that encapsulate the business
model, including data, rules, and persistence behavior, for items
that are used in your application.
Entity
objects can represent:
- Elements of the logical structure of the business, such as product lines, departments, sales, and regions.
- Business documents, such as invoices, change orders, and service requests
- Physical items, such as warehouses, employees, and equipment .
Entity object definitions comprise three Java classes:
- The entity
collection class -
an instance of this class represents the collection
of rows currently in
memory for a single user.
- The entity definition class - the singleton instance of this class represents represents the entire data source object.
- The entity object class - an instance of this class (an entity object instance) represents a single row from the data source.Entity object class : (EOImpl)It basically has following methods:
- Accessors.(setters and getters)
- Create Method
- Data Manipulation method.(doDML(int operation, TransactionEvent e))
- Remove method
Other
important EOImpl class methods are:
setAttrInvokeAccessor(),getAttrInvokeAccessor(),createPrimaryKey()
and lock().
Accessors:
Attributes
in Entity Objects can be of two types:
- Persistent attributes : Maps to the data source object columns.
- Transient attributes : Doesn't map to any data source object,used mainly for temporary storage and retrieval or simple calculations.
EOImpl
class contains getters and setters for all the attributes in EO, so
they can be accessed and changed as required.
Eg:
getAttribute("Deptno")
or setAttribute("Deptno","10")
.
doDML():
This
method is invoked whenever the commit operation is performed.
protected void doDML(int operation, TransactionEvent e) {
if (operation == DML_INSERT) {
/* write PRE-INSERT trigger-like code here */
super.doDML(operation, e); /* Don't call the super and do something
else to write ON-INSERT trigger-like code */
/* write POST-INSERT trigger-like code here */
}
else if (operation == DML_UPDATE) {
/* write PRE-UPDATE trigger-like code here */
super.doDML(operation, e); /* Don't call the super and do something
else to write ON-UPDATE trigger-like code here */
/* write POST-UPDATE trigger-like code here */
}
else if (operation == DML_DELETE) {
/* write PRE-DELETE trigger-like code here */
super.doDML(operation, e); /* Don't call the super and do something
else to write ON-DELETE trigger-like code here */
/* write POST-DELETE trigger-like code here */
}
}
Eg:
//in EmpEOimpl's doDML(), after creating a row for Emp table,we are
inserting a new row for Department table.
protected void doDML(int operation, TransactionEvent e) {
super.doDML(operation,e);
//after insert operation is done
if(operation==1){
EntityDefImpl dept=DepartmentEOImpl.getDefinitionObject();
DepartmentEOImpl newd= (DepartmentEOImpl)dept.createInstance2(getDBTransaction(), null);
newd.setDepartmentId(c);
newd.setDepartmentName("Finance"+b.toString());
}
}
Note:Don't
set the attributes of same EO after calling super.doDML() ,else it
throws JBOexception : Post threshold limit reached. Some entities yet
to be posted.
EOImpl
class methods:
- protected void prepareForDML(int i, TransactionEvent transactionEvent) {}
A pre-notification for preparing rows for posting to DB. If you need to update some dependency columns
or custom history columns then add that logic here.
- Method calls doDML() at the end.
- protected void doDML(int i, TransactionEvent transactionEvent) {}
- Does the DML operation. This is where everything gets into the DB. All the INSERT, UPDATE, and DELETE statements for a row executes here.
- public void beforeCommit(TransactionEvent transactionEvent) {}
Reports that a commit operation has initiated
- Invoked before commit is called. By this time the changes are already present in the DB. So any logic that needs updated data in the DB can be written in this method.
- public void afterCommit(TransactionEvent transactionEvent) {}
Reports that a successful commit operation has occurred.
- protected void validateEntity() {}
- Call executes the entity level validations defined on the EO. Gets invoked when use moves from one row to another.
- public void lock() {}
Locks the row.
- Executes a SELECT FOR UPDATE based on the DML operations, for eg like UPDATE or DELETE
- protected void create(AttributeList attributeList) {}
- Apart from declarative defaulting override the method to have custom creation and defaulting logic for attributes.
- public void remove() {}
- For delete operation.
- public void postChanges(TransactionEvent transactionEvent) {}
- Calls prepareForDML and later doDML to post the changes to DB. Its only after the method's execution data changes are available in the DB before being committed. If application need some PL/SQL or any procedure to be invoked with updated data they can do it here after super or in doDML as needed.
- public boolean isAttributeUpdateable(int i) {}
- Returns true if the attribute is update able. Override the method to define own logic, to whether an attribute is updateable or not apart from default WHILE_NEW, NEVER or ALWAYS. The super.isAttributeUpdateable() returns the declarative setting.
- Eg: Lets say Commission is updateable only when Salary is greater than 5000.This cannot be declaratively achieved. One can write that logic here.
- <Pseudo Code>
if(index==comm)
return this.getSal()!=null && this.getSal().doubleValue()>5000
else
return super.isAttributeUpdateable(index) //Default setting for the rest
- protected void setAttributeInternal(int p1, java.lang.Object p2) { }
- Triggers attribute level validations. One can see that every attribute setter has setAttributeInternal; It's because of this call the attribute level validations get fired.
- protected void populateAttribute(int i, Object object) {}
- Use it to set attribute value by skipping any attribute level validations. The default setAttribute() fires validation after value is set and does not update the target value if any validation fails.
- protected void populateAttributeAsChanged(int i, Object object) {}
- Same as above but instructs the framework that the attributes value has changed.
View
Object:
ViewObject
decribes how the application will view and update data. A View Object
may be Entity based or non-Entity based.
View
objects are business components that collect data from the
datasource, shape that data for use by clients, and allow clients to
change that data in the Oracle ADF Business Components cache. For
example, a view object can gather all the information needed to:
- Populate a single table element in a form
- Create and process an insert or edit form
- Create an LOV for
populating a dropdown list
View Object can be
customized on the basis of its Java classes which can be generated:
(i)View
Object Class (VOImpl) -
an
instance of this class is a view object instance; that is, a
particular reference to a Oracle ADF view object definition within an
application module definition.
(ii)View
Row Class(VORowImpl) -
an
instance of this class represents a single row returned by the view
object's mechanism.
VOImpl
methods:
- protected ViewRowImpl createRowFromResultSet(Object object,ResultSet resultSet) {}
- Executed after the VO SQL query runs.Its here the query result set is iterated and each result is split and pushed to respective entity cache.Override to run any logic to default attribute values based on PL/SQL functions or any other logic after query is executed.One can also create SQL derived attributes for simple SQL procedure or function invocation for an attribute.
- public void beforeCommit(TransactionEvent transactionEvent) {}
- Invoked before commit is called. By this time the changes are already present in the DB.So any logic that needs updated data in the DB can be writtern here.
- public void afterCommit(TransactionEvent transactionEvent) {}
Reports that a successful commit operation has occurred.
- public void postChanges(TransactionEvent transactionEvent) {}
- Calls prepareForDML and later doDML to post the changes to DB.Its only after the method's execution data changes are available in the DB before being committed. If apps need some PL/SQL or any procedure to be invoked with updated data they can do it here after super or in doDML as needed.
- public boolean isAttributeUpdateable(int i) {}
- Same as in EOImpl class.
- public RowSet createRowSet(String string) {}
- A rowset is a memory representation for the VO rows. One can create a row set to iterate over rows and access row attributes. ADF has a default rowset and a default rowset iterator. It's always recommended to create one's own rowset and rowset iterator to process rows than manipulating the default rowset. To avoid memory leaks always close rowset and its iterator after processing.
- public RowSetIterator createRowSetIterator(String string) {}
- Creates a row set iterator. This iterator is created on the default row set. Always create a custom rowset and create iterator with the custom rowset . To avoid memory leaks always close rowset and its iterator after processing.
- public Row getCurrentRow() {}
- The call is primarily routed to default rowset and returns the current selected row. The default rowset is used for UI row currency (meaning current selected row).
- protected void create() {}
- Call to create a new row. Any modification for any attribute on call to CREATEINSERT or CREATE can be done here. For eg: Serial No. auto-generation .
- public Row createRow() {}
- Call to create a new row in the VO.
ViewRowImpl
methods:
- public
void validate() {}
- Internally invokes validate for corresponding entities.
- protected void setAttributeInternal(int p1, java.lang.Object p2) { }
- Same behavior as in Eoimpl class.
- public boolean isAttributeUpdateable(int i) {}
- Same behavior as in EO
No comments:
Post a Comment