Date Effective property of VO.
Some time we have come to scenarios when the validatity of the row is dependent over a column value of date type.
A typical example of this is contractual employees, if the contract date is over we may not be interested these employees for the payrole. ADF provides a property effective date for this use case. Its quite easy to implement and in the VO by just setting a flag we can ignore these rows.
For this example we are using default HR schema of the XE database, we will create a new table as the existing table does not solve our purpose.
create table CONTRATUAL_EMP as select * from employees;
alter table CONTRATUAL_EMP add (CONTRACT_END_DATE DATE);
update CONTRATUAL_EMP set CONTRACT_END_DATE = sysdate -10
where mod(employee_id,2) =0;
update CONTRATUAL_EMP set CONTRACT_END_DATE = sysdate + 200
where mod(employee_id,2) =1;
commit;
Now table is ready, We are moving to to project. please download the project from the link.
A typical example of this is contractual employees, if the contract date is over we may not be interested these employees for the payrole. ADF provides a property effective date for this use case. Its quite easy to implement and in the VO by just setting a flag we can ignore these rows.
For this example we are using default HR schema of the XE database, we will create a new table as the existing table does not solve our purpose.
create table CONTRATUAL_EMP as select * from employees;
alter table CONTRATUAL_EMP add (CONTRACT_END_DATE DATE);
update CONTRATUAL_EMP set CONTRACT_END_DATE = sysdate -10
where mod(employee_id,2) =0;
update CONTRATUAL_EMP set CONTRACT_END_DATE = sysdate + 200
where mod(employee_id,2) =1;
commit;
Now table is ready, We are moving to to project. please download the project from the link.
Open this project and then run the page DisplayResult.jpx. Now click the search button and it will display only the empId which are odd.
Implementation Steps.
1. Marking the start date and end date
The entity ContractualEmpEO is base on the new table which we have just created, in it we have to mark two date columns which will be used effective date as its start and end date. I have used Hiredate as start date and ContractEndDate as end date, apart from this we need to mark both the column as the key attributes.
The ContractualEmpVO is based on the entity ContractualEmpEO. To make this VO as effective dated VO we need to set the effective dated property of this VO to true.
Now any query run over the vo will not display the employee for which the contractual date has been passed.
Rest of the steps are simple, just created a QueryCriteria FindByCntrlEmp which is been displayed in the page to query the employees.
Simple Words...
All the above steps will append/add a where clause to VO query which will be like
sysdate inbetween < column selected as startdate> and < column selected as enddate >
Now some may ask the question, we can simply do this in the VO query by adding this where clause, yes its true but think about the scenario where this EO can be consumed at a number of places then this option will be quite handy instead of adding the effective date in the where clause. Other is the way described is declarative, which ADF always recommend.
Comments