KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * com.mckoi.database.GTDataSource 27 Apr 2001
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 com.mckoi.database.global.SQLTypes;
28
29 /**
30  * A base class for a dynamically generated data source. While this inherits
31  * MutableTableDataSource (so we can make a DataTable out of it) a GTDataSource
32  * derived class may not be mutable. For example, an implementation of this
33  * class may produce a list of a columns in all tables. You would typically
34  * not want a user to change this information unless they run a DML command.
35  *
36  * @author Tobias Downer
37  */

38
39 abstract class GTDataSource implements MutableTableDataSource {
40
41   /**
42    * The TransactionSystem object for this table.
43    */

44   private TransactionSystem system;
45
46
47   /**
48    * Constructor.
49    */

50   public GTDataSource(TransactionSystem system) {
51     this.system = system;
52   }
53
54   /**
55    * Returns a TObject that represents a value for the given column in this
56    * table. The Object must be of a compatible class to store in the type
57    * of the column defined.
58    */

59   protected TObject columnValue(int column, Object JavaDoc ob) {
60     TType type = getDataTableDef().columnAt(column).getTType();
61     return new TObject(type, ob);
62   }
63
64   // ---------- Implemented from TableDataSource ----------
65

66   public TransactionSystem getSystem() {
67     return system;
68   }
69
70   public abstract DataTableDef getDataTableDef();
71
72   public abstract int getRowCount();
73
74   public RowEnumeration rowEnumeration() {
75     return new SimpleRowEnumeration(getRowCount());
76   }
77
78   public SelectableScheme getColumnScheme(int column) {
79     return new BlindSearch(this, column);
80   }
81
82   public abstract TObject getCellContents(final int column, final int row);
83
84   // ---------- Implemented from MutableTableDataSource ----------
85

86   public int addRow(RowData row_data) {
87     throw new RuntimeException JavaDoc("Functionality not available.");
88   }
89
90   public void removeRow(int row_index) {
91     throw new RuntimeException JavaDoc("Functionality not available.");
92   }
93
94   public int updateRow(int row_index, RowData row_data) {
95     throw new RuntimeException JavaDoc("Functionality not available.");
96   }
97
98   public MasterTableJournal getJournal() {
99     throw new RuntimeException JavaDoc("Functionality not available.");
100   }
101
102   public void flushIndexChanges() {
103     throw new RuntimeException JavaDoc("Functionality not available.");
104   }
105   
106   public void constraintIntegrityCheck() {
107     throw new RuntimeException JavaDoc("Functionality not available.");
108   }
109
110   public void dispose() {
111   }
112
113   public void addRootLock() {
114     // No need to lock roots
115
}
116
117   public void removeRootLock() {
118     // No need to lock roots
119
}
120
121   // ---------- Static ----------
122

123   /**
124    * Convenience methods for constructing a DataTableDef for the dynamically
125    * generated table.
126    */

127   protected static DataTableColumnDef stringColumn(String JavaDoc name) {
128     DataTableColumnDef column = new DataTableColumnDef();
129     column.setName(name);
130     column.setNotNull(true);
131     column.setSQLType(SQLTypes.VARCHAR);
132     column.setSize(Integer.MAX_VALUE);
133     column.setScale(-1);
134     column.setIndexScheme("BlindSearch");
135     column.initTTypeInfo();
136     return column;
137   }
138
139   protected static DataTableColumnDef booleanColumn(String JavaDoc name) {
140     DataTableColumnDef column = new DataTableColumnDef();
141     column.setName(name);
142     column.setNotNull(true);
143     column.setSQLType(SQLTypes.BIT);
144     column.setSize(-1);
145     column.setScale(-1);
146     column.setIndexScheme("BlindSearch");
147     column.initTTypeInfo();
148     return column;
149   }
150
151   protected static DataTableColumnDef numericColumn(String JavaDoc name) {
152     DataTableColumnDef column = new DataTableColumnDef();
153     column.setName(name);
154     column.setNotNull(true);
155     column.setSQLType(SQLTypes.NUMERIC);
156     column.setSize(-1);
157     column.setScale(-1);
158     column.setIndexScheme("BlindSearch");
159     column.initTTypeInfo();
160     return column;
161   }
162
163   protected static DataTableColumnDef dateColumn(String JavaDoc name) {
164     DataTableColumnDef column = new DataTableColumnDef();
165     column.setName(name);
166     column.setNotNull(true);
167     column.setSQLType(SQLTypes.TIMESTAMP);
168     column.setSize(-1);
169     column.setScale(-1);
170     column.setIndexScheme("BlindSearch");
171     column.initTTypeInfo();
172     return column;
173   }
174
175 }
176
Popular Tags