KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > sql > dictionary > CheckConstraintDescriptor


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.dictionary.CheckConstraintDescriptor
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.iapi.sql.dictionary;
23 import org.apache.derby.catalog.ReferencedColumns;
24 import org.apache.derby.catalog.UUID;
25 import org.apache.derby.iapi.services.sanity.SanityManager;
26 import org.apache.derby.iapi.sql.StatementType;
27
28 /**
29  * This class represents a check constraint descriptor.
30  *
31  * @author jamie
32  */

33 public class CheckConstraintDescriptor extends ConstraintDescriptor
34 {
35     ReferencedColumns referencedColumns;
36     String JavaDoc constraintText;
37
38     CheckConstraintDescriptor(
39             DataDictionary dataDictionary,
40             TableDescriptor table,
41             String JavaDoc constraintName,
42             boolean deferrable,
43             boolean initiallyDeferred,
44             UUID constraintId,
45             String JavaDoc constraintText,
46             ReferencedColumns referencedColumns,
47             SchemaDescriptor schemaDesc,
48             boolean isEnabled
49             )
50     {
51         super(dataDictionary, table, constraintName, deferrable,
52               initiallyDeferred, (int []) null,
53               constraintId, schemaDesc, isEnabled);
54         this.constraintText = constraintText;
55         this.referencedColumns = referencedColumns;
56     }
57
58     /**
59      * Does this constraint have a backing index?
60      *
61      * @return boolean Whether or not there is a backing index for this constraint.
62      */

63     public boolean hasBackingIndex()
64     {
65         return false;
66     }
67
68     /**
69      * Gets an identifier telling what type of descriptor it is
70      * (UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK).
71      *
72      * @return An identifier telling what type of descriptor it is
73      * (UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK).
74      */

75     public int getConstraintType()
76     {
77         return DataDictionary.CHECK_CONSTRAINT;
78     }
79
80     /**
81      * Get the text of the constraint. (Only non-null/meaningful for check
82      * constraints.)
83      * @return The constraint text.
84      */

85     public String JavaDoc getConstraintText()
86     {
87         return constraintText;
88     }
89
90     /**
91      * Get the UUID of the backing index, if one exists.
92      *
93      * @return The UUID of the backing index, if one exists, else null.
94      */

95     public UUID getConglomerateId()
96     {
97         return null;
98     }
99
100     /**
101      * Get the ReferencedColumns.
102      *
103      * @return The ReferencedColumns.
104      */

105     public ReferencedColumns getReferencedColumnsDescriptor()
106     {
107         return referencedColumns;
108     }
109
110     /**
111      * Set the ReferencedColumns; used in drop column
112      *
113      * @param rcd The new ReferencedColumns.
114      */

115     public void setReferencedColumnsDescriptor(ReferencedColumns rcd)
116     {
117         referencedColumns = rcd;
118     }
119
120     /**
121      * Get the referenced columns as an int[] of column ids.
122      *
123      * @return The array of referenced column ids.
124      */

125     public int[] getReferencedColumns()
126     {
127         return referencedColumns.getReferencedColumnPositions();
128     }
129
130     /**
131      * Does this constraint need to fire on this type of
132      * DML? For a check constraint, all inserts, and
133      * appropriate updates
134      *
135      * @param stmtType the type of DML
136      * (StatementType.INSERT|StatementType.UPDATE|StatementType.DELETE)
137      * @param modifiedCols the columns modified, or null for all
138      *
139      * @return true/false
140      */

141     public boolean needsToFire(int stmtType, int[] modifiedCols)
142     {
143         /*
144         ** If we are disabled, we never fire
145         */

146         if (!isEnabled)
147         {
148             return false;
149         }
150
151         if (stmtType == StatementType.INSERT)
152         {
153             return true;
154         }
155
156         if (stmtType == StatementType.DELETE)
157         {
158             return false;
159         }
160     
161         // if update, only relevant if columns intersect
162
return doColumnsIntersect(modifiedCols, getReferencedColumns());
163     }
164
165     /**
166      * Convert the CheckConstraintDescriptor to a String.
167      *
168      * @return A String representation of this CheckConstraintDescriptor
169      */

170
171     public String JavaDoc toString()
172     {
173         if (SanityManager.DEBUG)
174         {
175             return "constraintText: " + constraintText + "\n" +
176                "referencedColumns: " + referencedColumns + "\n" +
177                 super.toString();
178         }
179         else
180         {
181             return "";
182         }
183     }
184
185
186 }
187
Popular Tags