01: package dinamica;
02:
03: /**
04: * Deletes record from recordset stored in session
05: * and then executes whatever queries as defined in
06: * config.xml. This class may be used to create the visual effect
07: * of record deletion when deleting records from paged views. It requires two
08: * special parameters in config.xml: recordset-id (attribute ID used to store recordset
09: * in session) and pkey (name of the field that is the primary key of the table, also contained
10: * in the recordset). It is also assumed that the request contains a parameter "id", which contains
11: * the value of the PKey used to delete a specific record. It will trigger an exception if can't find
12: * a record with pkey = id, if config parameters are not present, or if it cannot find the recordset in session.
13: * @author Martín Cordova
14: */
15: public class DeleteRecordPaged extends GenericTableManager {
16:
17: public int service(Recordset inputParams) throws Throwable {
18: String rsID = getConfig().getConfigValue("recordset-id");
19: String pkey = getConfig().getConfigValue("pkey");
20: Recordset rs = (Recordset) getSession().getAttribute(rsID);
21:
22: if (rs == null)
23: throw new Throwable(
24: "Can't find recordset in session with attribute ID = "
25: + rsID);
26:
27: int id = inputParams.getInt("id");
28: int pos = rs.findRecord(pkey, id);
29: if (pos < 0)
30: throw new Throwable("Can't find record with column " + pkey
31: + "=" + id);
32: else
33: rs.delete(pos);
34:
35: super .service(inputParams);
36:
37: return 0;
38: }
39:
40: }
|