KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > raw > data > BaseContainerHandle


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.data.BaseContainerHandle
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.raw.data;
23
24 import org.apache.derby.iapi.reference.SQLState;
25
26 import org.apache.derby.iapi.services.locks.Lockable;
27 import org.apache.derby.iapi.services.locks.VirtualLockTable;
28 import org.apache.derby.iapi.services.sanity.SanityManager;
29 import org.apache.derby.iapi.error.StandardException;
30 import org.apache.derby.iapi.store.access.SpaceInfo;
31 import org.apache.derby.iapi.store.raw.ContainerHandle;
32 import org.apache.derby.iapi.store.raw.ContainerLock;
33 import org.apache.derby.iapi.store.raw.LockingPolicy;
34 import org.apache.derby.iapi.store.raw.Page;
35 import org.apache.derby.iapi.store.raw.PageKey;
36 import org.apache.derby.iapi.store.raw.PageTimeStamp;
37 import org.apache.derby.iapi.store.raw.RecordHandle;
38 import org.apache.derby.iapi.store.raw.ContainerKey;
39
40 import org.apache.derby.iapi.store.raw.data.RawContainerHandle;
41 import org.apache.derby.iapi.store.raw.xact.RawTransaction;
42 import org.apache.derby.iapi.store.raw.log.LogInstant;
43
44 import org.apache.derby.iapi.util.ByteArray;
45 import org.apache.derby.catalog.UUID;
46
47 import java.util.Hashtable JavaDoc;
48 import java.util.Observable JavaDoc;
49 import java.util.Observer JavaDoc;
50 import java.util.Properties JavaDoc;
51
52 /**
53     A handle to an open container, implememts RawContainerHandle.
54     <P>
55     This class is an Observer to observe RawTransactions
56     and is also a Observable to
57     handle the list of pages accessed thorough this handle.
58     <BR>
59     This class implements Lockable (defined to be ContainerHandle) and is
60     the object used to logically lock the container.
61
62     <BR> MT - Mutable - Immutable identity - Thread Aware
63 */

