* @param resourceCollection A Collection of DDNameValues.
* @see com.centraview.common.DDNameValue
*/
private void updateResources(Collection resourceCollection)
{
CVDal cvdl = new CVDal(dataSource);
try {
if (resourceCollection != null) {
StringBuffer stringBuffer = new StringBuffer();
Iterator it = resourceCollection.iterator();
while (it.hasNext()) {
DDNameValue resourceObject = (DDNameValue) it.next();
// System.out.println("[DEBUG] [AppSettingsEJB]: resourceObject: " +
// resourceObject.toString());
if (resourceObject.getName() != null && resourceObject.getId() == -1) {
// create a new Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("INSERT INTO activityresources (Name) VALUES (?)");
cvdl.setString(1, resourceObject.getName());
cvdl.executeUpdate();
int newId = cvdl.getAutoGeneratedKey();
stringBuffer.append(newId);
} // end of if statement (resourceObject.getName() != null ...
else if (resourceObject.getName() != null) {
// update the existing Resource Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("UPDATE activityresources SET Name = ? WHERE ActivityResourceID = ?");
cvdl.setString(1, resourceObject.getName());
cvdl.setInt(2, resourceObject.getId());
cvdl.executeUpdate();
stringBuffer.append(resourceObject.getId());
} // end of else if statement (resourceObject.getName() != null)
if (stringBuffer.length() > 0 && it.hasNext()) {
stringBuffer.append(", ");
}
} // end of while loop (it.hasNext())
if (stringBuffer.length() > 0) {
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("DELETE FROM activityresources WHERE ActivityResourceID NOT IN (" + stringBuffer + ")");
cvdl.executeUpdate();
} // end of if statement (stringBuffer.length() > 0)
} // end of if statement (sourceValues != null)
}catch (Exception e) {
logger.error("[updateResources]: Exception", e);
}finally {
cvdl.destroy();
} // end of finally block
} // end of updateResources method