001: /*
002:
003: Derby - Class org.apache.derby.impl.store.raw.data.TruncateOnCommit
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.store.raw.data;
023:
024: import org.apache.derby.iapi.store.raw.ContainerHandle;
025: import org.apache.derby.iapi.store.raw.ContainerLock;
026: import org.apache.derby.iapi.store.raw.Page;
027: import org.apache.derby.iapi.store.raw.LockingPolicy;
028: import org.apache.derby.iapi.store.raw.RecordHandle;
029: import org.apache.derby.iapi.store.raw.ContainerKey;
030:
031: import org.apache.derby.iapi.store.raw.data.RawContainerHandle;
032: import org.apache.derby.iapi.store.raw.log.LogInstant;
033: import org.apache.derby.iapi.store.raw.xact.RawTransaction;
034:
035: import org.apache.derby.iapi.services.locks.Lockable;
036:
037: import org.apache.derby.catalog.UUID;
038:
039: import org.apache.derby.iapi.error.StandardException;
040:
041: import org.apache.derby.iapi.services.sanity.SanityManager;
042:
043: import java.util.Observable;
044:
045: /**
046: Truncate a temp table on a commit, abort or rollback to savepoint
047: */
048:
049: public class TruncateOnCommit extends ContainerHandleActionOnCommit {
050:
051: /**
052: Truncate on a commit as well.
053: */
054: private boolean commitAsWell;
055:
056: public TruncateOnCommit(ContainerKey identity, boolean commitAsWell) {
057:
058: super (identity);
059: this .commitAsWell = commitAsWell;
060:
061: if (SanityManager.DEBUG) {
062: if (identity.getSegmentId() != ContainerHandle.TEMPORARY_SEGMENT)
063: SanityManager
064: .THROWASSERT("segment id is not temp segment "
065: + identity.getSegmentId());
066: }
067: }
068:
069: public void update(Observable obj, Object arg) {
070: if (SanityManager.DEBUG) {
071: if (arg == null)
072: SanityManager.THROWASSERT("still on observer list "
073: + this );
074: }
075:
076: if (arg.equals(RawTransaction.ABORT)
077: || arg.equals(RawTransaction.SAVEPOINT_ROLLBACK)
078: || (commitAsWell && arg.equals(RawTransaction.COMMIT))) {
079: openContainerAndDoIt((RawTransaction) obj);
080: }
081:
082: // remove this object if we are commiting, aborting or the container is being dropped
083: if (arg.equals(RawTransaction.COMMIT)
084: || arg.equals(RawTransaction.ABORT)
085: || arg.equals(identity)) {
086: obj.deleteObserver(this );
087: }
088: }
089:
090: /**
091: @exception StandardException Standard Cloudscape error policy
092: */
093: protected void doIt(BaseContainerHandle handle)
094: throws StandardException {
095:
096: handle.container.truncate(handle);
097: }
098:
099: public boolean equals(Object other) {
100:
101: if (other instanceof TruncateOnCommit) {
102:
103: if (((TruncateOnCommit) other).commitAsWell != commitAsWell)
104: return false;
105:
106: return super .equals(other);
107: } else
108: return false;
109: }
110: }
|