KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > GTConnectionInfoDataSource


1 /**
2  * com.mckoi.database.GTConnectionInfoDataSource 23 Mar 2002
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.database;
26
27 import java.util.ArrayList JavaDoc;
28
29 /**
30  * An implementation of MutableTableDataSource that presents the current
31  * connection information.
32  * <p>
33  * NOTE: This is not designed to be a long kept object. It must not last
34  * beyond the lifetime of a transaction.
35  *
36  * @author Tobias Downer
37  */

38
39 final class GTConnectionInfoDataSource extends GTDataSource {
40
41   /**
42    * The DatabaseConnection object that this is table is modelling the
43    * information within.
44    */

45   private DatabaseConnection database;
46
47   /**
48    * The list of info keys/values in this object.
49    */

50   private ArrayList JavaDoc key_value_pairs;
51
52   /**
53    * Constructor.
54    */

55   public GTConnectionInfoDataSource(DatabaseConnection connection) {
56     super(connection.getSystem());
57     this.database = connection;
58     this.key_value_pairs = new ArrayList JavaDoc();
59   }
60
61   /**
62    * Initialize the data source.
63    */

64   public GTConnectionInfoDataSource init() {
65
66     // Set up the connection info variables.
67
key_value_pairs.add("auto_commit");
68     key_value_pairs.add(database.getAutoCommit() ? "true" : "false");
69
70     key_value_pairs.add("isolation_level");
71     key_value_pairs.add(database.getTransactionIsolationAsString());
72
73     key_value_pairs.add("user");
74     key_value_pairs.add(database.getUser().getUserName());
75
76     key_value_pairs.add("time_connection");
77     key_value_pairs.add(new java.sql.Timestamp JavaDoc(
78                           database.getUser().getTimeConnected()).toString());
79
80     key_value_pairs.add("connection_string");
81     key_value_pairs.add(database.getUser().getConnectionString());
82
83     key_value_pairs.add("current_schema");
84     key_value_pairs.add(database.getCurrentSchema());
85
86     key_value_pairs.add("case_insensitive_identifiers");
87     key_value_pairs.add(database.isInCaseInsensitiveMode() ? "true" : "false");
88
89     return this;
90   }
91
92   // ---------- Implemented from GTDataSource ----------
93

94   public DataTableDef getDataTableDef() {
95     return DEF_DATA_TABLE_DEF;
96   }
97
98   public int getRowCount() {
99     return key_value_pairs.size() / 2;
100   }
101
102   public TObject getCellContents(final int column, final int row) {
103     switch (column) {
104       case 0: // var
105
return columnValue(column, (String JavaDoc) key_value_pairs.get(row * 2));
106       case 1: // value
107
return columnValue(column,
108                            (String JavaDoc) key_value_pairs.get((row * 2) + 1));
109       default:
110         throw new Error JavaDoc("Column out of bounds.");
111     }
112   }
113
114   // ---------- Overwritten from GTDataSource ----------
115

116   public void dispose() {
117     super.dispose();
118     key_value_pairs = null;
119     database = null;
120   }
121
122   // ---------- Static ----------
123

124   /**
125    * The data table def that describes this table of data source.
126    */

127   static final DataTableDef DEF_DATA_TABLE_DEF;
128
129   static {
130
131     DataTableDef def = new DataTableDef();
132     def.setTableName(
133                  new TableName(Database.SYSTEM_SCHEMA, "sUSRConnectionInfo"));
134
135     // Add column definitions
136
def.addColumn(stringColumn("var"));
137     def.addColumn(stringColumn("value"));
138
139     // Set to immutable
140
def.setImmutable();
141
142     DEF_DATA_TABLE_DEF = def;
143
144   }
145
146 }
147
Popular Tags