Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / store / raw / data / RemoveFileOperation.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/raw/data/RemoveFileOperation.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/raw/data/RemoveFileOperation.java
new file mode 100644 (file)
index 0000000..91115c5
--- /dev/null
@@ -0,0 +1,173 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.store.raw.data.RemoveFileOperation\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.Loggable;\r
+import org.apache.derby.iapi.store.raw.Undoable;\r
+import org.apache.derby.iapi.store.raw.Transaction;\r
+import org.apache.derby.iapi.store.raw.Compensation;\r
+import org.apache.derby.iapi.services.io.FormatIdUtil;\r
+import org.apache.derby.iapi.services.io.StoredFormatIds;\r
+\r
+import org.apache.derby.iapi.store.raw.xact.RawTransaction;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.store.access.FileResource;\r
+import org.apache.derby.iapi.store.raw.log.LogInstant;\r
+\r
+import org.apache.derby.io.StorageFile;\r
+\r
+import org.apache.derby.iapi.util.ByteArray;\r
+\r
+import java.io.ObjectInput;\r
+import java.io.ObjectOutput;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import org.apache.derby.iapi.services.io.LimitObjectInput;\r
+\r
+/** \r
+*/\r
+\r
+public class RemoveFileOperation implements Undoable\r
+{\r
+       private String name;\r
+       private long generationId;\r
+       private boolean removeAtOnce;\r
+\r
+       transient private StorageFile fileToGo;\r
+\r
+       // no-arg constructor, required by Formatable\r
+       public RemoveFileOperation()\r
+       {\r
+       }\r
+\r
+       RemoveFileOperation(String name, long generationId, boolean removeAtOnce)\r
+       {\r
+               this.name = name;\r
+               this.generationId = generationId;\r
+               this.removeAtOnce = removeAtOnce;\r
+       }\r
+\r
+       /*\r
+        * Formatable methods\r
+        */\r
+       public void writeExternal(ObjectOutput out) throws IOException\r
+       {\r
+               out.writeUTF(name);\r
+               out.writeLong(generationId);\r
+               out.writeBoolean(removeAtOnce);\r
+       }\r
+\r
+       public void readExternal(ObjectInput in) \r
+                throws IOException, ClassNotFoundException \r
+       {\r
+               name = in.readUTF();\r
+               generationId = in.readLong();\r
+               removeAtOnce = in.readBoolean();\r
+       }\r
+       /**\r
+               Return my format identifier.\r
+       */\r
+       public int getTypeFormatId() {\r
+               return StoredFormatIds.LOGOP_REMOVE_FILE;\r
+       }\r
+\r
+\r
+       /**\r
+               Loggable methods\r
+       */\r
+\r
+       /**\r
+               the default for prepared log is always null for all the operations\r
+               that don't have optionalData.  If an operation has optional data,\r
+               the operation need to prepare the optional data for this method.\r
+\r
+               Space Operation has no optional data to write out\r
+       */\r
+       public ByteArray getPreparedLog()\r
+       {\r
+               return null;\r
+       }\r
+\r
+       public void releaseResource(Transaction tran)\r
+       {\r
+       }\r
+\r
+       /**\r
+               A space operation is a RAWSTORE log record\r
+       */\r
+       public int group()\r
+       {\r
+               return Loggable.FILE_RESOURCE | Loggable.RAWSTORE ;\r
+       }\r
+\r
+       public void doMe(Transaction xact, LogInstant instant, \r
+                                                  LimitObjectInput in)\r
+                throws StandardException\r
+       {\r
+               if (fileToGo == null)\r
+                       return;\r
+\r
+               BaseDataFileFactory bdff = \r
+                       (BaseDataFileFactory) ((RawTransaction) xact).getDataFactory();\r
+               \r
+               bdff.fileToRemove(fileToGo, true);\r
+       }\r
+\r
+\r
+       /**\r
+               @exception StandardException Standard Derby error policy\r
+       */\r
+       public boolean needsRedo(Transaction xact)\r
+                throws StandardException\r
+       {\r
+               if (!removeAtOnce)\r
+                       return false;\r
+\r
+               FileResource fr = ((RawTransaction) xact).getDataFactory().getFileHandler();\r
+\r
+               fileToGo = fr.getAsFile(name, generationId);\r
+\r
+               if (fileToGo == null)\r
+                       return false;\r
+\r
+        return fileToGo.exists();\r
+       }\r
+\r
+\r
+       public Compensation generateUndo(Transaction xact, LimitObjectInput in)\r
+               throws StandardException, IOException {\r
+\r
+\r
+               if (fileToGo != null) {\r
+                       BaseDataFileFactory bdff = \r
+                               (BaseDataFileFactory) ((RawTransaction) xact).getDataFactory();\r
+               \r
+                       bdff.fileToRemove(fileToGo, false);\r
+               }\r
+\r
+               return null;\r
+       }\r
+}\r
+\r
+\r