KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > transactions > security > InsertRoles


1 package transactions.security;
2
3 import dinamica.*;
4
5 /**
6  * Reusable class to insert user roles into DB.<br>
7  * This class exposes a single method that deletes all
8  * previous related roles and re-insert the new ones.
9  * <br><br>
10  * Creation date: 5/03/2004<br>
11  * Last Update: 5/03/2004<br>
12  * (c) 2004 Martin Cordova<br>
13  * This code is released under the LGPL license<br>
14  * @author Martin Cordova (dinamica@martincordova.com)
15  * */

16 public class InsertRoles extends dinamica.GenericTransaction
17 {
18
19     /**
20      * Insert user roles in DB
21      * @param sql SQL template for the INSERT statement, may vary according to
22      * the context (a new user or an existing user).
23      * @throws Throwable
24      */

25     public void saveRoles(String JavaDoc sql) throws Throwable JavaDoc
26     {
27         
28         //get db channel
29
Db db = getDb();
30         
31         //create recordset to hold categoryid values
32
Recordset detail = new Recordset();
33         detail.append("role_id", java.sql.Types.INTEGER);
34         
35         //fill it
36
String JavaDoc v[] = getRequest().getParameterValues("role_id");
37         for (int i=0;i<v.length;i++)
38         {
39             detail.addNew();
40             detail.setValue("role_id", new Integer JavaDoc(v[i]));
41             String JavaDoc cmd = getSQL(sql, detail);
42             db.addBatchCommand(cmd);
43         }
44
45         //insert detail
46
db.exec();
47         
48     }
49
50 }
51
Popular Tags