1 21 22 package org.apache.derby.impl.store.raw.data; 23 24 import org.apache.derby.iapi.store.raw.Loggable; 25 import org.apache.derby.iapi.store.raw.Undoable; 26 import org.apache.derby.iapi.store.raw.Transaction; 27 import org.apache.derby.iapi.store.raw.Compensation; 28 import org.apache.derby.iapi.services.io.FormatIdUtil; 29 import org.apache.derby.iapi.services.io.StoredFormatIds; 30 31 import org.apache.derby.iapi.store.raw.xact.RawTransaction; 32 33 import org.apache.derby.iapi.error.StandardException; 34 import org.apache.derby.iapi.services.sanity.SanityManager; 35 import org.apache.derby.iapi.store.access.FileResource; 36 import org.apache.derby.iapi.store.raw.log.LogInstant; 37 38 import org.apache.derby.io.StorageFile; 39 40 import org.apache.derby.iapi.util.ByteArray; 41 42 import java.io.ObjectInput ; 43 import java.io.ObjectOutput ; 44 import java.io.IOException ; 45 import java.io.InputStream ; 46 import org.apache.derby.iapi.services.io.LimitObjectInput; 47 48 50 51 public class RemoveFileOperation implements Undoable 52 { 53 private String name; 54 private long generationId; 55 private boolean removeAtOnce; 56 57 transient private StorageFile fileToGo; 58 59 public RemoveFileOperation() 61 { 62 } 63 64 RemoveFileOperation(String name, long generationId, boolean removeAtOnce) 65 { 66 this.name = name; 67 this.generationId = generationId; 68 this.removeAtOnce = removeAtOnce; 69 } 70 71 74 public void writeExternal(ObjectOutput out) throws IOException 75 { 76 out.writeUTF(name); 77 out.writeLong(generationId); 78 out.writeBoolean(removeAtOnce); 79 } 80 81 public void readExternal(ObjectInput in) 82 throws IOException , ClassNotFoundException 83 { 84 name = in.readUTF(); 85 generationId = in.readLong(); 86 removeAtOnce = in.readBoolean(); 87 } 88 91 public int getTypeFormatId() { 92 return StoredFormatIds.LOGOP_REMOVE_FILE; 93 } 94 95 96 99 100 107 public ByteArray getPreparedLog() 108 { 109 return null; 110 } 111 112 public void releaseResource(Transaction tran) 113 { 114 } 115 116 119 public int group() 120 { 121 return Loggable.FILE_RESOURCE | Loggable.RAWSTORE ; 122 } 123 124 public void doMe(Transaction xact, LogInstant instant, 125 LimitObjectInput in) 126 throws StandardException 127 { 128 if (fileToGo == null) 129 return; 130 131 BaseDataFileFactory bdff = 132 (BaseDataFileFactory) ((RawTransaction) xact).getDataFactory(); 133 134 bdff.fileToRemove(fileToGo, true); 135 } 136 137 138 141 public boolean needsRedo(Transaction xact) 142 throws StandardException 143 { 144 if (!removeAtOnce) 145 return false; 146 147 FileResource fr = ((RawTransaction) xact).getDataFactory().getFileHandler(); 148 149 fileToGo = fr.getAsFile(name, generationId); 150 151 if (fileToGo == null) 152 return false; 153 154 return fileToGo.exists(); 155 } 156 157 158 public Compensation generateUndo(Transaction xact, LimitObjectInput in) 159 throws StandardException, IOException { 160 161 162 if (fileToGo != null) { 163 BaseDataFileFactory bdff = 164 (BaseDataFileFactory) ((RawTransaction) xact).getDataFactory(); 165 166 bdff.fileToRemove(fileToGo, false); 167 } 168 169 return null; 170 } 171 } 172 173 174 | Popular Tags |