public final Map act(Redirector redirector,
SourceResolver resolver,
Map objectModel,
String source,
Parameters param) throws Exception {
DataSourceComponent datasource = null;
Connection conn = null;
int currentIndex = 0;
// read global parameter settings
boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT;
if (this.settings.containsKey("reloadable"))
reloadable = Boolean.valueOf((String) this.settings.get("reloadable")).booleanValue();
// read local parameter settings
try {
Configuration conf =
this.getConfiguration(param.getParameter("descriptor", (String) this.settings.get("descriptor")), resolver,
param.getParameterAsBoolean("reloadable",reloadable));
String query = this.getDeleteQuery(conf);
datasource = this.getDataSource(conf);
conn = datasource.getConnection();
Request request = ObjectModelHelper.getRequest(objectModel);
if (conn.getAutoCommit()) {
conn.setAutoCommit(false);
}
PreparedStatement statement = conn.prepareStatement(query);
Configuration[] keys = conf.getChild("table").getChild("keys").getChildren("key");
for (int i = 0; i < keys.length; i++) {
this.setColumn(statement, i + 1, request, keys[i]);
}
int rows = statement.executeUpdate();
conn.commit();
statement.close();
if (rows > 0) {
request.setAttribute("rows", Integer.toString(rows));
return EMPTY_MAP;
}
} catch (Exception e) {
if (conn != null) {
conn.rollback();
}
throw new ProcessingException("Could not delete record :position = " + currentIndex, e);
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException sqe) {
getLogger().warn("There was an error closing the datasource", sqe);
}
}
if (datasource != null) {
this.dbselector.release(datasource);
}
}
return null;
}
Delete a record from the database. This action assumes that
the file referenced by the "descriptor" parameter conforms
to the AbstractDatabaseAction specifications. |