Tuesday, January 04, 2011

Duplicating a Row in the VO

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 =
//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.
} //End of duplicate EMP OBject
//Creates a new Emp Row
newEmpRow =

* 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() ==

1 comment:

ashish suyal said...