KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > interpret > FromTableDef


1 /**
2  * com.mckoi.database.interpret.FromTableDef 31 Oct 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.interpret;
26
27 import com.mckoi.database.ExpressionPreparer;
28 import com.mckoi.database.DatabaseException;
29 import com.mckoi.database.StatementTree;
30
31 /**
32  * Describes a single table declaration in the from clause of a table
33  * expression (SELECT).
34  *
35  * @author Tobias Downer
36  */

37
38 public final class FromTableDef implements java.io.Serializable JavaDoc, Cloneable JavaDoc {
39
40   static final long serialVersionUID = -606852454508224625L;
41
42   /**
43    * If this is true, then the table def represents a sub-query table.
44    * The 'getSubSelectStatement' and 'getAlias' method can be used to
45    * get the table information.
46    * <p>
47    * eg. FROM ( SELECT id, number FROM Part ) AS part_info, ....
48    */

49   private boolean subquery_table;
50
51   /**
52    * The unique key name given to this table definition.
53    */

54   private String JavaDoc unique_key;
55
56   /**
57    * The name of the table this definition references.
58    */

59   private String JavaDoc table_name;
60
61   /**
62    * The alias of the table or null if no alias was defined.
63    */

64   private String JavaDoc table_alias;
65
66   /**
67    * The TableSelectExpression if this is a subquery table.
68    */

69   private TableSelectExpression subselect_table;
70
71   /**
72    * Constructs the table def. The constructs a table that is aliased under
73    * a different name.
74    */

75   public FromTableDef(String JavaDoc table_name, String JavaDoc table_alias) {
76     this.table_name = table_name;
77     this.table_alias = table_alias;
78     subselect_table = null;
79     subquery_table = false;
80   }
81
82   /**
83    * A simple table definition (not aliased).
84    */

85   public FromTableDef(String JavaDoc table_name) {
86     this(table_name, null);
87   }
88
89   /**
90    * A table that is a sub-query and given an aliased name.
91    */

92   public FromTableDef(TableSelectExpression select, String JavaDoc table_alias) {
93     this.subselect_table = select;
94     this.table_name = table_alias;
95     this.table_alias = table_alias;
96     subquery_table = true;
97   }
98
99   /**
100    * A simple sub-query table definition (not aliased).
101    */

102   public FromTableDef(TableSelectExpression select) {
103     this.subselect_table = select;
104     this.table_name = null;
105     this.table_alias = null;
106     subquery_table = true;
107   }
108
109
110   /**
111    * Sets the unique key.
112    */

113   public void setUniqueKey(String JavaDoc unique_key) {
114     this.unique_key = unique_key;
115   }
116
117   /**
118    * Returns the name of the table.
119    */

120   public String JavaDoc getName() {
121     return table_name;
122   }
123
124   /**
125    * Returns the alias for this table (or null if no alias given).
126    */

127   public String JavaDoc getAlias() {
128     return table_alias;
129   }
130
131   /**
132    * Returns the unique key.
133    */

134   public String JavaDoc getUniqueKey() {
135     return unique_key;
136   }
137
138   /**
139    * Returns true if this item in the FROM clause is a subquery table.
140    */

141   public boolean isSubQueryTable() {
142     return subquery_table;
143   }
144
145   /**
146    * Returns the TableSelectExpression if this is a subquery table.
147    */

148   public TableSelectExpression getTableSelectExpression() {
149     return subselect_table;
150   }
151
152   /**
153    * Prepares the expressions in this table def.
154    */

155   public void prepareExpressions(ExpressionPreparer preparer)
156                                                  throws DatabaseException {
157     if (subselect_table != null) {
158       subselect_table.prepareExpressions(preparer);
159     }
160   }
161
162   /**
163    * Clones the object (deep clone of immutable members).
164    */

165   public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
166     FromTableDef v = (FromTableDef) super.clone();
167     if (subselect_table != null) {
168       v.subselect_table = (TableSelectExpression) subselect_table.clone();
169     }
170     return v;
171   }
172
173 }
174
Popular Tags