KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.data.ContainerHandleActionOnCommit
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.store.raw.ContainerHandle;
25 import org.apache.derby.iapi.store.raw.ContainerLock;
26 import org.apache.derby.iapi.store.raw.Page;
27 import org.apache.derby.iapi.store.raw.LockingPolicy;
28 import org.apache.derby.iapi.store.raw.RecordHandle;
29 import org.apache.derby.iapi.store.raw.ContainerKey;
30
31 import org.apache.derby.iapi.store.raw.data.RawContainerHandle;
32 import org.apache.derby.iapi.store.raw.log.LogInstant;
33 import org.apache.derby.iapi.store.raw.xact.RawTransaction;
34
35 import org.apache.derby.iapi.services.locks.Lockable;
36
37 import org.apache.derby.catalog.UUID;
38
39 import org.apache.derby.iapi.error.StandardException;
40
41 import org.apache.derby.iapi.services.sanity.SanityManager;
42
43 /**
44     An abstract class that opens the container at commit and delegates
45     the actual work to a sub-class.
46 */

47
48 public abstract class ContainerHandleActionOnCommit extends ContainerActionOnCommit {
49
50     public ContainerHandleActionOnCommit(ContainerKey identity) {
51
52         super(identity);
53     }
54
55     /*
56     ** Methods of Observer
57     */

58
59     /**
60         Open the container and call the doIt method
61     */

62     public void openContainerAndDoIt(RawTransaction xact) {
63
64         BaseContainerHandle handle = null;
65         try {
66             handle = (BaseContainerHandle) xact.openContainer(identity, (LockingPolicy) null,
67                 ContainerHandle.MODE_FORUPDATE | ContainerHandle.MODE_NO_ACTIONS_ON_COMMIT);
68
69             // if the handle is null, the container may have been removed by a previous observer.
70
if (handle != null) {
71                 try {
72                     doIt(handle);
73                 } catch (StandardException se) {
74                     xact.setObserverException(se);
75                 }
76             }
77
78         } catch (StandardException se) {
79
80             // if we get this exception, then the container is readonly.
81
// no problem if we can't open an closed temp container.
82
if (identity.getSegmentId() != ContainerHandle.TEMPORARY_SEGMENT)
83                 xact.setObserverException(se);
84         } finally {
85             if (handle != null)
86                 handle.close();
87         }
88     }
89
90     protected abstract void doIt(BaseContainerHandle handle)
91         throws StandardException;
92 }
93
Popular Tags