KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.btree.index.B2IMaxScan
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.types.RowLocation;
34 import org.apache.derby.iapi.store.access.ScanController;
35 import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;
36 import org.apache.derby.iapi.store.access.TransactionController;
37
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.services.io.FormatableBitSet;
44
45 import org.apache.derby.impl.store.access.btree.BTreeController;
46 import org.apache.derby.impl.store.access.btree.BTreeLockingPolicy;
47 import org.apache.derby.impl.store.access.btree.BTreeMaxScan;
48
49 import org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil;
50
51 /**
52 Scan used to find maximum value in the secondary index.
53
54 This class implements an optimized interface to find the maximum row,
55 for a set of rows between an input start and stop key.
56
57 Note most work of this class is inherited from the generic btree implementation.
58 This class initializes the top level object and deals with locking information
59 specific to a secondary index implementation of a btree.
60
61 **/

62
63 public class B2IMaxScan extends BTreeMaxScan
64 {
65
66     /*
67     ** Fields of B2IMaxScan.
68     */

69     private ConglomerateController base_cc_for_locking;
70
71     /*
72     ** Methods of B2IMaxScan.
73     */

74
75     B2IMaxScan()
76     {
77         // Perform the generic b-tree scan construction.
78
super();
79     }
80
81     /**
82     Close the scan.
83     @see GenericScanController#newRowLocationTemplate
84     **/

85     public void close()
86         throws StandardException
87     {
88         super.close();
89
90         if (base_cc_for_locking != null)
91         {
92             base_cc_for_locking.close();
93             base_cc_for_locking = null;
94         }
95     }
96
97     /**
98     Close the scan, a commit or abort is about to happen.
99     **/

100     public boolean closeForEndTransaction(boolean closeHeldScan)
101         throws StandardException
102     {
103         boolean ret_val = super.closeForEndTransaction(closeHeldScan);
104
105         if (SanityManager.DEBUG)
106             SanityManager.ASSERT(
107                 ret_val, "B2IMaxScan never should be held across a commit.");
108
109         if (base_cc_for_locking != null)
110         {
111             base_cc_for_locking.close();
112             base_cc_for_locking = null;
113         }
114
115         return(ret_val);
116     }
117
118     /**
119     Initialize the scan for use.
120     <p>
121     Any changes to this method may have to be reflected in close as well.
122     <p>
123     The btree init opens the container (super.init), and stores away the
124     state of the qualifiers. The actual searching for the first position
125     is delayed until the first next() call.
126
127     @exception StandardException Standard exception policy.
128     **/

129     public void init(
130     TransactionManager xact_manager,
131     Transaction rawtran,
132     int open_mode,
133     int lock_level,
134     LockingPolicy locking_policy,
135     int isolation_level,
136     boolean open_for_locking,
137     FormatableBitSet scanColumnList,
138     B2I conglomerate,
139     B2IUndo undo)
140         throws StandardException
141     {
142         // open and lock the base table.
143

144         int base_open_mode =
145             open_mode | TransactionController.OPENMODE_FOR_LOCK_ONLY;
146
147         // open the base conglomerate - just to get lock
148
base_cc_for_locking =
149             xact_manager.openConglomerate(
150                 conglomerate.baseConglomerateId, false,
151                 base_open_mode, lock_level,
152                 isolation_level);
153         
154         BTreeLockingPolicy b2i_locking_policy =
155             conglomerate.getBtreeLockingPolicy(
156                 rawtran, lock_level, open_mode, isolation_level,
157                 base_cc_for_locking, this);
158
159         super.init(
160             xact_manager,
161             rawtran,
162             false,
163             open_mode,
164             lock_level,
165             b2i_locking_policy,
166             scanColumnList,
167             (DataValueDescriptor[]) null,// no start position supported
168
ScanController.NA, // no start position supported
169
(Qualifier[][]) null, // no qualifier supported
170
(DataValueDescriptor[]) null,// no stop position supported
171
ScanController.NA, // no stop position supported
172
conglomerate,
173             undo,
174             (StaticCompiledOpenConglomInfo) null,
175             (DynamicCompiledOpenConglomInfo) null);
176     }
177 }
178
Popular Tags