http://www.awasthiashish.com/2014/04/performing-partial-rollback-undo.html
UseCase
Two tables on page Departments and Employees, and i have changed one row in Departments table and same time created a row in Employees table, now i want to rollback the changes done in Departments table only.
Solution
1- add a new transient attribute in Departments Vo to get current state of each row
UseCase
Two tables on page Departments and Employees, and i have changed one row in Departments table and same time created a row in Employees table, now i want to rollback the changes done in Departments table only.
Solution
1- add a new transient attribute in Departments Vo to get current state of each row
/**
* Gets the attribute value for the calculated attribute RowStatusTrans.
* @return the RowStatusTrans
*/
public Integer getRowStatusTrans() {
/*here row is reference variable of collection, this expression returns an int value if it is
2-Modified
0-New
1-Unmodified
-1-Initialized
*/
byte entityState = this.getEntity(0).getEntityState();
return new Integer(entityState);
}
2- create a method to remove newly added row , and to undo changes in existing rows of departments VO in Impl class /**Method to revert changes of current row
* @param curRow
*/
public void revertChangesCurrentRow(Row curRow) {
if (curRow != null) {
curRow.refresh(Row.REFRESH_UNDO_CHANGES | Row.REFRESH_WITH_DB_FORGET_CHANGES);
}
}
/**Method to check whether row should be removed or not
* If it is new - removed
* If old one- Undo Changes
* */
public void revertOrremoveRowValues() {
ViewObject deptVo = this;
RowSetIterator deptIter = deptVo.createRowSetIterator(null);
while (deptIter.hasNext()) {
Row nextRow = deptIter.next();
if (nextRow.getAttribute("RowStatusTrans") != null) {
Integer rowStatus = (Integer) nextRow.getAttribute("RowStatusTrans");
if (rowStatus == 2) {
System.out.println("Modified Rows-" + nextRow.getAttribute("DepartmentId"));
revertChangesCurrentRow(nextRow);
} else if (rowStatus == 0) {
System.out.println("New Row Removed");
nextRow.remove();
}
}
}
this.executeQuery();
}
No comments:
Post a Comment