--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.store.raw.data.TruncateOnCommit\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.store.raw.data;\r
+\r
+import org.apache.derby.iapi.store.raw.ContainerHandle;\r
+import org.apache.derby.iapi.store.raw.ContainerLock;\r
+import org.apache.derby.iapi.store.raw.Page;\r
+import org.apache.derby.iapi.store.raw.LockingPolicy;\r
+import org.apache.derby.iapi.store.raw.RecordHandle;\r
+import org.apache.derby.iapi.store.raw.ContainerKey;\r
+\r
+import org.apache.derby.iapi.store.raw.data.RawContainerHandle;\r
+import org.apache.derby.iapi.store.raw.log.LogInstant;\r
+import org.apache.derby.iapi.store.raw.xact.RawTransaction;\r
+\r
+import org.apache.derby.iapi.services.locks.Lockable;\r
+\r
+import org.apache.derby.catalog.UUID;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import java.util.Observable;\r
+\r
+/**\r
+ Truncate a temp table on a commit, abort or rollback to savepoint\r
+*/\r
+\r
+public class TruncateOnCommit extends ContainerHandleActionOnCommit {\r
+\r
+ /**\r
+ Truncate on a commit as well.\r
+ */\r
+ private boolean commitAsWell;\r
+\r
+ public TruncateOnCommit(ContainerKey identity, boolean commitAsWell) {\r
+\r
+ super(identity);\r
+ this.commitAsWell = commitAsWell;\r
+\r
+ if (SanityManager.DEBUG) {\r
+ if (identity.getSegmentId() != ContainerHandle.TEMPORARY_SEGMENT)\r
+ SanityManager.THROWASSERT("segment id is not temp segment " + identity.getSegmentId());\r
+ }\r
+ }\r
+\r
+ public void update(Observable obj, Object arg) {\r
+ if (SanityManager.DEBUG) {\r
+ if (arg == null)\r
+ SanityManager.THROWASSERT("still on observer list " + this);\r
+ }\r
+\r
+ if (arg.equals(RawTransaction.ABORT) ||\r
+ arg.equals(RawTransaction.SAVEPOINT_ROLLBACK) ||\r
+ (commitAsWell && arg.equals(RawTransaction.COMMIT))) {\r
+ openContainerAndDoIt((RawTransaction) obj);\r
+ }\r
+\r
+ // remove this object if we are commiting, aborting or the container is being dropped\r
+ if (arg.equals(RawTransaction.COMMIT) || arg.equals(RawTransaction.ABORT)\r
+ || arg.equals(identity)) {\r
+ obj.deleteObserver(this);\r
+ }\r
+ }\r
+\r
+ /**\r
+ @exception StandardException Standard Derby error policy\r
+ */\r
+ protected void doIt(BaseContainerHandle handle)\r
+ throws StandardException {\r
+\r
+ handle.container.truncate(handle);\r
+ }\r
+\r
+ public boolean equals(Object other) {\r
+\r
+ if (other instanceof TruncateOnCommit) {\r
+\r
+ if (((TruncateOnCommit) other).commitAsWell\r
+ != commitAsWell)\r
+ return false;\r
+\r
+ return super.equals(other);\r
+ }\r
+ else\r
+ return false;\r
+ }\r
+}\r