KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > store > raw > data > DataFactory


1 /*
2
3    Derby - Class org.apache.derby.iapi.store.raw.data.DataFactory
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.iapi.store.raw.data;
23
24 import org.apache.derby.iapi.store.raw.ContainerKey;
25
26 import org.apache.derby.iapi.services.daemon.Serviceable;
27 import org.apache.derby.iapi.services.context.ContextManager;
28
29 import org.apache.derby.iapi.error.StandardException;
30 import org.apache.derby.iapi.store.raw.ContainerHandle;
31 import org.apache.derby.iapi.store.raw.Corruptable;
32 import org.apache.derby.iapi.store.raw.LockingPolicy;
33 import org.apache.derby.iapi.store.raw.RawStoreFactory;
34 import org.apache.derby.iapi.store.raw.RecordHandle;
35 import org.apache.derby.iapi.store.raw.StreamContainerHandle;
36 import org.apache.derby.iapi.store.raw.xact.RawTransaction;
37 import org.apache.derby.iapi.store.raw.Transaction;
38 import org.apache.derby.io.StorageFactory;
39 import org.apache.derby.iapi.store.access.FileResource;
40 import org.apache.derby.iapi.store.access.RowSource;
41 import org.apache.derby.iapi.store.raw.log.LogInstant;
42 import org.apache.derby.iapi.util.ByteArray;
43 import org.apache.derby.catalog.UUID;
44
45 import java.util.Properties JavaDoc;
46 import java.io.File JavaDoc;
47
48 public interface DataFactory extends Corruptable {
49
50     public static final String JavaDoc MODULE = "org.apache.derby.iapi.store.raw.data.DataFactory";
51
52     /**
53         The temporary segment is called "tmp"
54      */

55     public static final String JavaDoc TEMP_SEGMENT_NAME = "tmp";
56
57     /**
58         The database lock
59      */

60     public static final String JavaDoc DB_LOCKFILE_NAME = "db.lck";
61
62     /*
63     ** file name that is used to acquire exclusive lock on DB.
64     **/

65     public static final String JavaDoc DB_EX_LOCKFILE_NAME = "dbex.lck";
66
67     /**
68         Is the store read-only.
69     */

70     public boolean isReadOnly();
71
72
73     /**
74         Open a container that is not droped.
75
76         @param t the raw transaction that is opening the container
77         @param containerId the container's identity
78         @param locking the locking policy
79         @param mode see the different mode in @see ContainerHandle
80         then will return a null handle if the container is dropped.
81
82         @return the handle to the opened container
83         @exception StandardException Standard Cloudscape error policy
84
85      */

86     public ContainerHandle openContainer(RawTransaction t,
87                                          ContainerKey containerId,
88                                          LockingPolicy locking,
89                                          int mode)
90          throws StandardException;
91
92     /**
93         Open a container that may have been dropped.
94         Only internal raw store code should call this, e.g. recovery.
95
96         @see #openContainer
97         @exception StandardException Standard Cloudscape error policy
98     */

99     public RawContainerHandle openDroppedContainer(RawTransaction t,
100                                                    ContainerKey containerId,
101                                                    LockingPolicy locking,
102                                                    int mode)
103         throws StandardException;
104
105     /**
106         Add a container.
107
108         @param t the transaction that is creating the container
109         @param segmentId the segment where the container is to go
110         @param mode whether or not to LOGGED or not. The effect of this mode
111                 is only for this addContainer call, not persisently stored
112                 throughout the lifetime of the container
113         @param tableProperties properties of the container that is persistently
114                 stored throughout the lifetime of the container
115
116         @return the containerId of the newly created container
117
118         @exception StandardException Standard Cloudscape Error policy
119
120      */

121     public long addContainer(
122     RawTransaction t,
123     long segmentId,
124     long containerid,
125     int mode,
126     Properties JavaDoc tableProperties,
127     int temporaryFlag)
128         throws StandardException;
129
130     /**
131         Create and load a stream container.
132
133         @param t the transaction that is creating the container
134         @param segmentId the segment where the container is to go
135         @param tableProperties properties of the container that is persistently
136                 stored throughout the lifetime of the container
137         @param rowSource the data to load the container with
138
139         @return the containerId of the newly created stream container
140
141         @exception StandardException Standard Cloudscape Error policy
142
143      */

144     public long addAndLoadStreamContainer(RawTransaction t, long segmentId,
145             Properties JavaDoc tableProperties, RowSource rowSource)
146          throws StandardException;
147
148     /**
149         Open a stream container.
150
151         @return a valid StreamContainerHandle or null if the container does not exist.
152
153         @exception StandardException Standard cloudscape exception policy
154
155     */

156     public StreamContainerHandle openStreamContainer(
157     RawTransaction t,
158     long segmentId,
159     long containerId,
160     boolean hold)
161         throws StandardException;
162
163     /**
164         Drop and remove a stream container.
165
166         @exception StandardException Standard cloudscape exception policy
167     */

168     public void dropStreamContainer(RawTransaction t, long segmentId, long containerId)
169         throws StandardException;
170
171     /**
172         re-Create a container during redo recovery.
173
174         Used if container is found to not exist during redo recovery of
175         log records creating the container.
176
177         @exception StandardException Standard Cloudscape Error policy
178      */

179     public void reCreateContainerForRedoRecovery(RawTransaction t,
180             long segmentId, long containerId, ByteArray containerInfo)
181          throws StandardException;
182
183
184     public void dropContainer(RawTransaction t, ContainerKey containerId)
185         throws StandardException;
186
187     public void checkpoint() throws StandardException;
188
189     public void idle() throws StandardException;
190
191     /**
192         Return the identifier that uniquely identifies this raw store at runtime.
193         This identifier is to be used as part of the lokcing key for objects
194         locked in the raw store by value (e.g. Containers).
195     */

