KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.btree.index.B2IController
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 java.io.IOException JavaDoc;
25 import java.util.Properties JavaDoc;
26 import org.apache.derby.iapi.services.sanity.SanityManager;
27 import org.apache.derby.iapi.error.StandardException;
28 import org.apache.derby.iapi.store.access.conglomerate.Conglomerate;
29 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;
30 import org.apache.derby.iapi.store.access.ConglomerateController;
31 import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;
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.TransactionController;
36 import org.apache.derby.iapi.store.access.ConglomerateController;
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.impl.store.access.btree.BTreeController;
44 import org.apache.derby.impl.store.access.btree.BTreeLockingPolicy;
45
46 import org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil;
47
48 import org.apache.derby.iapi.services.io.FormatableBitSet;
49
50 /**
51  * Controller used to insert rows into a secondary index.
52  *
53  * Implements the ConglomerateController interface for the B-Tree index
54  * access method.
55  *
56  * Note most work of this class is inherited from the generic btree
57  * implementation. This class initializes the top level object and deals with
58  * locking information specific to a secondary index implementation of a btree.
59  */

60 public class B2IController extends BTreeController
61 {
62
63     /*
64     ** Fields of B2IController.
65     */

66     private ConglomerateController base_cc_for_locking;
67
68     /*
69     ** Methods of B2IController.
70     */

71
72     B2IController()
73     {
74         // Perform the generic b-tree construction.
75
super();
76     }
77
78     void init(
79     TransactionManager xact_manager,
80     Transaction rawtran,
81     boolean hold,
82     int open_mode,
83     int lock_level,
84     LockingPolicy locking_policy,
85     boolean get_locks,
86     B2I conglomerate,
87     B2IUndo undo,
88     B2IStaticCompiledInfo static_info,
89     DynamicCompiledOpenConglomInfo dynamic_info)
90         throws StandardException
91     {
92         // open and lock the base table.
93

94         int base_open_mode =
95             open_mode | TransactionController.OPENMODE_FOR_LOCK_ONLY;
96
97         // open the base conglomerate - just to get the lock. Since btree
98
// controllers only support update operations we just hard code
99
// the TransactionController.ISOLATION_REPEATABLE_READ, which is only
100
// used for geting the IX intent lock on the table.
101
if (static_info != null)
102         {
103             base_cc_for_locking =
104                 xact_manager.openCompiledConglomerate(
105                     false,
106                     base_open_mode, lock_level,
107                     TransactionController.ISOLATION_REPEATABLE_READ,
108                     static_info.base_table_static_info,
109                     /* TODO - maintain a dynamic info for this */
110                     ((Conglomerate) static_info.getConglom()).
111                         getDynamicCompiledConglomInfo(
112                             conglomerate.baseConglomerateId));
113         }
114         else
115         {
116             base_cc_for_locking =
117                 xact_manager.openConglomerate(
118                     conglomerate.baseConglomerateId,
119                     false,
120                     base_open_mode, lock_level,
121                     TransactionController.ISOLATION_REPEATABLE_READ);
122         }
123         
124         BTreeLockingPolicy b2i_locking_policy;
125         if (lock_level == TransactionController.MODE_TABLE)
126         {
127             b2i_locking_policy =
128                 new B2ITableLocking3(
129                     rawtran, lock_level, locking_policy,
130                     base_cc_for_locking, this);
131         }
132         else if (lock_level == TransactionController.MODE_RECORD)
133         {
134             b2i_locking_policy =
135                 new B2IRowLocking3(
136                     rawtran, lock_level, locking_policy,
137                     base_cc_for_locking, this);
138         }
139         else
140         {
141             if (SanityManager.DEBUG)
142             {
143                 SanityManager.THROWASSERT("Bad lock level: " + lock_level);
144             }
145             b2i_locking_policy = null;
146         }
147
148         // Do generic b-tree initialization.
149
super.init(
150             xact_manager,
151             hold,
152             (ContainerHandle) null,
153             rawtran,
154             open_mode,
155             lock_level,
156             b2i_locking_policy,
157             conglomerate,
158             undo,
159             static_info,
160             dynamic_info);
161
162         if (SanityManager.DEBUG)
163             SanityManager.ASSERT(conglomerate != null);
164     }
165
166     /*
167     ** Methods of ConglomerateController.
168     */

169
170     /**
171     Close the conglomerate controller.
172     <p>
173     Any changes to this method will probably have to be reflected in close as
174     well.
175     <p>
176     Currently delegates to OpenBTree. If the btree controller ends up not
177     having any state of its own, we can remove this method (the VM will
178     dispatch to OpenBTree), gaining some small efficiency. For now, this
179     method remains for clarity.
180
181     @see ConglomerateController#close
182     **/

183     public void close()
184         throws StandardException
185     {
186         super.close();
187
188         if (base_cc_for_locking != null)
189         {
190             base_cc_for_locking.close();
191             base_cc_for_locking = null;
192         }
193     }
194
195
196     /**
197     Insert a row into the conglomerate.
198     @see ConglomerateController#insert
199
200     @exception StandardException Standard exception policy.
201     **/

202     public int insert(DataValueDescriptor[] row)
203         throws StandardException
204     {
205         if (SanityManager.DEBUG)
206         {
207             if (this.container != null)
208             {
209                 SanityManager.ASSERT(this.getConglomerate() instanceof B2I);
210
211                 RowLocation rowloc = (RowLocation)
212                     row[((B2I)(this.getConglomerate())).rowLocationColumn];
213
214                 SanityManager.ASSERT(
215                     !rowloc.isNull(), "RowLocation value is null");
216             }
217         }
218
219         return(super.insert(row));
220     }
221 }
222
Popular Tags