001: /*
002:
003: Derby - Class org.apache.derby.impl.store.access.conglomerate.GenericController
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.conglomerate;
023:
024: import org.apache.derby.iapi.reference.SQLState;
025:
026: import org.apache.derby.iapi.services.sanity.SanityManager;
027:
028: import org.apache.derby.iapi.error.StandardException;
029:
030: import org.apache.derby.iapi.store.access.conglomerate.Conglomerate;
031: import org.apache.derby.iapi.store.access.conglomerate.LogicalUndo;
032: import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;
033:
034: import org.apache.derby.iapi.store.access.ConglomerateController;
035: import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;
036: import org.apache.derby.iapi.store.access.RowUtil;
037: import org.apache.derby.iapi.store.access.SpaceInfo;
038:
039: import org.apache.derby.iapi.store.raw.ContainerHandle;
040: import org.apache.derby.iapi.store.raw.Page;
041: import org.apache.derby.iapi.store.raw.RecordHandle;
042: import org.apache.derby.iapi.store.raw.Transaction;
043:
044: import org.apache.derby.iapi.types.RowLocation;
045:
046: import org.apache.derby.iapi.services.io.FormatableBitSet;
047:
048: import java.util.Properties;
049:
050: /**
051: **/
052:
053: abstract class GenericController {
054: /**************************************************************************
055: * Fields of the class
056: **************************************************************************
057: */
058: protected OpenConglomerate open_conglom;
059:
060: /**************************************************************************
061: * Constructors for This class:
062: **************************************************************************
063: */
064:
065: /**************************************************************************
066: * Private/Protected methods of This class:
067: **************************************************************************
068: */
069: protected void getRowPositionFromRowLocation(RowLocation row_loc,
070: RowPosition pos) throws StandardException {
071: // Not implemented in default conglomerate, needs to be overridden.
072: throw StandardException
073: .newException(SQLState.HEAP_UNIMPLEMENTED_FEATURE);
074:
075: }
076:
077: protected void queueDeletePostCommitWork(RowPosition pos)
078: throws StandardException {
079: // Not implemented in default conglomerate, needs to be overridden.
080: throw StandardException
081: .newException(SQLState.HEAP_UNIMPLEMENTED_FEATURE);
082: }
083:
084: /**************************************************************************
085: * Public Methods of This class:
086: **************************************************************************
087: */
088: public void init(OpenConglomerate open_conglom)
089: throws StandardException {
090: if (SanityManager.DEBUG)
091: SanityManager.ASSERT(open_conglom != null);
092:
093: this .open_conglom = open_conglom;
094: }
095:
096: public OpenConglomerate getOpenConglom() {
097: return (open_conglom);
098: }
099:
100: /**************************************************************************
101: * Public Methods implementing ConglomerateController which just
102: * delegate to OpenConglomerate:
103: **************************************************************************
104: */
105:
106: public void checkConsistency() throws StandardException {
107: open_conglom.checkConsistency();
108: }
109:
110: public void debugConglomerate() throws StandardException {
111: open_conglom.debugConglomerate();
112: }
113:
114: public void getTableProperties(Properties prop)
115: throws StandardException {
116: open_conglom.getTableProperties(prop);
117: }
118:
119: public Properties getInternalTablePropertySet(Properties prop)
120: throws StandardException {
121: return (open_conglom.getInternalTablePropertySet(prop));
122: }
123:
124: public SpaceInfo getSpaceInfo() throws StandardException {
125: return (open_conglom.getSpaceInfo());
126: }
127:
128: public void close() throws StandardException {
129: if (open_conglom != null)
130: open_conglom.close();
131: }
132:
133: public boolean isKeyed() {
134: return (open_conglom.isKeyed());
135: }
136:
137: public RowLocation newRowLocationTemplate()
138: throws StandardException {
139: if (open_conglom.isClosed())
140: open_conglom.reopen();
141:
142: return (open_conglom.newRowLocationTemplate());
143: }
144:
145: /**
146: * is the open btree table locked?
147: **/
148: public boolean isTableLocked() {
149: return (open_conglom.isTableLocked());
150: }
151:
152: /**
153: * Get the total estimated number of rows in the container.
154: * <p>
155: * The number is a rough estimate and may be grossly off. In general
156: * the server will cache the row count and then occasionally write
157: * the count unlogged to a backing store. If the system happens to
158: * shutdown before the store gets a chance to update the row count it
159: * may wander from reality.
160: * <p>
161: * This call is currently only supported on Heap conglomerates, it
162: * will throw an exception if called on btree conglomerates.
163: *
164: * @return The total estimated number of rows in the conglomerate.
165: *
166: * @exception StandardException Standard exception policy.
167: **/
168: public long getEstimatedRowCount() throws StandardException {
169: if (open_conglom.isClosed())
170: open_conglom.reopen();
171:
172: // Don't return 0 rows (return 1 instead), as this often leads the
173: // optimizer to produce plans which don't use indexes because of the 0
174: // row edge case.
175: //
176: // Eventually the plan is recompiled when rows are added, but we
177: // have seen multiple customer cases of deadlocks and timeouts
178: // because of these 0 row based plans.
179: long row_count = open_conglom.getContainer()
180: .getEstimatedRowCount(0);
181:
182: return ((row_count == 0) ? 1 : row_count);
183: }
184:
185: /**
186: * Set the total estimated number of rows in the container.
187: * <p>
188: * Often, after a scan, the client of RawStore has a much better estimate
189: * of the number of rows in the container than what store has. For
190: * instance if we implement some sort of update statistics command, or
191: * just after a create index a complete scan will have been done of the
192: * table. In this case this interface allows the client to set the
193: * estimated row count for the container, and store will use that number
194: * for all future references.
195: * <p>
196: * This call is currently only supported on Heap conglomerates, it
197: * will throw an exception if called on btree conglomerates.
198: *
199: * @param count the estimated number of rows in the container.
200: *
201: * @exception StandardException Standard exception policy.
202: **/
203: public void setEstimatedRowCount(long count)
204: throws StandardException {
205: ContainerHandle container = open_conglom.getContainer();
206:
207: if (container == null)
208: open_conglom.reopen();
209:
210: open_conglom.getContainer().setEstimatedRowCount(count, /* unused flag */
211: 0);
212: }
213:
214: /**************************************************************************
215: * Public Methods implementing ConglomerateController:
216: **************************************************************************
217: */
218:
219: }
|