196     public UUID getIdentifier();
197
198     /**
199         make data factory aware of which raw store factory it belongs to
200         Also need to boot the LogFactory
201
202         @exception StandardException cannot boot the log factory
203     */

204     public void setRawStoreFactory(RawStoreFactory rsf, boolean create,
205                                    Properties JavaDoc properties)
206          throws StandardException ;
207
208     /**
209         Return a record handle that is initialized to the given page number and
210         record id.
211
212         @exception StandardException Standard cloudscape exception policy.
213
214         @param segmentId segment where the RecordHandle belongs.
215         @param containerId container where the RecordHandle belongs.
216         @param pageNumber the page number of the RecordHandle.
217         @param recordId the record id of the RecordHandle.
218
219         @see RecordHandle
220     */

221 // public RecordHandle makeRecordHandle(long segmentId, long containerId, long pageNumber, int recordId)
222
// throws StandardException;
223

224     /**
225         Database creation finished
226
227         @exception StandardException Standard cloudscape exception policy.
228     */

229     public void createFinished() throws StandardException;
230
231     /**
232         Get an object to handle non-transactional files.
233     */

234     public FileResource getFileHandler();
235
236     /**
237         Tell the data factory it is OK to remove committed deleted containers
238         when the data factory shuts down.
239      */

240     public void removeStubsOK();
241
242     /**
243         Get cache statistics for the specified cache
244     */

245     public long[] getCacheStats(String JavaDoc cacheName);
246
247     /**
248         Reset the cache statistics for the specified cache
249     */

250     public void resetCacheStats(String JavaDoc cacheName);
251
252     /**
253         Reclaim space used by this factory. Called by post commit daemon.
254         @exception StandardException Standard cloudscape exception policy
255     */

256     public int reclaimSpace(Serviceable work, ContextManager contextMgr)
257          throws StandardException;
258
259     /**
260         Called after recovery is performed.
261
262         @exception StandardException Standard Cloudscape Error Policy
263     */

264     public void postRecovery() throws StandardException;
265
266     /**
267         Encrypt cleartext into ciphertext.
268
269         @see org.apache.derby.iapi.services.crypto.CipherProvider#encrypt
270         @exception StandardException Standard Cloudscape Error Policy
271      */

272     public int encrypt(byte[] cleartext, int offset, int length,
273                        byte[] ciphertext, int outputOffset,
274                        boolean newEngine)
275          throws StandardException ;
276
277     /**
278         Decrypt cleartext from ciphertext.
279
280         @see org.apache.derby.iapi.services.crypto.CipherProvider#decrypt
281         @exception StandardException Standard Cloudscape Error Policy
282      */

283     public int decrypt(byte[] ciphertext, int offset, int length,
284                        byte[] cleartext, int outputOffset)
285          throws StandardException ;
286
287     /**
288      * Encrypt all the containers in the data segment.
289      * @param t the transaction that is encrypting the containers.
290      * @exception StandardException Standard Derby Error Policy
291      */

292     public void encryptAllContainers(RawTransaction t)
293         throws StandardException;
294
295     /*
296      * Remove old versions of the containers after (re)encryption
297      * of the database.
298      * @param inRecovery <code> true </code>, if cleanup is
299      * happening during recovery.
300      * @exception StandardException Standard Derby Error Policy
301      */

302     public void removeOldVersionOfContainers(boolean inRecovery)
303         throws StandardException;
304
305     /*
306      * Set that the database is encrypted.
307      */

308     public void setDatabaseEncrypted();
309
310     /**
311         Return the encryption block size used by the algorithm at time of
312         encrypted database creation
313      */

314     public int getEncryptionBlockSize();
315
316     /**
317      * Backup restore - stop writing dirty pages or container to disk
318      * @exception StandardException Standard Cloudscape error policy
319      */

320     public void freezePersistentStore() throws StandardException;
321
322     /**
323      * Backup restore - start writing dirty pages or container to disk
324      */

325     public void unfreezePersistentStore();
326
327     /**
328      * Backup restore - don't allow the persistent store to be frozen - or if
329      * it is already frozen, block. A write is about to commence.
330      * @exception StandardException Standard Cloudscape error policy
331      */

332     public void writeInProgress() throws StandardException;
333
334     /**
335      * Backup restore - write finished, if this is the last writer, allow the
336      * persistent store to proceed.
337      */

338     public void writeFinished();
339
340     /**
341      * Back up the data segment of the database.
342      */

343     public void backupDataFiles(Transaction rt, File JavaDoc backupDir) throws StandardException;
344
345     /**
346      * Return an id which can be used to create a container.
347      * <p>
348      * Return an id number with is greater than any existing container
349      * in the current database. Caller will use this to allocate future
350      * container numbers - most likely caching the value and then incrementing
351      * it as it is used.
352      * <p>
353      *
354      * @return The an id which can be used to create a container.
355      *
356      * @exception StandardException Standard exception policy.
357      **/

358     long getMaxContainerId()
359         throws StandardException;
360
361     /**
362      * This function is called after a checkpoint to remove the stub files thar are not required
363      * during recovery. Crash recovery uses these files to identify the dropped
364      * containers. Stub files(d*.dat) gets creates when a
365      * table/index(containers) dropped.
366      * @exception StandardException Standard Cloudscape error policy
367      **/

368     public void removeDroppedContainerFileStubs(LogInstant redoLWM) throws StandardException;
369
370     /**
371      * @return The StorageFactory used by this dataFactory
372      */

373     public StorageFactory getStorageFactory();
374
375     public void stop();
376 }
377
Popular Tags