KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > transactions > SaveProjects


1 package transactions;
2
3 import dinamica.*;
4
5 /**
6  * Transaction class that retrieves a recordset containing
7  * multiple records to be saved, this type of parameters (array values)
8  * cannot be auto-validated by the framework, so a custom validator
9  * must be used to read, validate and create a recordset with those values.
10  * The validator will store the resulting recordset into a request attribute
11  * in order to make it available to this Transaction module.
12  * @author Martin Cordova
13  */

14 public class SaveProjects extends GenericTransaction
15 {
16
17     /**
18      * Save list of records using prepared statement
19      * in batch mode - very efficient for this type of operation
20      */

21     public int service(Recordset inputParams) throws Throwable JavaDoc
22     {
23         
24         //reuse superclass code
25
super.service(inputParams);
26         
27         //retrieve recordset pre-processed by the validator
28
//and stored in a request attribute
29
Recordset rs = (Recordset)getRequest().getAttribute("projects");
30         
31         //define prepared-statement parameter names (in correct order please!)
32
//teh parameters order must match the SQL template
33
String JavaDoc[] params =
34         {
35             "manager_id",
36             "log_activity",
37             "budget",
38             "start_date",
39             "description",
40             "project_id"
41
42         };
43         
44         //load prepared statement template
45
String JavaDoc sql = getResource("update.sql");
46         
47         //get db channel and execute batch query
48
Db db = getDb();
49         db.execBatch(sql, rs, params);
50         
51         return 0;
52         
53     }
54
55 }
56
Popular Tags