KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > dao > drivers > keygen > KeyKeeperTest


1 /*
2  * $Id: KeyKeeperTest.java,v 1.1 2004/11/23 11:09:04 bel70 Exp $
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the Mozilla Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Alexey Pavlov <alexnet@users.sourceforge.net>
23  *
24  * ***** END LICENSE BLOCK ***** */

25 package org.jresearch.gossip.dao.drivers.keygen;
26
27 import java.sql.Connection JavaDoc;
28 import java.sql.DatabaseMetaData JavaDoc;
29 import java.sql.DriverManager JavaDoc;
30 import java.sql.ResultSet JavaDoc;
31
32 import junit.framework.TestCase;
33
34 /**
35  * KeyKeeperTest
36  *
37  * @author <a HREF="alexnet@sourceforge.net">A. Pavlov</a>
38  * @version $version$ $Date: 2004/11/23 11:09:04 $
39  */

40 public class KeyKeeperTest extends TestCase {
41     
42     private Connection JavaDoc conn;
43
44     /**
45      * Constructor for KeyKeeperTest.
46      * @param arg0
47      */

48     public KeyKeeperTest(String JavaDoc arg0) {
49         super(arg0);
50     }
51
52     public static void main(String JavaDoc[] args) {
53         junit.textui.TestRunner.run(KeyKeeperTest.class);
54     }
55
56     /*
57      * @see TestCase#setUp()
58      */

59     protected void setUp() throws Exception JavaDoc {
60         super.setUp();
61         Class.forName("oracle.jdbc.driver.OracleDriver");
62         conn = DriverManager.getConnection("jdbc:oracle:thin:@frodo:1521:ORACLEDB", "jgossip", "Welcome1");;
63     }
64
65     /*
66      * @see TestCase#tearDown()
67      */

68     protected void tearDown() throws Exception JavaDoc {
69         super.tearDown();
70         if (null != conn) conn.close();
71         conn = null;
72     }
73
74     final public void testGetColumnTypeTC()
75             throws Exception JavaDoc
76     {
77         ResultSet JavaDoc rs = null;
78         String JavaDoc table = "JRF_KEY_KEEPER";
79         String JavaDoc column = "next_key";
80         DatabaseMetaData JavaDoc dmd = conn.getMetaData();
81         System.out.println("database metadata obtained: "+dmd.toString());
82         System.out.println("Columns info obtaining for table[" + table +"] column["+column+"].");
83         //schema - "JGOSSIP"
84
rs = dmd.getColumns(null, null, table.toUpperCase(), column.toUpperCase());
85         System.out.println("Columns info obtained: "+rs);
86         if(null != rs )
87         {
88             for(int i = rs.getMetaData().getColumnCount(); i > 0; i--) {
89                 System.out.println(rs.getMetaData().getColumnName(i));
90             }
91             while(rs.next()) {
92                     System.out.println("TABLE_CAT:"+rs.getObject("TABLE_CAT"));
93                     System.out.println("TABLE_SCHEM:"+rs.getObject("TABLE_SCHEM"));
94                     System.out.println("TABLE_NAME:"+rs.getObject("TABLE_NAME"));
95                     System.out.println("COLUMN_NAME:"+rs.getObject("COLUMN_NAME"));
96                     System.out.println("DATA_TYPE:"+rs.getObject("DATA_TYPE"));
97                     System.out.println("TYPE_NAME:"+rs.getObject("TYPE_NAME"));
98                     System.out.println("COLUMN_SIZE:"+rs.getObject("COLUMN_SIZE"));
99                     System.out.println("DECIMAL_DIGITS:"+rs.getObject("DECIMAL_DIGITS"));
100                     System.out.println("NULLABLE:"+rs.getObject("NULLABLE"));
101                     System.out.println("IS_NULLABLE:"+rs.getObject("IS_NULLABLE"));
102                     //System.out.println("SCOPE_CATLOG:"+rs.getObject("SCOPE_CATLOG"));
103
//System.out.println("SCOPE_SCHEMA:"+rs.getObject("SCOPE_SCHEMA"));
104
//System.out.println("SCOPE_TABLE:"+rs.getObject("SCOPE_TABLE"));
105
}
106             rs.close();
107         }
108     }
109
110         final public void testGetColumnTypePK()
111                 throws Exception JavaDoc
112         {
113             ResultSet JavaDoc rs = null;
114             String JavaDoc [] primaryKey = {"jrf_message", "id"};
115             DatabaseMetaData JavaDoc dmd = conn.getMetaData();
116             System.out.println("database metadata obtained: "+dmd.toString());
117             System.out.println("Primary keys:");
118             for (int i = 0; i < primaryKey.length; ++i)
119                 System.out.println("primary key ["+i+"]="+primaryKey[i]);
120             System.out.println("Columns info obtaining for table[" + primaryKey[0] +"] column["+primaryKey[1]+"].");
121             // schema - "JGOSSIP"
122
rs = dmd.getColumns(null, null, primaryKey[0].toUpperCase(), primaryKey[1].toUpperCase());
123             System.out.println("Columns info obtained: "+rs);
124             if(null != rs )
125             {
126                 for(int i = rs.getMetaData().getColumnCount(); i > 0; i--) {
127                     System.out.println(rs.getMetaData().getColumnName(i));
128                 }
129                 while(rs.next()) {
130                     System.out.println("TABLE_CAT:"+rs.getObject("TABLE_CAT"));
131                     System.out.println("TABLE_SCHEM:"+rs.getObject("TABLE_SCHEM"));
132                     System.out.println("TABLE_NAME:"+rs.getObject("TABLE_NAME"));
133                     System.out.println("COLUMN_NAME:"+rs.getObject("COLUMN_NAME"));
134                     System.out.println("DATA_TYPE:"+rs.getObject("DATA_TYPE"));
135                     System.out.println("TYPE_NAME:"+rs.getObject("TYPE_NAME"));
136                     System.out.println("COLUMN_SIZE:"+rs.getObject("COLUMN_SIZE"));
137                     System.out.println("DECIMAL_DIGITS:"+rs.getObject("DECIMAL_DIGITS"));
138                     System.out.println("NULLABLE:"+rs.getObject("NULLABLE"));
139                     System.out.println("IS_NULLABLE:"+rs.getObject("IS_NULLABLE"));
140                     //System.out.println("SCOPE_CATLOG:"+rs.getObject("SCOPE_CATLOG"));
141
//System.out.println("SCOPE_SCHEMA:"+rs.getObject("SCOPE_SCHEMA"));
142
//System.out.println("SCOPE_TABLE:"+rs.getObject("SCOPE_TABLE"));
143
}
144                 rs.close();
145             }
146         }
147
148 }
149
Popular Tags