public void seek(long x) { this.pos = x; super.seek(x); }
@Override public void done() { file.seek(FileStorage.HEADER_LENGTH); file.autoDelete(); }
private Value[] nextUnsorted() { file.seek(mainTape.pos); if (mainTape.buffer.isEmpty()) { for (int j = 0; mainTape.pos < mainTape.end && j < READ_AHEAD; j++) { readRow(mainTape); } } Value[] row = mainTape.buffer.get(0); mainTape.buffer.remove(0); return row; }
/** * Remove all rows from the list. */ public void reset() { index = 0; if (file != null) { listIndex = 0; if (!written) { writeAllRows(); written = true; } list.clear(); file.seek(FileStorage.HEADER_LENGTH); } }
private Value[] nextSorted() { int next = -1; for (int i = 0, size = tapes.size(); i < size; i++) { ResultDiskTape tape = tapes.get(i); if (tape.buffer.isEmpty() && tape.pos < tape.end) { file.seek(tape.pos); for (int j = 0; tape.pos < tape.end && j < READ_AHEAD; j++) { readRow(tape); } } if (tape.buffer.size() > 0) { if (next == -1) { next = i; } else if (compareTapes(tape, tapes.get(next)) < 0) { next = i; } } } ResultDiskTape t = tapes.get(next); Value[] row = t.buffer.get(0); t.buffer.remove(0); return row; }
private void writeAllRows() { if (file == null) { Database db = session.getDatabase(); String fileName = db.createTempFile(); file = db.openFile(fileName, "rw", false); file.setCheckedWriting(false); file.seek(FileStorage.HEADER_LENGTH); rowBuff = DataBuffer.create(db, Constants.DEFAULT_PAGE_SIZE); file.seek(FileStorage.HEADER_LENGTH); } DataBuffer buff = rowBuff; initBuffer(buff); for (int i = 0, size = list.size(); i < size; i++) { if (i > 0 && buff.length() > Constants.IO_BUFFER_SIZE) { flushBuffer(buff); initBuffer(buff); } Row r = list.get(i); writeRow(buff, r); } flushBuffer(buff); file.autoDelete(); list.clear(); memory = 0; }
} else { seek(0); byte[] buff = new byte[len]; readFullyDirect(buff, 0, len);
ResultDiskBuffer(ServerSession session, SortOrder sort, int columnCount) { this.parent = null; this.sort = sort; this.columnCount = columnCount; Database db = session.getDatabase(); rowBuff = DataBuffer.create(db, Constants.DEFAULT_PAGE_SIZE); String fileName = db.createTempFile(); file = db.openFile(fileName, "rw", false); file.setCheckedWriting(false); file.seek(FileStorage.HEADER_LENGTH); if (sort != null) { tapes = Utils.newSmallArrayList(); mainTape = null; } else { tapes = null; mainTape = new ResultDiskTape(); mainTape.pos = FileStorage.HEADER_LENGTH; } this.maxBufferSize = db.getSettings().largeResultBufferSize; }