KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * com.mckoi.database.TableAccessState 13 Sep 1998
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 /**
28  * This class provides very limited access to a Table object. The purpose of
29  * this object is to define the functionality of a table when the root table(s)
30  * are locked via the 'Table.lockRoot(int)' method, and when the Table is no
31  * longer READ or WRITE locked via the 'LockingMechanism' system. During these
32  * conditions, the table is in a semi-volatile state, so this class provides
33  * a safe way to access the table without having to worry about using some
34  * functionality of Table which isn't supported at this time.
35  *
36  * @author Tobias Downer
37  */

38
39 public final class TableAccessState {
40
41   /**
42    * The underlying Table object.
43    */

44   private Table table;
45
46   /**
47    * Set to true when the table is first locked.
48    */

49   private boolean been_locked;
50
51   /**
52    * The Constructor.
53    */

54   TableAccessState(Table table) {
55     this.table = table;
56     been_locked = false;
57   }
58
59   /**
60    * Returns the cell at the given row/column coordinates in the table.
61    * This method is valid because it doesn't use any of the SelectableScheme
62    * information in any of its parent tables which could change at any time
63    * when there is no READ or WRITE lock on the table.
64    */

65   public TObject getCellContents(int column, int row) {
66     return table.getCellContents(column, row);
67   }
68
69   /**
70    * Returns the DataTableDef object that contains information on the columns
71    * of the table.
72    */

73   public DataTableDef getDataTableDef() {
74     return table.getDataTableDef();
75   }
76
77   /**
78    * Returns the TableName of the given column of this table. This, together
79    * with 'getDataTableDef' is used to find the fully qualified name of a
80    * column of the table.
81    */

82   public Variable getResolvedVariable(int column) {
83     return table.getResolvedVariable(column);
84   }
85
86 // /**
87
// * Returns the TableField object of the given column.
88
// * This information is constant per table.
89
// */
90
// public TableField getFieldAt(int column) {
91
// return table.getFieldAt(column);
92
// }
93

94 // /**
95
// * Returns a fully resolved name of the given column.
96
// */
97
// public String getResolvedColumnName(int column) {
98
// return table.getResolvedColumnName(column);
99
// }
100

101   /**
102    * Locks the root rows of the table.
103    * This method is a bit of a HACK - why should the contract include being
104    * able to lock the root rows?
105    * This method only permits the roots to be locked once.
106    */

107   public void lockRoot(int key) {
108     if (!been_locked) {
109       table.lockRoot(key);
110       been_locked = true;
111     }
112   }
113
114   /**
115    * Unlocks the root rows of the table.
116    */

117   public void unlockRoot(int key) {
118     if (been_locked) { // && table.hasRootsLocked()) {
119
table.unlockRoot(key);
120       been_locked = false;
121     }
122     else {
123       throw new RuntimeException JavaDoc("The root rows aren't locked.");
124     }
125   }
126
127 }
128
Popular Tags