1 21 22 package org.apache.derby.impl.store.raw.log; 23 24 import org.apache.derby.iapi.reference.SQLState; 25 26 import org.apache.derby.impl.store.raw.log.LogCounter; 27 import org.apache.derby.impl.store.raw.log.LogRecord; 28 import org.apache.derby.impl.store.raw.log.StreamLogScan; 29 import org.apache.derby.iapi.services.io.ArrayInputStream; 30 import org.apache.derby.iapi.services.sanity.SanityManager; 31 import org.apache.derby.iapi.error.StandardException; 32 import org.apache.derby.iapi.store.raw.Loggable; 33 import org.apache.derby.iapi.store.raw.ScanHandle; 34 import org.apache.derby.iapi.store.raw.ScannedTransactionHandle; 35 import org.apache.derby.iapi.store.raw.log.LogFactory; 36 import org.apache.derby.iapi.store.raw.log.LogInstant; 37 import org.apache.derby.iapi.store.raw.xact.TransactionId; 38 import org.apache.derby.iapi.store.access.DatabaseInstant; 39 import java.io.IOException ; 40 import java.io.InputStream ; 41 import java.util.Enumeration ; 42 43 public class FlushedScanHandle implements ScanHandle 44 { 45 LogFactory lf; 46 StreamLogScan fs; 47 48 LogRecord lr = null; 49 boolean readOptionalData = false; 50 int groupsIWant; 51 52 ArrayInputStream rawInput = new ArrayInputStream(new byte[4096]); 53 54 FlushedScanHandle(LogToFile lf, DatabaseInstant start, int groupsIWant) 55 throws StandardException 56 { 57 this.lf = lf; 58 fs = new FlushedScan(lf,((LogCounter)start).getValueAsLong()); 59 this.groupsIWant = groupsIWant; 60 } 61 62 public boolean next() throws StandardException 63 { 64 readOptionalData = false; 65 lr = null; 66 67 70 try 71 { 72 lr = fs.getNextRecord(rawInput,null, groupsIWant); 73 if (lr==null) return false; if (SanityManager.DEBUG) 75 { 76 if ((groupsIWant & lr.group()) == 0) 77 SanityManager.THROWASSERT(groupsIWant + "/" + lr.group()); 78 } 79 80 return true; 81 } 82 catch (IOException ioe) 83 { 84 ioe.printStackTrace(); 85 fs.close(); 86 fs = null; 87 throw lf.markCorrupt( 88 StandardException.newException(SQLState.LOG_IO_ERROR, ioe)); 89 } 90 } 91 92 96 public int getGroup() throws StandardException 97 { 98 return lr.group(); 99 } 100 101 105 public Loggable getLoggable() throws StandardException 106 { 107 try { 108 return lr.getLoggable(); 109 } 110 111 catch (IOException ioe) 112 { 113 ioe.printStackTrace(); 114 fs.close(); 115 fs = null; 116 throw lf.markCorrupt( 117 StandardException.newException(SQLState.LOG_IO_ERROR, ioe)); 118 } 119 120 catch (ClassNotFoundException cnfe) 121 { 122 fs.close(); 123 fs = null; 124 throw lf.markCorrupt( 125 StandardException.newException(SQLState.LOG_CORRUPTED, cnfe)); 126 } 127 } 128 129 public InputStream getOptionalData() 131 throws StandardException 132 { 133 if (SanityManager.DEBUG) SanityManager.ASSERT(!readOptionalData); 134 if (lr == null) return null; 135 try 136 { 137 int dataLength = rawInput.readInt(); 138 readOptionalData = true; 139 rawInput.setLimit(rawInput.getPosition(), dataLength); 140 return rawInput; 141 } 142 143 catch (IOException ioe) 144 { 145 fs.close(); 146 fs = null; 147 throw lf.markCorrupt( 148 StandardException.newException(SQLState.LOG_IO_ERROR, ioe)); 149 } 150 } 151 152 public DatabaseInstant getInstant() 153 throws StandardException 154 { 155 return fs.getLogInstant(); 156 } 157 158 public Object getTransactionId() 159 throws StandardException 160 { 161 try 162 { 163 return lr.getTransactionId(); 164 } 165 catch (IOException ioe) 166 { 167 ioe.printStackTrace(); 168 fs.close(); 169 fs = null; 170 throw lf.markCorrupt( 171 StandardException.newException(SQLState.LOG_IO_ERROR, ioe)); 172 } 173 catch (ClassNotFoundException cnfe) 174 { 175 fs.close(); 176 fs = null; 177 throw lf.markCorrupt( 178 StandardException.newException(SQLState.LOG_CORRUPTED, cnfe)); 179 } 180 } 181 182 public void close() 183 { 184 if (fs != null) fs.close(); 185 fs = null; 186 } 187 } 188 | Popular Tags |