Here is a quick one. If there is a requirement that states that an action must be performed to all the result set of a view object, then you might consider the following method. In our case, we have a requirement that we need to raise the salary of all the employees within an specific department.
For this, we need to think where is the right place to implement this logic. We have several options. We have taken the one we consider is more neat and follows best practices; in the view object implementation class. Let’s see how is made:
First we need to create the ViewObjectImpl class;
Then, we need to write the code to achieve this functionality. We need to iterate for the result set of the view object, we can do that using the following code;
Now, we need to be able to access that method from our application module. That is why we need to expose it to the client interface of the view object itself;
If we run the application module, we will be able to test it. Let’s pick some random department;
Since the method is exposed in the Employee VO, we right click to the link instance and select Operations from the menu;
After this, you will get the client interface screen where you can execute your exposed methods. Let’s give a rise of 2000;
If we check now, we will see the salary has increased just for the employees of this department;
Note: if you are working over the same project from previous posts; then a task for you will be to refresh the AvgSalary. We have re-executed the query of the VO to get this updated.