After learning how to create date-effective objects (i.e., Creating Date-Effective EO, Creating Date-Effective Associations and VOs), now we'll see how to implement date-effective search.
Sample Use Case:
Please go through my previous post to see the sample example use cases of performing date-effective operations on 'Job' object. So, here the requirement is to search for a job effective as of the given date. Sample application illustrating this example can be downloaded from here. Before running the example, you need to create the required tables in DB. The sql script for these table can be downloaded from here.
Implementation Steps:
1. Create the date-effective EO (JobEO) and date-effective VO (JobVO). Marking the JobVO will create a new transient attribute called SysEffectiveDate in the VO attributes.
2. Create a view criteria 'JobSearch' and add the required attributes as query criteria items on which you want to perform the search. As a best practice, use bind variables for all the view criteria items(attributes).
3. In addition to those attributes, add SysEffectiveDate in the query attributes and bind it to the bind variable SysEffectiveDateBindVar of type Date(if this bind variable is not already exist, create a new bind variable with same name and associate it to SysEffectiveDate). Here, the bind variable name that binds SysEffectiveDate should be SysEffectiveDateBindVar as this is the bind variable name generated at runtime by ADF for SysEffectiveDate. Otherwise, it'll throw run time exception.
4. Now, you're done with model part of defining view criteria with SysEffectiveDate. Now, implement search and search results in a jsff with this view criteria.
5. To test the functionality, create multiple job records with different date-effective updates and try to search for a required job records specifying the Effective Date in the search criteria. You'll get the job records which match the query criteria as of the given effective date. Here are the sample screen shots.
6. If the effective date (SysEffectiveDate) is not provided, it'll return the rows effective as of today (i.e.,the system date on which search is made). Screen shot below.
Enjoy!!!
Tuesday, December 28, 2010
ADF UI - Implementing Date Effective Search with Example
Labels:
ADF Model,
ADF UI,
Date-Effectivity,
example,
Search
Sunday, December 26, 2010
ADF Model: Creating Date Effective Association and Date Effective VO
To learn the basics of date-effectivity in ADF, please go through my post Learning basics of Date Effectivity in ADF. To learn how to create date-effective EO, please go through my post Creating Date Effective EO.
Creating Date Effective Association:
To have the basic idea of association between EOs, please go through my post ADF Model: Creating Entity Association. But, by default the association created is not date-effective. But, if you're creating association between two EOs in which at least on of them is effective-dated, then you should mark the association as 'Effective Dated'. To make the association date-effective,
1. Open Association -> Goto 'Relationship' tab -> Behavior -> Check 'Effective Dated Association' checkbox.
Marking the association 'Effective Dated Association' will take effective date into consideration while searching, inserting and updating the records.
Creating Date Effective VO:
Creating date effective VO is same as creating normal VO. In addition, we need to
1. Mark the VO as date-effective by setting EffectiveDated='true' for the VO. You can find this property in 'General' tab property inspector.
Specifying the above property for the VO will generate a new transient attribute called SysEffectiveDate in the VO.
2.Optional: Change the data type of SysEffectiveDate attribute to 'java.sql.Date' from 'oracle.jbo.domain.Number'. We'll often find it easier with native Java sql data types instead of using Oracle's jbo datatypes. It is recommended to use java native sql type(java.sql.Date) for all date type attributes in the EO.
Marking the VO effective dated, will support date-effective updates for a single record.
Creating Date Effective Association:
To have the basic idea of association between EOs, please go through my post ADF Model: Creating Entity Association. But, by default the association created is not date-effective. But, if you're creating association between two EOs in which at least on of them is effective-dated, then you should mark the association as 'Effective Dated'. To make the association date-effective,
1. Open Association -> Goto 'Relationship' tab -> Behavior -> Check 'Effective Dated Association' checkbox.
Marking the association 'Effective Dated Association' will take effective date into consideration while searching, inserting and updating the records.
Creating Date Effective VO:
Creating date effective VO is same as creating normal VO. In addition, we need to
1. Mark the VO as date-effective by setting EffectiveDated='true' for the VO. You can find this property in 'General' tab property inspector.
Specifying the above property for the VO will generate a new transient attribute called SysEffectiveDate in the VO.
2.Optional: Change the data type of SysEffectiveDate attribute to 'java.sql.Date' from 'oracle.jbo.domain.Number'. We'll often find it easier with native Java sql data types instead of using Oracle's jbo datatypes. It is recommended to use java native sql type(java.sql.Date) for all date type attributes in the EO.
Marking the VO effective dated, will support date-effective updates for a single record.
Learning basics of Date Effectivity in ADF
This post explains the basics of date-effectivity which include mainly the basic date-effective operations like Date 'Effective Search', 'Date Effective Create', 'Date Effective Update' and 'Date Effective Delete'. But, it'll be easier to explain the concepts with examples.
So, here for example, I'm taking the simple example of HR admin, who can search/create/update/correct jobs. Let us assume, each job has a name, code and other attributes like job level, if the job requires medical checkup required, minimum salary, maximum salary, etc. What makes the job is date effective is that the attributes of job may change over the time, but still we need to be able to search the jobs based on the attributes that were applicable previously or that will be applicable in future.
For instance, let us take a job with Name 'Java Associate' which was created on 01-01-2000. When the job was created, the minimum salary for the job (minSal) was 10000 and maximum salary (maxSal) was 15000. But, on 01-01-2005, the job was revised and the management decided to move their technology to ADF and changed the job name to 'ADF Associate'.On 01-01-2010, the same job was revised and salary ranges were updated to minSal 25000 and maxSal 40000. Again, the management decided to change all Associate jobs to Developer Jobs from 01-01-2012 onwards (i.e., the job name will be changed from 'ADF Associate' to 'ADF Developer') etc.,
Here, the requirement is that if the user knows the name of the job applicable in 2000, he should be able to search the job as of that date. Similarly, if the user wants to search as of the current date or future dates, he should be able to search as well. That means we shouldn't simply update the existing values of the attributes as it will update the existing values and the previous values would be lost! We need to keep different versions of the attributes for the same job. So, how will it be possible as to have the multiple records with same JobId? Here comes EffectiveStartDate and EffectiveEndDate. Actually, we need to have a composite key based on JobId, EffectiveStartDate and EffectiveEndDate(i.e., the combination of these 3 attributes should be unique).
So, the data in the above requirement can be shown in table as follows. Changed attributes for each date-effective update are highlighted in yellow.
If you see the above table, you'll notice that for any change in the Job attribute, we have new row with the corresponding EffectiveStartDate and EffectiveEndDate and there are no gaps in between. i.e., for any given date, only one record is applicable among multiple date-effective rows of a single Job record.
Now we'll see what date effectivity means in ADF for different operations on the records.
Date Effective Search:
For example, if we want to find the jobs whose name starts with 'ADF%' as of date 01-01-2006. Or, we want to find out the jobs which will be applicable after 01-01-2012. Or, we want to find the minSal and maxSal for a given job as of 01-01-2007. Here, the results would change changing the Effective Dates as each job would have different values for the same attribute for different effective dates. Date-effective search will make all these possible. Date-effective search is explained with an example here.
Date Effective Create:
For example, we want to create a job that will be applicable in future say from 01-01-2013. Or, I want to create record which should be applicable from the past say 12-12-1900. Or, I want to create a new job which should be effective from today. Date-effective create makes all of these possible.
Date Effective Update:
For example, we want to insert a new date-effective record for the job to represent a change in one of the attributes of the job. Say, I want to update the maxSal of the job with jobId 1001 to 20000 from 01-01-2008. This will insert a new record for the same job with EffectiveStartDate 01-01-2008 with maxSal 20000. Different date-effective update modes and the corresponding behavior has been explained here.
Date Effective Correct:
For example, I want to correct or change one or more of the attributes of one of the date-effective rows of a single job record. Date Effective Correct operation just corrects the existing data. It won't insert any new date-effective rows. You can find the example of DE correction mode here.
Date Effective Delete:
For example, we want to delete a single date-effective record out of multiple date-effective records of a job. For instance, we want to delete the job record [1001, 01-01-2005, 31-12-2009]. If the record is non-date effective, then deleting the row means deleting the entire record as there won't be multiple rows. But, in case of date-effective objects, if you want to delete entire record, you need to delete all date-effective rows of that record if any.
Now, you understand the basics of date-effectivity in ADF. If you need any clarification, please leave a comment.
Thursday, December 23, 2010
ADF Model: Creating Date Effective EO
Date-effectivity is an excellent feature available in Jdeveloper 11g. To learn the basics of date-effectivity in ADF, please go through my post Learning basic of Date Effectivity in ADF. With Jdev 11g, we can create date-effective objects and do date-effective operations using simple API calls. Before going into all those details, the first requirement would be creating Date-Effective EO.
The first requirement to create a DE-EO based on a table, the table should have two date columns to represent Effective Start Date(ESD) and Effecitve End Date(EED) of the record and these columns should be marked as primary keys along with id column. In other words, we need to define a composite key based on the id column and ESD and EED columns.
Creating Date Effective EO is same as creating normal EO. In addition, we need to do the following steps to make it date-effective.
1. Mark the EO as Date Effective by specifying the attribute Effective Date Type = 'EffectiveDated'. You can find this property in 'General' tab property inspector.
This will generate a new transient attributte called 'SysEffectiveDate' in the EO. Please find the screenshot below:
2. We need to specify which columns represent effective-date columns by checking the Check 'Effective Date' check box and selecting 'Start' and 'End' radio buttons for the effective-date columns which represent Effective Start Date and Effective End Date. Find the screen shots below:
3. Optional: Change the data type of SysEffectiveDate attribute to 'java.sql.Date' from 'oracle.jbo.domain.Number'. We'll often find it easier with native Java sql data types instead of using Oracle's jbo datatypes. It is recommended to use java native sql type(java.sql.Date) for all date type attributes in the EO.
That's it. Now, your EO is date-effective and supports date-effective operations on it's rows.
The first requirement to create a DE-EO based on a table, the table should have two date columns to represent Effective Start Date(ESD) and Effecitve End Date(EED) of the record and these columns should be marked as primary keys along with id column. In other words, we need to define a composite key based on the id column and ESD and EED columns.
Creating Date Effective EO is same as creating normal EO. In addition, we need to do the following steps to make it date-effective.
1. Mark the EO as Date Effective by specifying the attribute Effective Date Type = 'EffectiveDated'. You can find this property in 'General' tab property inspector.
This will generate a new transient attributte called 'SysEffectiveDate' in the EO. Please find the screenshot below:
2. We need to specify which columns represent effective-date columns by checking the Check 'Effective Date' check box and selecting 'Start' and 'End' radio buttons for the effective-date columns which represent Effective Start Date and Effective End Date. Find the screen shots below:
3. Optional: Change the data type of SysEffectiveDate attribute to 'java.sql.Date' from 'oracle.jbo.domain.Number'. We'll often find it easier with native Java sql data types instead of using Oracle's jbo datatypes. It is recommended to use java native sql type(java.sql.Date) for all date type attributes in the EO.
That's it. Now, your EO is date-effective and supports date-effective operations on it's rows.
Labels:
ADF Model,
Date-Effectivity,
Entity Object,
EO
Wednesday, December 22, 2010
ADF Model: Getting attribute values from parent VO to child VO and vice versa using view link accessors
In this post, let us see how to access parent VO attributes from child VO and child VO attributes from parent VO using view link. To have the basic idea about view links and how to create them, you can go through my blog post 'ADF Model: Creating View Link'.
Example Use Case:
For example we have two VOs DeptVO and EmpVO and both are linked via foreign key 'DeptId' using the view link EmpVOToDeptVO. Here, this relationship depicts the parent-child relationship using the foreign key DeptId. In other words, for a given current EmpVO(child) row, I need to know the DeptName from DeptVO(parent). Similarly, for a given current DeptVO(parent) row, I need to know all the empVO(child) rows. Sample application demonstrating this example can be downloaded from here.
Implementation Steps:
1. Create EmpVO and DeptVO and generate RowImpl classes for both of these two VOs.
2. Now, create a new view link say DeptVOToEmpVO between these two VOs via foreign key DeptId.
3. In the view link definition, select options to generate accessors in both source and destination VOs. i.e., in DeptVO and EmpVO.
4. Checking the above options will generate accessor methods in EmpVORowImpl and DeptVORowImpl. The accessor's return type in each VO is based on the type of relationship between the VOs. In other words, as the relationship between Dept and Emp is 1-to-many, the accessor in DeptVORowImpl will return multiple Emp rows(i.e, the return type of the accessor will be RowIterator). And, the accessor in EmpVORowImpl will return a single row (as an employee can be in only one dept).
If you observe the source of EmpVO and DeptVO, you can also see that a tag is added in each of these VOs for the viewLinkAccessor.
5. Now, you can use these accessors to get reference EmpVO from DeptVO and vice versa. You can also get attribute values from the same. Sample codes below:
Sample method in EmpVORowImpl to get the dept name.
Sample method in DeptVORowImpl to get the list of employees in the dept.
How to call/use these view link accessor methods in AMImpl methods?
This should be now pretty straightforward. Here is the sample AMImpl method which prints emp names in each dept. The code is self-explanatory.
Here is the sample output in console on running the above AMImpl method.
That's it. Now, you got the idea how to use view link accessors to get the values of child attributes from parent and vice versa. Enjoy!
Example Use Case:
For example we have two VOs DeptVO and EmpVO and both are linked via foreign key 'DeptId' using the view link EmpVOToDeptVO. Here, this relationship depicts the parent-child relationship using the foreign key DeptId. In other words, for a given current EmpVO(child) row, I need to know the DeptName from DeptVO(parent). Similarly, for a given current DeptVO(parent) row, I need to know all the empVO(child) rows. Sample application demonstrating this example can be downloaded from here.
Implementation Steps:
1. Create EmpVO and DeptVO and generate RowImpl classes for both of these two VOs.
2. Now, create a new view link say DeptVOToEmpVO between these two VOs via foreign key DeptId.
3. In the view link definition, select options to generate accessors in both source and destination VOs. i.e., in DeptVO and EmpVO.
4. Checking the above options will generate accessor methods in EmpVORowImpl and DeptVORowImpl. The accessor's return type in each VO is based on the type of relationship between the VOs. In other words, as the relationship between Dept and Emp is 1-to-many, the accessor in DeptVORowImpl will return multiple Emp rows(i.e, the return type of the accessor will be RowIterator). And, the accessor in EmpVORowImpl will return a single row (as an employee can be in only one dept).
If you observe the source of EmpVO and DeptVO, you can also see that a tag is added in each of these VOs for the viewLinkAccessor.
5. Now, you can use these accessors to get reference EmpVO from DeptVO and vice versa. You can also get attribute values from the same. Sample codes below:
Sample method in EmpVORowImpl to get the dept name.
public String getDeptNameViaViewLink() { //Getting reference to deptVO row using the view link accessor getDeptVO1() Row deptRow = this.getDeptVO1(); //Getting the attribute 'Dname' value from the deptRow. return (String)deptRow.getAttribute("Dname"); }
Sample method in DeptVORowImpl to get the list of employees in the dept.
public List getEmpNamesViaViewLink() { //Getting reference to empVO row using the view link accessor getEmpVO() RowIterator empRowIterator = this.getEmpVO(); //Creating an empty List to store all emp names List empNames = new ArrayList(); //iterating through all employee rows while(empRowIterator.hasNext()){ //getting emp row one by one from the iterator Row empRow = empRowIterator.next(); //adding emp name to the empNames list empNames.add(empRow.getAttribute("Ename")); } //returning all empNames corresponding to the current dept return empNames; }
How to call/use these view link accessor methods in AMImpl methods?
This should be now pretty straightforward. Here is the sample AMImpl method which prints emp names in each dept. The code is self-explanatory.
public void sampleMethod() { //getting reference to deptVO ViewObjectImpl deptVO = this.getDeptVO(); //setting range size to -1 to get all dept rows deptVO.setRangeSize(-1); //getting all dept rows Row[] deptRows = deptVO.getAllRowsInRange(); //iterating through all dept rows for (int i = 0; i < deptRows.length; i++) { //getting reference to each dept row. Note that we're type casting the VO reference type to DeptVORowImpl. DeptVORowImpl deptRow = (DeptVORowImpl)deptRows[i]; //printing dept name System.out.println("Employees in dept: " + deptRow.getAttribute("Dname")); //For each dept row, getting reference to empVO which contains all employees corresponding to current dept RowIterator empRows = deptRow.getEmpVO(); //iterating each emp row while (empRows.hasNext()) { Row empRow = empRows.next(); //printing emp name from each row System.out.println(empRow.getAttribute("Ename")); } } }
Here is the sample output in console on running the above AMImpl method.
That's it. Now, you got the idea how to use view link accessors to get the values of child attributes from parent and vice versa. Enjoy!
Subscribe to:
Posts (Atom)