001: /*
002:
003: Derby - Class org.apache.derby.impl.store.access.btree.index.B2IController
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.store.access.btree.index;
023:
024: import java.io.IOException;
025: import java.util.Properties;
026: import org.apache.derby.iapi.services.sanity.SanityManager;
027: import org.apache.derby.iapi.error.StandardException;
028: import org.apache.derby.iapi.store.access.conglomerate.Conglomerate;
029: import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;
030: import org.apache.derby.iapi.store.access.ConglomerateController;
031: import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;
032: import org.apache.derby.iapi.store.access.Qualifier;
033: import org.apache.derby.iapi.types.RowLocation;
034: import org.apache.derby.iapi.store.access.ScanController;
035: import org.apache.derby.iapi.store.access.TransactionController;
036: import org.apache.derby.iapi.store.access.ConglomerateController;
037: import org.apache.derby.iapi.store.raw.ContainerHandle;
038: import org.apache.derby.iapi.store.raw.LockingPolicy;
039: import org.apache.derby.iapi.store.raw.Transaction;
040:
041: import org.apache.derby.iapi.types.DataValueDescriptor;
042:
043: import org.apache.derby.impl.store.access.btree.BTreeController;
044: import org.apache.derby.impl.store.access.btree.BTreeLockingPolicy;
045:
046: import org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil;
047:
048: import org.apache.derby.iapi.services.io.FormatableBitSet;
049:
050: /**
051: * Controller used to insert rows into a secondary index.
052: *
053: * Implements the ConglomerateController interface for the B-Tree index
054: * access method.
055: *
056: * Note most work of this class is inherited from the generic btree
057: * implementation. This class initializes the top level object and deals with
058: * locking information specific to a secondary index implementation of a btree.
059: */
060: public class B2IController extends BTreeController {
061:
062: /*
063: ** Fields of B2IController.
064: */
065: private ConglomerateController base_cc_for_locking;
066:
067: /*
068: ** Methods of B2IController.
069: */
070:
071: B2IController() {
072: // Perform the generic b-tree construction.
073: super ();
074: }
075:
076: void init(TransactionManager xact_manager, Transaction rawtran,
077: boolean hold, int open_mode, int lock_level,
078: LockingPolicy locking_policy, boolean get_locks,
079: B2I conglomerate, B2IUndo undo,
080: B2IStaticCompiledInfo static_info,
081: DynamicCompiledOpenConglomInfo dynamic_info)
082: throws StandardException {
083: // open and lock the base table.
084:
085: int base_open_mode = open_mode
086: | TransactionController.OPENMODE_FOR_LOCK_ONLY;
087:
088: // open the base conglomerate - just to get the lock. Since btree
089: // controllers only support update operations we just hard code
090: // the TransactionController.ISOLATION_REPEATABLE_READ, which is only
091: // used for geting the IX intent lock on the table.
092: if (static_info != null) {
093: base_cc_for_locking = xact_manager
094: .openCompiledConglomerate(
095: false,
096: base_open_mode,
097: lock_level,
098: TransactionController.ISOLATION_REPEATABLE_READ,
099: static_info.base_table_static_info,
100: /* TODO - maintain a dynamic info for this */
101: ((Conglomerate) static_info.getConglom())
102: .getDynamicCompiledConglomInfo(conglomerate.baseConglomerateId));
103: } else {
104: base_cc_for_locking = xact_manager.openConglomerate(
105: conglomerate.baseConglomerateId, false,
106: base_open_mode, lock_level,
107: TransactionController.ISOLATION_REPEATABLE_READ);
108: }
109:
110: BTreeLockingPolicy b2i_locking_policy;
111: if (lock_level == TransactionController.MODE_TABLE) {
112: b2i_locking_policy = new B2ITableLocking3(rawtran,
113: lock_level, locking_policy, base_cc_for_locking,
114: this );
115: } else if (lock_level == TransactionController.MODE_RECORD) {
116: b2i_locking_policy = new B2IRowLocking3(rawtran,
117: lock_level, locking_policy, base_cc_for_locking,
118: this );
119: } else {
120: if (SanityManager.DEBUG) {
121: SanityManager.THROWASSERT("Bad lock level: "
122: + lock_level);
123: }
124: b2i_locking_policy = null;
125: }
126:
127: // Do generic b-tree initialization.
128: super .init(xact_manager, hold, (ContainerHandle) null, rawtran,
129: open_mode, lock_level, b2i_locking_policy,
130: conglomerate, undo, static_info, dynamic_info);
131:
132: if (SanityManager.DEBUG)
133: SanityManager.ASSERT(conglomerate != null);
134: }
135:
136: /*
137: ** Methods of ConglomerateController.
138: */
139:
140: /**
141: Close the conglomerate controller.
142: <p>
143: Any changes to this method will probably have to be reflected in close as
144: well.
145: <p>
146: Currently delegates to OpenBTree. If the btree controller ends up not
147: having any state of its own, we can remove this method (the VM will
148: dispatch to OpenBTree), gaining some small efficiency. For now, this
149: method remains for clarity.
150:
151: @see ConglomerateController#close
152: **/
153: public void close() throws StandardException {
154: super .close();
155:
156: if (base_cc_for_locking != null) {
157: base_cc_for_locking.close();
158: base_cc_for_locking = null;
159: }
160: }
161:
162: /**
163: Insert a row into the conglomerate.
164: @see ConglomerateController#insert
165:
166: @exception StandardException Standard exception policy.
167: **/
168: public int insert(DataValueDescriptor[] row)
169: throws StandardException {
170: if (SanityManager.DEBUG) {
171: if (this .container != null) {
172: SanityManager
173: .ASSERT(this .getConglomerate() instanceof B2I);
174:
175: RowLocation rowloc = (RowLocation) row[((B2I) (this
176: .getConglomerate())).rowLocationColumn];
177:
178: SanityManager.ASSERT(!rowloc.isNull(),
179: "RowLocation value is null");
180: }
181: }
182:
183: return (super.insert(row));
184: }
185: }
|