001: /**
002: * com.mckoi.database.GTDataSource 27 Apr 2001
003: *
004: * Mckoi SQL Database ( http://www.mckoi.com/database )
005: * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * Version 2 as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License Version 2 for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * Version 2 along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: * Change Log:
021: *
022: *
023: */package com.mckoi.database;
024:
025: import com.mckoi.database.global.SQLTypes;
026:
027: /**
028: * A base class for a dynamically generated data source. While this inherits
029: * MutableTableDataSource (so we can make a DataTable out of it) a GTDataSource
030: * derived class may not be mutable. For example, an implementation of this
031: * class may produce a list of a columns in all tables. You would typically
032: * not want a user to change this information unless they run a DML command.
033: *
034: * @author Tobias Downer
035: */
036:
037: abstract class GTDataSource implements MutableTableDataSource {
038:
039: /**
040: * The TransactionSystem object for this table.
041: */
042: private TransactionSystem system;
043:
044: /**
045: * Constructor.
046: */
047: public GTDataSource(TransactionSystem system) {
048: this .system = system;
049: }
050:
051: /**
052: * Returns a TObject that represents a value for the given column in this
053: * table. The Object must be of a compatible class to store in the type
054: * of the column defined.
055: */
056: protected TObject columnValue(int column, Object ob) {
057: TType type = getDataTableDef().columnAt(column).getTType();
058: return new TObject(type, ob);
059: }
060:
061: // ---------- Implemented from TableDataSource ----------
062:
063: public TransactionSystem getSystem() {
064: return system;
065: }
066:
067: public abstract DataTableDef getDataTableDef();
068:
069: public abstract int getRowCount();
070:
071: public RowEnumeration rowEnumeration() {
072: return new SimpleRowEnumeration(getRowCount());
073: }
074:
075: public SelectableScheme getColumnScheme(int column) {
076: return new BlindSearch(this , column);
077: }
078:
079: public abstract TObject getCellContents(final int column,
080: final int row);
081:
082: // ---------- Implemented from MutableTableDataSource ----------
083:
084: public int addRow(RowData row_data) {
085: throw new RuntimeException("Functionality not available.");
086: }
087:
088: public void removeRow(int row_index) {
089: throw new RuntimeException("Functionality not available.");
090: }
091:
092: public int updateRow(int row_index, RowData row_data) {
093: throw new RuntimeException("Functionality not available.");
094: }
095:
096: public MasterTableJournal getJournal() {
097: throw new RuntimeException("Functionality not available.");
098: }
099:
100: public void flushIndexChanges() {
101: throw new RuntimeException("Functionality not available.");
102: }
103:
104: public void constraintIntegrityCheck() {
105: throw new RuntimeException("Functionality not available.");
106: }
107:
108: public void dispose() {
109: }
110:
111: public void addRootLock() {
112: // No need to lock roots
113: }
114:
115: public void removeRootLock() {
116: // No need to lock roots
117: }
118:
119: // ---------- Static ----------
120:
121: /**
122: * Convenience methods for constructing a DataTableDef for the dynamically
123: * generated table.
124: */
125: protected static DataTableColumnDef stringColumn(String name) {
126: DataTableColumnDef column = new DataTableColumnDef();
127: column.setName(name);
128: column.setNotNull(true);
129: column.setSQLType(SQLTypes.VARCHAR);
130: column.setSize(Integer.MAX_VALUE);
131: column.setScale(-1);
132: column.setIndexScheme("BlindSearch");
133: column.initTTypeInfo();
134: return column;
135: }
136:
137: protected static DataTableColumnDef booleanColumn(String name) {
138: DataTableColumnDef column = new DataTableColumnDef();
139: column.setName(name);
140: column.setNotNull(true);
141: column.setSQLType(SQLTypes.BIT);
142: column.setSize(-1);
143: column.setScale(-1);
144: column.setIndexScheme("BlindSearch");
145: column.initTTypeInfo();
146: return column;
147: }
148:
149: protected static DataTableColumnDef numericColumn(String name) {
150: DataTableColumnDef column = new DataTableColumnDef();
151: column.setName(name);
152: column.setNotNull(true);
153: column.setSQLType(SQLTypes.NUMERIC);
154: column.setSize(-1);
155: column.setScale(-1);
156: column.setIndexScheme("BlindSearch");
157: column.initTTypeInfo();
158: return column;
159: }
160:
161: protected static DataTableColumnDef dateColumn(String name) {
162: DataTableColumnDef column = new DataTableColumnDef();
163: column.setName(name);
164: column.setNotNull(true);
165: column.setSQLType(SQLTypes.TIMESTAMP);
166: column.setSize(-1);
167: column.setScale(-1);
168: column.setIndexScheme("BlindSearch");
169: column.initTTypeInfo();
170: return column;
171: }
172:
173: }
|