Tuesday, January 04, 2011

Duplicating a Row in the VO

UseCase
We have an EmpVO.We want to create a duplicate Row in the EmpVO given an existing EmpRow.The new Duplicated row would have all Data Same except the EmpName,PK and the WHO columns

          public void doDuplicateEmpVORow(EmpVOImpl empVO, EmpVORowImpl origEmpRow, String newEmpName) {
EmpVORowImpl newEmpRow = null;
AttributeListImpl attrList = new AttributeListImpl();
//gets the AttributeNames
String[] attrNames = origEmpRow.getAttributeNames();
attrList.setAttribute("EmpName", newEmpName);
for (String attrName : attrNames) {
//Gets the AttributeDef
AttributeDef attrDef =
origEmpRow.findAttributeDef(attrName);
//Gets the sqlType of the Attribute
int sqlType = attrDef.getSQLType();
//Checks if the Attribute is a PK or not.
boolean isPK = attrDef.isPrimaryKey();
//Set Attribute value if the attribute is not PK nor EmpName nor RowSetIterator nor ViewAccessor
if (!isPK && !"EmpName".equals(attrName)&& sqlType > 0 &&
!isHistoryAttribute(attrName) &&
isPersistantAttribute(attrDef)) {
//Sets the attribute value.
attrList.setAttribute(attrName,
origEmpRow.getAttribute(attrName));
}
} //End of duplicate EMP OBject
//Creates a new Emp Row
newEmpRow =
(EmpVORowImpl)empVO.createAndInitRow(attrList);
}

/**
* This method checks if an attribute is a history attribute or not.
*
* @param attributeName
* @return
*/
private boolean isHistoryAttribute(String attributeName) {
//for HistoryAttribute and ObjectVersionNumber, return TRue.
return ("CreatedBy".equals(attributeName) ||
"CreationDate".equals(attributeName) ||
"LastUpdateDate".equals(attributeName) ||
"LastUpdatedBy".equals(attributeName) ||
"LastUpdateLogin".equals(attributeName) ||
"ObjectVersionNumber".equals(attributeName)) ?

true : false;
}

/**
* This method checks if an attribute is a Persistant attribute or not.
*
* @param attributeDef
* @return
*/
private boolean isPersistantAttribute(AttributeDef attributeDef) {
return (attributeDef.getAttributeKind() ==
AttributeDef.ATTR_PERSISTENT);
}

1 comment:

ashish suyal said...

https://community.oracle.com/people/3152606/blog/2016/01/27/finding-duplicates-in-vo-or-advanced-table-in-oafadf?sr=inbox&customTheme=ougc