KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > btree > index > B2IForwardScan


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.btree.index.B2IForwardScan
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.store.access.btree.index;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25
26 import org.apache.derby.iapi.error.StandardException;
27 import org.apache.derby.iapi.store.access.conglomerate.Conglomerate;
28 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;
29 import org.apache.derby.iapi.store.access.ConglomerateController;
30 import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;
31 import org.apache.derby.iapi.store.access.GenericScanController;
32 import org.apache.derby.iapi.store.access.Qualifier;
33 import org.apache.derby.iapi.store.access.ScanController;
34 import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;
35 import org.apache.derby.iapi.store.access.TransactionController;
36
37 import org.apache.derby.iapi.store.raw.ContainerHandle;
38 import org.apache.derby.iapi.store.raw.LockingPolicy;
39 import org.apache.derby.iapi.store.raw.Transaction;
40
41 import org.apache.derby.iapi.types.DataValueDescriptor;
42
43 import org.apache.derby.iapi.types.RowLocation;
44
45 import org.apache.derby.iapi.services.io.FormatableBitSet;
46
47 import org.apache.derby.impl.store.access.btree.BTreeController;
48 import org.apache.derby.impl.store.access.btree.BTreeLockingPolicy;
49 import org.apache.derby.impl.store.access.btree.BTreeForwardScan;
50
51 import org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil;
52
53 /**
54
55 The btree secondary index implementation of ScanManager which provides reading
56 and deleting of entries in the btree secondary index.
57
58 This supports setting up and
59 iterating through a set of rows while providing a start key, stop key,
60 and a set of AND and OR qualifiers to skip unwanted rows. Currently
61 derby only supports forward scans (but individual columns can have
62 descending order). This interface is also used to delete rows from
63 the conglomerate. Note that update is not supported, it must be
64 implemented as a delete, followed by an insert.
65
66 Note most work of this class is inherited from the generic btree implementation.
67 This class initializes the top level object and deals with locking information
68 specific to a secondary index implementation of a btree.
69
70 **/

71
72 public class B2IForwardScan extends BTreeForwardScan
73 {
74
75     /*
76     ** Fields of B2IForwardScan.
77     */

78     private ConglomerateController base_cc_for_locking;
79     private int init_isolation_level;
80
81     /*
82     ** Methods of B2IForwardScan.
83     */

84
85     B2IForwardScan()
86     {
87         // Perform the generic b-tree scan construction.
88
super();
89     }
90
91     /**
92     Close the scan.
93     @see GenericScanController#newRowLocationTemplate
94     **/

95     public void close()
96         throws StandardException
97     {
98         super.close();
99
100         if (base_cc_for_locking != null)
101         {
102             base_cc_for_locking.close();
103             base_cc_for_locking = null;
104         }
105     }
106
107
108     /**
109     Close the scan, a commit or abort is about to happen.
110     **/

111     public boolean closeForEndTransaction(boolean closeHeldScan)
112         throws StandardException
113     {
114         boolean ret_val = super.closeForEndTransaction(closeHeldScan);
115
116         if (base_cc_for_locking != null)
117         {
118             base_cc_for_locking.close();
119             base_cc_for_locking = null;
120         }
121
122         return(ret_val);
123     }
124
125     /**
126      * Open the container after it has been closed previously.
127      * <p>
128      * Open the container, obtaining necessary locks. Most work is actually
129      * done by RawStore.openContainer(). Will only reopen() if the container
130      * is not already open.
131      *
132      * @exception StandardException Standard exception policy.
133      **/

134     public ContainerHandle reopen()
135         throws StandardException
136     {
137
138         ContainerHandle container = super.reopen();
139         B2I b2i = (B2I) getConglomerate();
140
141         // open and lock the base table.
142

143         int base_open_mode =
144             getOpenMode() | TransactionController.OPENMODE_FOR_LOCK_ONLY;
145
146
147         // TODO - figure out what to do with static_info stuff
148

149
150         // open the base conglomerate - just to get lock
151
/*
152         if (static_info != null)
153         {
154             base_cc_for_locking =
155                 xact_manager.openCompiledConglomerate(
156                     false,
157                     base_open_mode, lock_level, isolation_level,
158                     static_info.base_table_static_info,
159                     ((Conglomerate) static_info.getConglom()).
160                         getDynamicCompiledConglomInfo(
161                             b2i.baseConglomerateId));
162         }
163         else
164         */

165         {
166             base_cc_for_locking =
167                 getXactMgr().openConglomerate(
168                     b2i.baseConglomerateId,
169                     false,
170                     base_open_mode, init_lock_level,
171                     init_isolation_level);
172
173             setLockingPolicy(
174                 b2i.getBtreeLockingPolicy(
175                     getXactMgr().getRawStoreXact(),
176                     getLockLevel(),
177                     getOpenMode(),
178                     init_isolation_level,
179                     base_cc_for_locking, this));
180         }
181         
182         return(container);
183     }
184
185
186     /**
187     Initialize the scan for use.
188     <p>
189     Any changes to this method may have to be reflected in close as well.
190     <p>
191     The btree init opens the container (super.init), and stores away the
192     state of the qualifiers. The actual searching for the first position
193     is delayed until the first next() call.
194
195     @exception StandardException Standard exception policy.
196     **/

197     public void init(
198     TransactionManager xact_manager,
199     Transaction rawtran,
200     boolean hold,
201     int open_mode,
202     int lock_level,
203     LockingPolicy locking_policy,
204     int isolation_level,
205     boolean open_for_locking,
206     FormatableBitSet scanColumnList,
207     DataValueDescriptor[] startKeyValue,
208     int startSearchOperator,
209     Qualifier qualifier[][],
210     DataValueDescriptor[] stopKeyValue,
211     int stopSearchOperator,
212     B2I conglomerate,
213     B2IUndo undo,
214     B2IStaticCompiledInfo static_info,
215     DynamicCompiledOpenConglomInfo dynamic_info)
216         throws StandardException
217     {
218         // open and lock the base table.
219

220         int base_open_mode =
221             open_mode | TransactionController.OPENMODE_FOR_LOCK_ONLY;
222
223         // open the base conglomerate - just to get lock
224
if (static_info != null)
225         {
226             base_cc_for_locking =
227                 xact_manager.openCompiledConglomerate(
228                     false,
229                     base_open_mode, lock_level, isolation_level,
230                     static_info.base_table_static_info,
231                     /* TODO - maintain a dynamic info for this */
232                     ((Conglomerate) static_info.getConglom()).
233                         getDynamicCompiledConglomInfo(
234                             conglomerate.baseConglomerateId));
235         }
236         else
237         {
238             base_cc_for_locking =
239                 xact_manager.openConglomerate(
240                     conglomerate.baseConglomerateId, false, base_open_mode, lock_level,
241                     isolation_level);
242         }
243         
244         BTreeLockingPolicy b2i_locking_policy =
245             conglomerate.getBtreeLockingPolicy(
246                 rawtran, lock_level, open_mode, isolation_level,
247                 base_cc_for_locking, this);
248
249         super.init(
250             xact_manager,
251             rawtran,
252             hold,
253             open_mode,
254             lock_level,
255             b2i_locking_policy,
256             scanColumnList,
257             startKeyValue,
258             startSearchOperator,
259             qualifier,
260             stopKeyValue,
261             stopSearchOperator,
262             conglomerate,
263             undo,
264             static_info,
265             dynamic_info);
266
267
268         // todo - should just save the isolation level in OpenBtree but
269
// save it here for now.
270
init_isolation_level = isolation_level;
271     }
272 }
273
Popular Tags