KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dinamica > GenericTableManager


1 package dinamica;
2
3 import electric.xml.*;
4
5 /**
6  * Generic Transaction to execute one or more simple
7  * action queries like INSERT, UPDATE or DELETE.<br>
8  * This module requires one or more extra elements in config.xml
9  * called "query", containing the filename of the SQL file
10  * to load and execute. Input parameters will be automatically
11  * replaced if config.xml contains validator=true.<br>
12  * Please remember that if you are going to execute more than one
13  * statement you have to activate JDBC transactions in your config.xml
14  * file.
15  * Last update: 24/11/2003
16  * @author Martin Cordova (dinamica@martincordova.com)
17  */

18 public class GenericTableManager extends GenericTransaction
19 {
20
21     /* (non-Javadoc)
22      * @see dinamica.GenericTransaction#service(dinamica.Recordset)
23      */

24     public int service(Recordset inputParams) throws Throwable JavaDoc
25     {
26
27         //return OK
28
int rc = 0;
29         
30         //reuse superclass code
31
super.service(inputParams);
32
33         //get database channel
34
Db db = getDb();
35                 
36         //get config object
37
Config c = getConfig();
38         
39         //read xml - search for all <query> elements in config.xml
40
Document doc = c.getDocument();
41         Elements q = doc.getRoot().getElements("query");
42         
43         if (q!=null)
44         {
45             while (q.hasMoreElements())
46             {
47                 
48                 //read template filename
49
Element e = q.next();
50                 String JavaDoc queryName = e.getString();
51                 
52                 //load sql template
53
String JavaDoc sql = getResource(queryName);
54                 
55                 //replace parameter values
56
sql = this.getSQL(sql, inputParams);
57                 
58                 //execute query
59
db.exec(sql);
60                 
61             }
62         }
63         
64         return rc;
65         
66     }
67
68 }
69
Popular Tags