KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > conglomerate > GenericController


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.conglomerate.GenericController
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.conglomerate;
23
24 import org.apache.derby.iapi.reference.SQLState;
25
26 import org.apache.derby.iapi.services.sanity.SanityManager;
27
28 import org.apache.derby.iapi.error.StandardException;
29
30 import org.apache.derby.iapi.store.access.conglomerate.Conglomerate;
31 import org.apache.derby.iapi.store.access.conglomerate.LogicalUndo;
32 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;
33
34 import org.apache.derby.iapi.store.access.ConglomerateController;
35 import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;
36 import org.apache.derby.iapi.store.access.RowUtil;
37 import org.apache.derby.iapi.store.access.SpaceInfo;
38
39 import org.apache.derby.iapi.store.raw.ContainerHandle;
40 import org.apache.derby.iapi.store.raw.Page;
41 import org.apache.derby.iapi.store.raw.RecordHandle;
42 import org.apache.derby.iapi.store.raw.Transaction;
43
44
45 import org.apache.derby.iapi.types.RowLocation;
46
47 import org.apache.derby.iapi.services.io.FormatableBitSet;
48
49 import java.util.Properties JavaDoc;
50
51
52 /**
53 **/

54
55 abstract class GenericController
56 {
57     /**************************************************************************
58      * Fields of the class
59      **************************************************************************
60      */

61     protected OpenConglomerate open_conglom;
62
63     /**************************************************************************
64      * Constructors for This class:
65      **************************************************************************
66      */

67
68     /**************************************************************************
69      * Private/Protected methods of This class:
70      **************************************************************************
71      */

72     protected void getRowPositionFromRowLocation(
73     RowLocation row_loc,
74     RowPosition pos)
75         throws StandardException
76     {
77         // Not implemented in default conglomerate, needs to be overridden.
78
throw StandardException.newException(
79                 SQLState.HEAP_UNIMPLEMENTED_FEATURE);
80        
81     }
82
83     protected void queueDeletePostCommitWork(
84     RowPosition pos)
85         throws StandardException
86     {
87         // Not implemented in default conglomerate, needs to be overridden.
88
throw StandardException.newException(
89                 SQLState.HEAP_UNIMPLEMENTED_FEATURE);
90     }
91
92
93     /**************************************************************************
94      * Public Methods of This class:
95      **************************************************************************
96      */

97     public void init(
98     OpenConglomerate open_conglom)
99         throws StandardException
100     {
101         if (SanityManager.DEBUG)
102             SanityManager.ASSERT(open_conglom != null);
103
104         this.open_conglom = open_conglom;
105     }
106
107     public OpenConglomerate getOpenConglom()
108     {
109         return(open_conglom);
110     }
111
112
113     /**************************************************************************
114      * Public Methods implementing ConglomerateController which just
115      * delegate to OpenConglomerate:
116      **************************************************************************
117      */

118
119     public void checkConsistency()
120         throws StandardException
121     {
122         open_conglom.checkConsistency();
123     }
124
125     public void debugConglomerate()
126         throws StandardException
127     {
128         open_conglom.debugConglomerate();
129     }
130
131     public void getTableProperties(Properties JavaDoc prop)
132         throws StandardException
133     {
134         open_conglom.getTableProperties(prop);
135     }
136
137     public Properties JavaDoc getInternalTablePropertySet(Properties JavaDoc prop)
138         throws StandardException
139     {
140         return(open_conglom.getInternalTablePropertySet(prop));
141     }
142
143     public SpaceInfo getSpaceInfo()
144         throws StandardException
145     {
146         return(open_conglom.getSpaceInfo());
147     }
148
149     public void close()
150         throws StandardException
151     {
152         if (open_conglom != null)
153             open_conglom.close();
154     }
155
156     public boolean isKeyed()
157     {
158         return(open_conglom.isKeyed());
159     }
160
161     public RowLocation newRowLocationTemplate()
162         throws StandardException
163     {
164         if (open_conglom.isClosed())
165             open_conglom.reopen();
166
167         return(open_conglom.newRowLocationTemplate());
168     }
169
170     /**
171      * is the open btree table locked?
172      **/

173     public boolean isTableLocked()
174     {
175         return(open_conglom.isTableLocked());
176     }
177
178     /**
179      * Get the total estimated number of rows in the container.
180      * <p>
181      * The number is a rough estimate and may be grossly off. In general
182      * the server will cache the row count and then occasionally write
183      * the count unlogged to a backing store. If the system happens to
184      * shutdown before the store gets a chance to update the row count it
185      * may wander from reality.
186      * <p>
187      * This call is currently only supported on Heap conglomerates, it
188      * will throw an exception if called on btree conglomerates.
189      *
190      * @return The total estimated number of rows in the conglomerate.
191      *
192      * @exception StandardException Standard exception policy.
193      **/

194     public long getEstimatedRowCount()
195         throws StandardException
196     {
197         if (open_conglom.isClosed())
198             open_conglom.reopen();
199
200         // Don't return 0 rows (return 1 instead), as this often leads the
201
// optimizer to produce plans which don't use indexes because of the 0
202
// row edge case.
203
//
204
// Eventually the plan is recompiled when rows are added, but we
205
// have seen multiple customer cases of deadlocks and timeouts
206
// because of these 0 row based plans.
207
long row_count = open_conglom.getContainer().getEstimatedRowCount(0);
208
209         return( (row_count == 0) ? 1 : row_count);
210     }
211
212     /**
213      * Set the total estimated number of rows in the container.
214      * <p>
215      * Often, after a scan, the client of RawStore has a much better estimate
216      * of the number of rows in the container than what store has. For
217      * instance if we implement some sort of update statistics command, or
218      * just after a create index a complete scan will have been done of the
219      * table. In this case this interface allows the client to set the
220      * estimated row count for the container, and store will use that number
221      * for all future references.
222      * <p>
223      * This call is currently only supported on Heap conglomerates, it
224      * will throw an exception if called on btree conglomerates.
225      *
226      * @param count the estimated number of rows in the container.
227      *
228      * @exception StandardException Standard exception policy.
229      **/

230     public void setEstimatedRowCount(long count)
231         throws StandardException
232     {
233         ContainerHandle container = open_conglom.getContainer();
234
235         if (container == null)
236             open_conglom.reopen();
237
238         open_conglom.getContainer().setEstimatedRowCount(
239                 count, /* unused flag */ 0);
240     }
241
242     /**************************************************************************
243      * Public Methods implementing ConglomerateController:
244      **************************************************************************
245      */

246
247 }
248
Popular Tags