Reusable Code – How to check existing record

/**
*It checks for existing record based on provided parameter. Check ViewObject.estimatedRowCount>0 for results
*@Param – ViewObject Name to be checked
*@Param – where clause needs to be executed
*@return – returns updated viewObject.
*/

public ViewObjectImpl checkForExistingRecord(String viewObjectName,
Map<String, Number> params) {

Row[] resultRows = null;
ViewObjectImpl viewObject =
(ViewObjectImpl)getAppModule().findViewObject(viewObjectName);

if (params != null) {
Iterator paramsIter = params.keySet().iterator();
while (paramsIter.hasNext()) {
String key = (String)paramsIter.next();
viewObject.setNamedWhereClauseParam(key, params.get(key));
System.out.println(“Query after modification : ” + viewObject.getQuery());
System.out.println(“Where clause after modification : ” + viewObject.getNamedWhereClauseParam(key));
}
viewObject.executeQuery();
resultRows = viewObject.getAllRowsInRange();
}

return viewObject;
}

/**
*This method is called from previous method
*/

public ApplicationModule getAppModule() {
DCBindingContainer bindings = (DCBindingContainer)getBindings();
ApplicationModule appModule =
bindings.getDataControl().getApplicationModule();
return appModule;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s