64
65 public class BaseContainerHandle extends Observable JavaDoc
66     implements RawContainerHandle, Observer JavaDoc
67 {
68
69     /*
70     ** Fields
71     */

72
73     /**
74         Container identifier
75         <BR> MT - Immutable
76     */

77     protected /*final*/ ContainerKey identity;
78
79     /**
80         Is this ContainerHandle active.
81
82         <BR> MT - Mutable : scoped
83     */

84     protected boolean active;
85
86     /**
87         The actual container we are accessing. Only valid when active is true.
88
89         <BR> MT - Mutable : scoped
90     */

91     protected BaseContainer container;
92
93     /**
94         the locking policy we opened the container with.
95         Only valid when active is true.
96
97         <BR> MT - Mutable : scoped
98     */

99
100     private LockingPolicy locking;
101
102     /**
103         our transaction. Only valid when active is true.
104
105         <BR> MT - Mutable : scoped
106     */

107     protected RawTransaction xact;
108
109     /**
110         are we going to update?
111
112         <BR> MT - Immutable after container handle becomes active
113     */

114     private boolean forUpdate;
115
116     protected int mode; // mode the container was opened in
117

118
119     protected PageActions actionsSet;
120     protected AllocationActions allocActionsSet;
121
122
123     /*
124     ** Constructor
125     */

126
127     /**
128         Create an object that is only used for locking the container.
129     */

130     public BaseContainerHandle(UUID rawStoreId, RawTransaction xact,
131         ContainerKey identity, LockingPolicy locking, int mode)
132     {
133         this.identity = identity;
134         this.xact = xact;
135         this.locking = locking;
136         this.mode = mode;
137         this.forUpdate = (mode & MODE_FORUPDATE) == MODE_FORUPDATE;
138     }
139
140     /**
141         Create a container handle that is used to actually access the container.
142     */

143     public BaseContainerHandle(
144     UUID rawStoreId,
145     RawTransaction xact,
146     PageActions actionsSet,
147     AllocationActions allocActionsSet,
148     LockingPolicy locking,
149     BaseContainer container,
150     int mode)
151     {
152         this(rawStoreId, xact,
153                 (ContainerKey) container.getIdentity(), locking, mode);
154
155
156         this.actionsSet = actionsSet;
157         this.allocActionsSet = allocActionsSet;
158         this.container = container;
159
160         // we are inactive until useContainer is called.
161
}
162
163     /*
164     ** Methods from ContainerHandle
165     */

166
167     /**
168         Add a page to the container
169         The page returned will be observing me.
170
171         @see BaseContainer#addPage
172         @see ContainerHandle#addPage
173         @exception StandardException Standard Cloudscape error policy
174     */

175     public Page addPage() throws StandardException
176     {
177         checkUpdateOpen();
178
179         Page page = container.addPage(this, false /* not an overflow page */);
180             
181         return page;
182     }
183
184     /**
185         Release free space to the OS.
186         <P>
187         As is possible release any free space to the operating system. This
188         will usually mean releasing any free pages located at the end of the
189         file using the java truncate() interface.
190
191         @exception StandardException Standard Cloudscape error policy
192     */

193     public void compressContainer() throws StandardException
194     {
195         checkUpdateOpen();
196
197         container.compressContainer(this);
198     }
199
200     /**
201      * Get the reusable recordId sequence number.
202      * @return version sequence number
203      * @exception StandardException Standard Derby error policy
204      * @see ContainerHandle#getReusableRecordIdSequenceNumber
205      */

206     public long getReusableRecordIdSequenceNumber() throws StandardException
207     {
208         checkOpen();
209         
210         return container.getReusableRecordIdSequenceNumber();
211     }
212
213     /**
214         Add a page to the container, if flag == ContainerHandle.ADD_PAGE_BULK,
215         tell the container about it.
216
217         The page returned will be observing me.
218
219         @see BaseContainer#addPage
220         @see ContainerHandle#addPage
221         @exception StandardException Standard Cloudscape error policy
222     */

223     public Page addPage(int flag) throws StandardException {
224
225         if ((flag & ContainerHandle.ADD_PAGE_BULK) != 0 && active && forUpdate)
226         {
227             // start preallocating immediatelly, don't wait for the
228
// preallocation threshold to be crossed. Don't go wild and
229
// preallocate a bunch of pages either, use preAllocate for that.
230
container.clearPreallocThreshold();
231         }
232
233         return addPage();
234     }
235
236     /**
237         Preallocate numPage if possible.
238     */

239     public void preAllocate(int numPage)
240     {
241         if (numPage > 0 && active && forUpdate)
242             container.prepareForBulkLoad(this, numPage);
243     }
244
245     /**
246      * Request the system properties associated with a container.
247      * <p>
248      * Request the value of properties that are associated with a container.
249      * The following properties can be requested:
250      * derby.storage.pageSize
251      * derby.storage.pageReservedSpace
252      * derby.storage.minimumRecordSize
253      * <p>
254      * To get the value of a particular property add it to the property list,
255      * and on return the value of the property will be set to it's current
256      * value. For example:
257      *
258      * get_prop(BaseContainerHandle ch)
259      * {
260      * Properties prop = new Properties();
261      * prop.put("derby.storage.pageSize", "");
262      * ch.getContainerProperties(prop);
263      *
264      * System.out.println(
265      * "conatainer's page size = " +
266      * prop.getProperty("derby.storage.pageSize");
267      * }
268      *
269      * @param prop Property list to fill in.
270      *
271      * @exception StandardException Standard exception policy.
272      **/

273     public void getContainerProperties(Properties JavaDoc prop)
274         throws StandardException
275     {
276         checkOpen();
277
278         container.getContainerProperties(prop);
279
280         return;
281     }
282
283     /**
284         Remove a page from the container.
285
286         @see ContainerHandle#removePage
287         @exception StandardException Standard Cloudscape error policy
288     */

289     public void removePage(Page page) throws StandardException
290     {
291         if (!active)
292         {
293             if (page != null)
294                 page.unlatch();
295             throw StandardException.newException(
296                     SQLState.DATA_CONTAINER_CLOSED);
297         }
298
299         if (!forUpdate)
300         {
301             if (page != null)
302                 page.unlatch();
303             throw StandardException.newException(
304                     SQLState.DATA_CONTAINER_READ_ONLY);
305         }
306
307         container.removePage(this, (BasePage)page);
308     }
309
310     public Page getPage(long pageNumber) throws StandardException
311     {
312
313         checkOpen();
314
315         return container.getPage(this, pageNumber, true);
316     }
317
318
319     public Page getAllocPage(long pageNumber) throws StandardException
320     {
321         checkOpen();
322
323         return container.getAllocPage(this, pageNumber, true);
324     }
325
326     public Page getUserPageNoWait(long pageNumber)
327         throws StandardException
328     {
329         checkOpen();
330
331         return container.getHeadPage(this, pageNumber, false);
332     }
333     public Page getUserPageWait(long pageNumber)
334         throws StandardException
335     {
336         checkOpen();
337
338         return container.getHeadPage(this, pageNumber, true);
339     }
340
341     public Page getPageNoWait(long pageNumber)
342         throws StandardException
343     {
344         checkOpen();
345
346         return container.getPage(this, pageNumber, false);
347     }
348
349     public Page getFirstPage() throws StandardException
350     {
351         checkOpen();
352
353         return container.getFirstPage(this);
354     }
355
356     public Page getNextPage(long pageNumber) throws StandardException
357     {
358         checkOpen();
359
360         return container.getNextPage(this, pageNumber);
361     }
362
363     public Page getPageForInsert(int flag)
364          throws StandardException
365     {
366         checkUpdateOpen();
367
368         return container.getPageForInsert(this, flag);
369     }
370
371     public Page getPageForCompress(int flag, long pageno)
372          throws StandardException
373     {
374         checkUpdateOpen();
375
376         return container.getPageForCompress(this, flag, pageno);
377     }
378
379     /**
380         @see ContainerHandle#isReadOnly()
381     */

382     public final boolean isReadOnly()
383     {
384         return(!forUpdate);
385     }
386
387     /**
388         @see ContainerHandle#close
389     */

390
391     public void close()
392     {
393
394         if (xact == null)
395         {
396             // Probably be closed explicitly by a client, after closing
397
// automatically after an abort.
398

399             if (SanityManager.DEBUG)
400                 SanityManager.ASSERT(!active);
401
402             return;
403         }
404
405         // notify our observers (Pages) that we are closing ...
406
informObservers();
407
408         active = false;
409
410         getLockingPolicy().unlockContainer(xact, this);
411
412         // let go of the container
413
if (container != null)
414         {
415             container.letGo(this);
416             container = null;
417         }
418
419         // and remove ourseleves from this transaction
420
xact.deleteObserver(this);
421
422         xact = null;
423         
424     }
425
426     /* cost estimation */
427
428     /**
429         @see ContainerHandle#getEstimatedRowCount
430         @exception StandardException Standard Cloudscape error policy
431      */

432     public long getEstimatedRowCount(int flag) throws StandardException
433     {
434         checkOpen();
435
436         return container.getEstimatedRowCount(flag);
437     }
438
439     /**
440         @see ContainerHandle#setEstimatedRowCount
441         @exception StandardException Standard Cloudscape error policy
442      */

443     public void setEstimatedRowCount(long count, int flag)
444         throws StandardException
445     {
446         checkOpen();
447
448         container.setEstimatedRowCount(count, flag);
449     }
450
451     /**
452         @see ContainerHandle#getEstimatedPageCount
453         @exception StandardException Standard Cloudscape error policy
454      */

455     public long getEstimatedPageCount(int flag)
456         throws StandardException
457     {
458         checkOpen();
459
460         return container.getEstimatedPageCount(this, flag);
461     }
462
463     /**
464         @see ContainerHandle#flushContainer
465         @exception StandardException Standard Cloudscape error policy
466      */

467     public void flushContainer()
468         throws StandardException
469     {
470         checkUpdateOpen();
471
472         // raw store may override unlog mode when log is Archived.
473
// if ((mode & MODE_CREATE_UNLOGGED) == 0)
474
// throw StandardException.newException(
475
// SQLState.DATA_NOT_CREATE_UNLOGGED, identity);
476

477         container.flushAll();
478
479     }
480
481     /**
482         @see ContainerHandle#compactRecord
483         @exception StandardException Standard Cloudscape error policy
484      */

485     public void compactRecord(RecordHandle record)
486         throws StandardException
487     {
488         if (!forUpdate)
489         {
490             throw StandardException.newException(
491                     SQLState.DATA_CONTAINER_READ_ONLY);
492         }
493
494         PageKey pkey = (PageKey)record.getPageId();
495         BasePage headPage = (BasePage)getPage(pkey.getPageNumber());
496
497         if (headPage != null)
498         {
499             // The page could have been null if it was deallocated after the
500
// row lock is gotten. We are doing all of these post commit so
501
// the record may not even be there and we got a lock for nothing.
502
try
503             {
504                 headPage.compactRecord(record);
505             }
506             finally
507             {
508                 headPage.unlatch();
509             }
510         }
511     }
512
513
514     /*
515     ** Methods of RawContainerHandle - methods are called underneath the log
516     */

517
518     /**
519         Get the container status.
520
521         @exception StandardException Standard Cloudscape error policy
522         @see RawContainerHandle#getContainerStatus
523     */

524     public int getContainerStatus() throws StandardException
525     {
526         checkOpen();
527
528         return container.getContainerStatus();
529     }
530
531     /**
532         remove the container
533
534         @exception StandardException Standard Cloudscape error policy
535         @see RawContainerHandle#removeContainer
536     */

537     public void removeContainer(LogInstant instant) throws StandardException
538     {
539         checkUpdateOpen();
540
541         // This call can only be issued by within rawStore.
542
// while the container is dropped, no client of raw store
543
// should be able to access the container (it is
544
// exclusively locked).
545
// Then as postcommit processing,
546
// the container iw
547

548         container.removeContainer(instant, true);
549     }
550
551     /**
552         @see ContainerHandle#getId
553      */

554     public ContainerKey getId()
555     {
556         return identity;
557     }
558
559     /**
560         @see ContainerHandle#getUniqueId
561      */

562     public Object JavaDoc getUniqueId()
563     {
564         return(this);
565     }
566
567
568     /**
569         @exception StandardException Standard cloudscape exception policy
570         @see RawContainerHandle#dropContainer
571     */

572     public void dropContainer(LogInstant instant, boolean drop)
573         throws StandardException
574     {
575         checkUpdateOpen();
576
577         container.dropContainer(instant, drop);
578     }
579
580     /**
581         @exception StandardException Standard cloudscape exception policy
582         @see RawContainerHandle#getContainerVersion
583     */

584     public long getContainerVersion()
585         throws StandardException
586     {
587         checkOpen();
588
589         return container.getContainerVersion();
590     }
591
592
593     /**
594         Get this page with no check - any page type or status is fine.
595         Caller must be prepared to handle freed, deallocated,or alloc page
596         Called by recovery ONLY.
597
598         @exception StandardException Cloudscape Standard error policy
599     */

600     public Page getAnyPage(long pageNumber) throws StandardException
601     {
602         checkOpen();
603
604         return container.getAnyPage(this, pageNumber, true /* wait */);
605     }
606
607     /**
608      * ReCreate a page for rollforward recovery.
609      * <p>
610      * During redo recovery it is possible for the system to try to redo
611      * the creation of a page (ie. going from non-existence to version 0).
612      * It first trys to read the page from disk, but a few different types
613      * of errors can occur:
614      * o the page does not exist at all on disk, this can happen during
615      * rollforward recovery applied to a backup where the file was
616      * copied and the page was added to the file during the time frame
617      * of the backup but after the physical file was copied.
618      * o space in the file exists, but it was never initalized. This
619      * can happen if you happen to crash at just the right moment during
620      * the allocation process. Also
621      * on some OS's it is possible to read from a part of the file that
622      * was not ever written - resulting in garbage from the store's
623      * point of view (often the result is all 0's).
624      *
625      * All these errors are easy to recover from as the system can easily
626      * create a version 0 from scratch and write it to disk.
627      *
628      * Because the system does not sync allocation of data pages, it is also
629      * possible at this point that whlie writing the version 0 to disk to
630      * create it we may encounter an out of disk space error (caught in this
631      * routine as a StandardException from the create() call. We can't
632      * recovery from this without help from outside, so the caught exception
633      * is nested and a new exception thrown which the recovery system will
634      * output to the user asking them to check their disk for space/errors.
635      *
636      * @exception StandardException Standard exception policy.
637      **/

638     public Page reCreatePageForRedoRecovery(
639     int pageFormat,
640     long pageNumber,
641     long pageOffset)
642          throws StandardException
643     {
644         checkUpdateOpen();
645
646         return container.reCreatePageForRedoRecovery(
647                     this, pageFormat, pageNumber, pageOffset);
648     }
649
650     /**
651         Log all information necessary to recreate the container during a load
652         tran.
653
654         @exception StandardException Standard Cloudscape error policy
655      */

656     public ByteArray logCreateContainerInfo()
657         throws StandardException
658     {
659         checkUpdateOpen();
660
661         return container.logCreateContainerInfo();
662     }
663     
664     /**
665         Return a record handle that is initialized to the given page number and
666         record id.
667
668         @exception StandardException Standard cloudscape exception policy.
669
670         @param pageNumber the page number of the RecordHandle.
671         @param recordId the record id of the RecordHandle.
672
673         @see RecordHandle
674     */

675     public RecordHandle makeRecordHandle(long pageNumber, int recordId)
676          throws StandardException
677     {
678         return new RecordId(identity, pageNumber, recordId);
679     }
680
681
682     /*
683     ** Methods of Observer
684     */

685
686     /**
687         Called when the transaction is about to complete.
688
689         @see Observer#update
690     */

691     public void update(Observable JavaDoc obj, Object JavaDoc arg)
692     {
693         if (SanityManager.DEBUG)
694         {
695             if (arg == null)
696                 SanityManager.THROWASSERT("still on observr list " + this);
697         }
698
699         // already been removed from the list
700
if (xact == null)
701         {
702             return;
703         }
704
705         if (SanityManager.DEBUG)
706         {
707             // just check reference equality
708

709             if (obj != xact)
710             {
711                 SanityManager.THROWASSERT(
712                     "Observable passed to update is incorrect expected " +
713                     xact + " got " + obj);
714             }
715         }
716
717         // close on a commit, abort or drop of this container.
718
if (arg.equals(RawTransaction.COMMIT) ||
719             arg.equals(RawTransaction.ABORT) ||
720             arg.equals(identity))
721         {
722             // close the container
723
close();
724             return;
725
726         }
727         
728         if (arg.equals(RawTransaction.SAVEPOINT_ROLLBACK))
729         {
730
731             // unlatch any pages but remain open
732
informObservers();
733
734             // remain open
735
return;
736         }
737
738         // Transaction is notifying us that our container
739
// has undergone some lock escalation. We re-get
740
// our table lock which will promote us
741
// if possible
742

743         if (arg.equals(RawTransaction.LOCK_ESCALATE))
744         {
745
746             // only attempt escalation on RowLocking modes.
747
if (getLockingPolicy().getMode() != LockingPolicy.MODE_RECORD)
748                 return;
749
750             try
751             {
752                 getLockingPolicy().lockContainer(
753                     getTransaction(), this, false, forUpdate);
754             }
755             catch (StandardException se)
756             {
757                 xact.setObserverException(se);
758             }
759         }
760     }
761
762     /*
763     ** Implementation specific methods, these are public so that they can be
764     ** called in other packages that are specific implementations of Data, ie.
765     ** a directory at the level
766     **
767     ** com.ibm.db2j.impl.Database.Storage.RawStore.Data.*
768     */

769
770     public PageActions getActionSet()
771     {
772         return actionsSet;
773     }
774     
775     public AllocationActions getAllocationActionSet()
776     {
777         return allocActionsSet;
778     }
779
780     /**
781         Attach me to a container. If this method returns false then
782         I cannot be used anymore, and any reference to me must be discarded.
783
784         @param droppedOK if true, use this container even if it is dropped,
785         otherwise, return false if container is dropped.
786
787         @param waitForLock if true, wait on lock, otherwise, get lock no wait.
788
789         @exception StandardException Standard Cloudscape error policy
790     */

791     public boolean useContainer(
792     boolean droppedOK,
793     boolean waitForLock)
794         throws StandardException
795     {
796
797         if (SanityManager.DEBUG)
798         {
799             SanityManager.ASSERT(!active);
800         }
801
802         boolean gotLock =
803             getLockingPolicy().lockContainer(
804                 getTransaction(), this, waitForLock, forUpdate);
805
806         if (gotLock == false)
807         {
808             // this is a lockingPolicy error, if waitForLock should either
809
// return true or throw a deadlock exception
810
if (SanityManager.DEBUG)
811                 SanityManager.ASSERT(waitForLock == false,
812                     "lockContainer wait returns false");
813
814             container = null;
815
816             throw StandardException.newException(SQLState.LOCK_TIMEOUT);
817         }
818
819         if ((mode & ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY) == 0)
820         {
821
822             if (SanityManager.DEBUG)
823             {
824                 SanityManager.ASSERT(container != null);
825             }
826
827             if (!container.use(this, forUpdate, droppedOK))
828             {
829
830                 // If we got a lock, but for some reason we can't open the
831
// table (like it doesn't exist), then call unlockContainer().
832
// In the normal case it would be called when the container
833
// handle was closed, but in this case the user is never going
834
// to get an "open" container handle back. We can't call
835
// close() here as we haven't done all the "open" stuff.
836
getLockingPolicy().unlockContainer(xact, this);
837
838                 container = null;
839
840                 return false;
841             }
842             active = true;
843         }
844         else
845         {
846             // lock only, we only observe the transaction if
847
// we are performing row level locking.
848
if (getLockingPolicy().getMode() != LockingPolicy.MODE_RECORD)
849                 return true;
850         }
851
852         // watch transaction so we will close handle just before xact completes.
853
xact.addObserver(this);
854
855
856         // Add special objects implementing certain behaviour at commit/rollback
857

858         if ((mode & (ContainerHandle.MODE_READONLY |
859                      ContainerHandle.MODE_NO_ACTIONS_ON_COMMIT)) == 0)
860         {
861             if ((mode & MODE_TRUNCATE_ON_COMMIT) == MODE_TRUNCATE_ON_COMMIT)
862             {
863                 xact.addObserver(
864                     new TruncateOnCommit(identity, true /* always */));
865             }
866             else if ((mode & MODE_TRUNCATE_ON_ROLLBACK) ==
867                                         MODE_TRUNCATE_ON_ROLLBACK)
868             {
869                 xact.addObserver(
870                     new TruncateOnCommit(identity, false /* rollbacks only */));
871             }
872
873             if ((mode & MODE_DROP_ON_COMMIT) == MODE_DROP_ON_COMMIT)
874             {
875                 xact.addObserver(new DropOnCommit(identity));
876             }
877
878             if ((mode & MODE_FLUSH_ON_COMMIT) == MODE_FLUSH_ON_COMMIT)
879             {
880                 xact.addObserver(new SyncOnCommit(identity));
881             }
882         }
883
884         return true;
885     }
886
887     /**
888         Return the RawTransaction I was opened in.
889     */

890     public final RawTransaction getTransaction()
891     {
892         return xact;
893     }
894
895     /**
896         Return my locking policy, may be different from the Transaction's
897         default locking policy.
898     */

899     public final LockingPolicy getLockingPolicy()
900     {
901
902         if (SanityManager.DEBUG)
903         {
904             SanityManager.ASSERT(locking != null);
905         }
906
907         return locking;
908     }
909
910     public final void setLockingPolicy(LockingPolicy newLockingPolicy)
911     {
912         locking = newLockingPolicy;
913     }
914
915     /**
916         Was I opened for updates?
917         <p>
918
919         <BR> MT - thread safe
920     */

921     public final boolean updateOK()
922     {
923         return forUpdate;
924     }
925
926     /**
927         Get the mode I was opened with.
928     */

929     public int getMode()
930     {
931         return mode;
932     }
933
934     /**
935        The container is about to be modified.
936        Loggable actions use this to make sure the container gets cleaned if a
937        checkpoint is taken after any log record is sent to the log stream but
938        before the container is actually dirtied.
939
940         @exception StandardException Standard Cloudscape error policy
941      */

942     public void preDirty(boolean preDirtyOn) throws StandardException
943     {
944
945         checkUpdateOpen();
946
947         container.preDirty(preDirtyOn);
948
949     }
950
951     /**
952         @see ContainerHandle#isTemporaryContainer
953         @exception StandardException Standard Cloudscape error policy
954      */

955     public boolean isTemporaryContainer() throws StandardException
956     {
957
958         checkOpen();
959
960         return (identity != null &&
961                 identity.getSegmentId() == ContainerHandle.TEMPORARY_SEGMENT);
962     }
963
964     /*
965     ** Implementation specific methods for myself and my sub-classes
966     */

967
968     protected void checkOpen() throws StandardException
969     {
970         if (!active)
971             throw StandardException.newException(
972                     SQLState.DATA_CONTAINER_CLOSED);
973     }
974
975
976     private void checkUpdateOpen() throws StandardException
977     {
978
979         if (!active)
980         {
981             throw StandardException.newException(
982                     SQLState.DATA_CONTAINER_CLOSED);
983         }
984
985         if (!forUpdate)
986         {
987             throw StandardException.newException(
988                     SQLState.DATA_CONTAINER_READ_ONLY);
989         }
990     }
991
992     protected void informObservers()
993     {
994
995         // notify our observers (Pages) that we are closing,
996
// or undergoing some state change ...
997

998         if (countObservers() != 0)
999         {
1000            setChanged();
1001            notifyObservers();
1002        }
1003    }
1004
1005
1006    /**
1007    Get information about space used by the container.
1008    **/

1009    public SpaceInfo getSpaceInfo()
1010        throws StandardException
1011    {
1012        return container.getSpaceInfo(this);
1013    }
1014
1015
1016    /**
1017     * Backup the container to the specified path.
1018     * @param backupContainerPath location of the backup container.
1019     * @exception StandardException Standard Derby error policy
1020     */

1021    public void backupContainer(String JavaDoc backupContainerPath) throws StandardException
1022    {
1023        checkOpen();
1024        container.backupContainer(this, backupContainerPath);
1025    }
1026
1027
1028
1029    /**
1030     * Create encrypted version of the container with the
1031     * user specified encryption properties.
1032     * @param newFilePath file to store the new encrypted version of the container
1033     * @exception StandardException Standard Derby error policy
1034     */

1035    public void encryptContainer(String JavaDoc newFilePath) throws StandardException
1036    {
1037        checkOpen();
1038        container.encryptContainer(this, newFilePath);
1039    }
1040
1041    
1042    public String JavaDoc toString()
1043    {
1044        if (SanityManager.DEBUG)
1045        {
1046            String JavaDoc str = new String JavaDoc();
1047            str += "BaseContainerHandle:(" + identity.toString() + ")";
1048            return(str);
1049        }
1050        else
1051        {
1052            return(super.toString());
1053        }
1054    }
1055
1056}
1057
Popular Tags