* Select a record from the database. This action assumes that
* the file referenced by the "descriptor" parameter conforms
* to the AbstractDatabaseAction specifications.
*/
public 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.getBoolean((String) this.settings.get("reloadable"));
// read local parameter settings
try {
Configuration conf =
this.getConfiguration(param.getParameter("descriptor", (String) this.settings.get("descriptor")),
resolver,
param.getParameterAsBoolean("reloadable",reloadable));
Request request = ObjectModelHelper.getRequest(objectModel);
Configuration[] keys = conf.getChild("table").getChild("keys").getChildren("key");
Configuration[] values = conf.getChild("table").getChild("values").getChildren("value");
PreparedStatement statement = null;
ResultSet rset = null;
boolean result = false;
for (int i = 0; i < keys.length; i++) {
final String parameter = keys[i].getAttribute("param");
Object value = request.getParameter(parameter);
if (value == null || "".equals(value)) {
if (statement == null) {
final String query = this.getSelectQuery(conf);
datasource = this.getDataSource(conf);
conn = datasource.getConnection();
statement = conn.prepareStatement(query);
currentIndex = 1;
for (int j = 0; j < keys.length; j++, currentIndex++) {
this.setColumn(statement, currentIndex, request, keys[j]);
}
rset = statement.executeQuery();
result = rset.next();
}
if (result)
value = this.getColumn(rset, request, keys[i]);
}
if (value != null)
request.setAttribute(parameter, value.toString());
}
for (int i = 0; i < values.length; i++) {
final String parameter = values[i].getAttribute("param");
Object value = request.getParameter(parameter);
if (value == null || "".equals(value)) {
if (statement == null) {
final String query = this.getSelectQuery(conf);
datasource = this.getDataSource(conf);
conn = datasource.getConnection();
statement = conn.prepareStatement(query);
currentIndex = 1;
for (int j = 0; j < keys.length; j++, currentIndex++) {
this.setColumn(statement, currentIndex, request, keys[j]);