KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > TableElementNode


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.TableElementNode
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.compile;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25
26 /**
27  * A TableElementNode is an item in a TableElementList, and represents
28  * a single table element such as a column or constraint in a CREATE TABLE
29  * or ALTER TABLE statement.
30  *
31  * @author Jeff Lichtman
32  */

33
34 public class TableElementNode extends QueryTreeNode
35 {
36     /////////////////////////////////////////////////////////////////////////
37
//
38
// CONSTANTS
39
//
40
/////////////////////////////////////////////////////////////////////////
41

42     public static final int AT_UNKNOWN = 0;
43     public static final int AT_ADD_FOREIGN_KEY_CONSTRAINT = 1;
44     public static final int AT_ADD_PRIMARY_KEY_CONSTRAINT = 2;
45     public static final int AT_ADD_UNIQUE_CONSTRAINT = 3;
46     public static final int AT_ADD_CHECK_CONSTRAINT = 4;
47     public static final int AT_DROP_CONSTRAINT = 5;
48     public static final int AT_MODIFY_COLUMN = 6;
49     public static final int AT_DROP_COLUMN = 7;
50
51
52     /////////////////////////////////////////////////////////////////////////
53
//
54
// STATE
55
//
56
/////////////////////////////////////////////////////////////////////////
57

58     String JavaDoc name;
59     int elementType; // simple element nodes can share this class,
60
// eg., drop column and rename table/column/index
61
// etc., no need for more classes, an effort to
62
// minimize footprint
63

64     /////////////////////////////////////////////////////////////////////////
65
//
66
// BEHAVIOR
67
//
68
/////////////////////////////////////////////////////////////////////////
69

70     /**
71      * Initializer for a TableElementNode
72      *
73      * @param name The name of the table element, if any
74      */

75
76     public void init(Object JavaDoc name)
77     {
78         this.name = (String JavaDoc) name;
79     }
80
81     /**
82      * Initializer for a TableElementNode
83      *
84      * @param name The name of the table element, if any
85      */

86
87     public void init(Object JavaDoc name, Object JavaDoc elementType)
88     {
89         this.name = (String JavaDoc) name;
90         this.elementType = ((Integer JavaDoc) elementType).intValue();
91     }
92
93     /**
94      * Convert this object to a String. See comments in QueryTreeNode.java
95      * for how this should be done for tree printing.
96      *
97      * @return This object as a String
98      */

99
100     public String JavaDoc toString()
101     {
102         if (SanityManager.DEBUG)
103         {
104             return "name: " + name + "\n" +
105                 super.toString();
106         }
107         else
108         {
109             return "";
110         }
111     }
112
113     /**
114      * Does this element have a primary key constraint.
115      *
116      * @return boolean Whether or not this element has a primary key constraint
117      */

118     boolean hasPrimaryKeyConstraint()
119     {
120         return false;
121     }
122
123     /**
124      * Does this element have a unique key constraint.
125      *
126      * @return boolean Whether or not this element has a unique key constraint
127      */

128     boolean hasUniqueKeyConstraint()
129     {
130         return false;
131     }
132
133     /**
134      * Does this element have a foreign key constraint.
135      *
136      * @return boolean Whether or not this element has a foreign key constraint
137      */

138     boolean hasForeignKeyConstraint()
139     {
140         return false;
141     }
142
143     /**
144      * Does this element have a check constraint.
145      *
146      * @return boolean Whether or not this element has a check constraint
147      */

148     boolean hasCheckConstraint()
149     {
150         return false;
151     }
152
153     /**
154      * Does this element have a constraint on it.
155      *
156      * @return boolean Whether or not this element has a constraint on it
157      */

158     boolean hasConstraint()
159     {
160         return false;
161     }
162
163     /**
164      * Get the name from this node.
165      *
166      * @return String The name.
167      */

168     public String JavaDoc getName()
169     {
170         return name;
171     }
172
173     /**
174       * Get the type of this table element.
175       *
176       * @return one of the constants at the front of this file
177       */

178     int getElementType()
179     {
180         if ( hasForeignKeyConstraint() ) { return AT_ADD_FOREIGN_KEY_CONSTRAINT; }
181         else if ( hasPrimaryKeyConstraint() ) { return AT_ADD_PRIMARY_KEY_CONSTRAINT; }
182         else if ( hasUniqueKeyConstraint() ) { return AT_ADD_UNIQUE_CONSTRAINT; }
183         else if ( hasCheckConstraint() ) { return AT_ADD_CHECK_CONSTRAINT; }
184         else if ( this instanceof ConstraintDefinitionNode ) { return AT_DROP_CONSTRAINT; }
185         else if ( this instanceof ModifyColumnNode ) { return AT_MODIFY_COLUMN; }
186         else { return elementType; }
187     }
188
189 }
190
Popular Tags