KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.data.TruncateOnCommit
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 import java.util.Observable JavaDoc;
44
45 /**
46     Truncate a temp table on a commit, abort or rollback to savepoint
47 */

48
49 public class TruncateOnCommit extends ContainerHandleActionOnCommit {
50
51     /**
52         Truncate on a commit as well.
53     */

54     private boolean commitAsWell;
55
56     public TruncateOnCommit(ContainerKey identity, boolean commitAsWell) {
57
58         super(identity);
59         this.commitAsWell = commitAsWell;
60
61         if (SanityManager.DEBUG) {
62             if (identity.getSegmentId() != ContainerHandle.TEMPORARY_SEGMENT)
63                 SanityManager.THROWASSERT("segment id is not temp segment " + identity.getSegmentId());
64         }
65     }
66
67     public void update(Observable JavaDoc obj, Object JavaDoc arg) {
68         if (SanityManager.DEBUG) {
69             if (arg == null)
70                 SanityManager.THROWASSERT("still on observer list " + this);
71         }
72
73         if (arg.equals(RawTransaction.ABORT) ||
74             arg.equals(RawTransaction.SAVEPOINT_ROLLBACK) ||
75             (commitAsWell && arg.equals(RawTransaction.COMMIT))) {
76             openContainerAndDoIt((RawTransaction) obj);
77         }
78
79         // remove this object if we are commiting, aborting or the container is being dropped
80
if (arg.equals(RawTransaction.COMMIT) || arg.equals(RawTransaction.ABORT)
81             || arg.equals(identity)) {
82             obj.deleteObserver(this);
83         }
84     }
85
86     /**
87         @exception StandardException Standard Cloudscape error policy
88     */

89     protected void doIt(BaseContainerHandle handle)
90         throws StandardException {
91
92         handle.container.truncate(handle);
93     }
94
95     public boolean equals(Object JavaDoc other) {
96
97         if (other instanceof TruncateOnCommit) {
98
99             if (((TruncateOnCommit) other).commitAsWell
100                 != commitAsWell)
101                 return false;
102
103             return super.equals(other);
104         }
105         else
106             return false;
107     }
108 }
109
Popular Tags