KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > catalog > DropDependencyFilter


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.catalog.DropDependencyFilter
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.catalog;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25
26 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
27
28 import org.apache.derby.iapi.types.DataValueDescriptor;
29
30 import org.apache.derby.iapi.types.BooleanDataValue;
31
32 import org.apache.derby.iapi.sql.execute.ExecutionFactory;
33
34 import org.apache.derby.iapi.services.context.ContextService;
35 import org.apache.derby.iapi.types.DataValueFactory;
36
37 import org.apache.derby.iapi.services.monitor.Monitor;
38
39 import org.apache.derby.iapi.sql.execute.TupleFilter;
40 import org.apache.derby.iapi.sql.execute.ExecRow;
41 import org.apache.derby.iapi.error.StandardException;
42
43 import org.apache.derby.catalog.UUID;
44 import org.apache.derby.iapi.services.uuid.UUIDFactory;
45
46
47 /**
48 * A Filter to qualify tuples coming from a scan of SYSDEPENDS.
49 * Tuples qualify if they have the right providerID.
50 *
51 * @author Rick
52 */

53 public class DropDependencyFilter implements TupleFilter
54 {
55     //////////////////////////////////////////////////////////////////////////////////////
56
//
57
// CONSTANTS
58
//
59
//////////////////////////////////////////////////////////////////////////////////////
60

61
62     //////////////////////////////////////////////////////////////////////////////////////
63
//
64
// STATE
65
//
66
//////////////////////////////////////////////////////////////////////////////////////
67

68     UUID providerID;
69
70     UUIDFactory uuidFactory = null;
71     DataValueFactory dataValueFactory = null;
72
73     BooleanDataValue trueValue;
74     BooleanDataValue falseValue;
75
76     //////////////////////////////////////////////////////////////////////////////////////
77
//
78
// CONSTRUCTORS
79
//
80
//////////////////////////////////////////////////////////////////////////////////////
81

82     /**
83       * Construct a TupleFilter to qualify SYSDEPENDS rows with the
84       * designated providerID.
85       *
86       * @param providerID UUID of provider. Tuples with this ID qualify.
87       */

88     public DropDependencyFilter( UUID providerID )
89     {
90         this.providerID = providerID;
91     }
92
93
94     //////////////////////////////////////////////////////////////////////////////////////
95
//
96
// TupleFilter BEHAVIOR
97
//
98
//////////////////////////////////////////////////////////////////////////////////////
99

100     /**
101       * Initialize a Filter with a vector of parameters. This is a NOP.
102       * We initialize this filter at Constructor time.
103       *
104       * @param parameters An ExecRow of parameter values
105       *
106       * @exception StandardException Thrown on error
107       */

108     public void init( ExecRow parameters )
109         throws StandardException
110     {}
111
112     /**
113       * Pump a SYSDEPENDS row through the Filter. If the providerID of the
114       * row matches our providerID, we return true. Otherwise we return false.
115       *
116       * @param currentRow SYSDEPENDS row
117       *
118       * @return True if the row has our providerID. False otherwise.
119       *
120       * @exception StandardException Thrown on error
121       */

122     public BooleanDataValue execute( ExecRow currentRow )
123         throws StandardException
124     {
125         /* 3rd column is PROVIDERID (UUID - char(36)) */
126         DataValueDescriptor col = currentRow.getColumn(SYSDEPENDSRowFactory.SYSDEPENDS_PROVIDERID);
127         String JavaDoc providerIDstring = col.getString();
128         UUID providerUUID = getUUIDFactory().recreateUUID(providerIDstring);
129
130         if ( providerID.equals( providerUUID ) ) { return getTrueValue(); }
131         else { return getFalseValue(); }
132     }
133
134
135     //////////////////////////////////////////////////////////////////////////////////////
136
//
137
// MINIONS
138
//
139
//////////////////////////////////////////////////////////////////////////////////////
140

141
142     /**
143       * Get the UUID factory
144       *
145       * @return the UUID factory
146       *
147       * @exception StandardException thrown on failure
148       */

149     private UUIDFactory getUUIDFactory()
150         throws StandardException
151     {
152         if ( uuidFactory == null )
153         {
154             uuidFactory = Monitor.getMonitor().getUUIDFactory();
155         }
156         return uuidFactory;
157     }
158
159     /**
160       * Gets the DataValueFactory for this connection.
161       *
162       * @return the data value factory for this connection
163       */

164     private DataValueFactory getDataValueFactory()
165     {
166         if ( dataValueFactory == null )
167         {
168             LanguageConnectionContext lcc = (LanguageConnectionContext)
169                                               ContextService.getContext
170                                               (LanguageConnectionContext.CONTEXT_ID);
171
172             dataValueFactory = lcc.getDataValueFactory();
173         }
174
175         return dataValueFactory;
176     }
177
178     /**
179       * Gets a BooleanDataValue representing TRUE.
180       *
181       * @return a TRUE value
182       * @exception StandardException Thrown on error
183       */

184     private BooleanDataValue getTrueValue()
185         throws StandardException
186     {
187         if ( trueValue == null )
188         {
189             trueValue = getDataValueFactory().getDataValue( true );
190         }
191
192         return trueValue;
193     }
194
195     /**
196       * Gets a BooleanDataValue representing FALSE
197       *
198       * @return a FALSE value
199       * @exception StandardException Thrown on error
200       */

201     private BooleanDataValue getFalseValue()
202         throws StandardException
203     {
204         if ( falseValue == null )
205         {
206             falseValue = getDataValueFactory().getDataValue( false );
207         }
208
209         return falseValue;
210     }
211
212 }
213
Popular Tags