KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > metadata > GetPKInfo


1 package metadata;
2
3 import dinamica.*;
4 import java.sql.*;
5
6 /**
7  * Base class to program business transaction services (read/write).
8  * All transactions will subclass this class.
9  *
10  * <br>
11  * Creation date: 29/10/2003<br>
12  * Last Update: 29/10/2003<br>
13  * (c) 2003 Martin Cordova<br>
14  * This code is released under the LGPL license<br>
15  * @author Martin Cordova
16  * */

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

23     public int service(Recordset inputs) throws Throwable JavaDoc
24     {
25         
26         int rc = super.service(inputs);
27         
28         Recordset rsinfo = new Recordset();
29         rsinfo.append("table", java.sql.Types.VARCHAR);
30         
31         String JavaDoc types[] = {"TABLE"};
32             
33         DatabaseMetaData md = getConnection().getMetaData();
34         ResultSet tables = md.getTables(null, inputs.getString("schema"), "%", types);
35         Recordset rs = new Recordset(tables);
36         tables.close();
37         
38         while (rs.next())
39         {
40             String JavaDoc table = rs.getString("table_name");
41             ResultSet pk = md.getPrimaryKeys(null, inputs.getString("schema"), table);
42             if (!pk.next())
43             {
44                 rsinfo.addNew();
45                 rsinfo.setValue("table", table);
46             }
47             pk.close();
48         }
49         
50         publish("tables", rsinfo);
51         
52         return rc;
53
54     }
55
56 }
57
Popular Tags