Package org.lealone.store

Examples of org.lealone.store.Data


            file.setCheckedWriting(false);
            file.seek(FileStore.HEADER_LENGTH);
            rowBuff = Data.create(db, Constants.DEFAULT_PAGE_SIZE);
            file.seek(FileStore.HEADER_LENGTH);
        }
        Data 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);
View Full Code Here


            r = list.get(index++);
        } else {
            if (listIndex >= list.size()) {
                list.clear();
                listIndex = 0;
                Data buff = rowBuff;
                buff.reset();
                int min = Constants.FILE_BLOCK_SIZE;
                file.readFully(buff.getBytes(), 0, min);
                int len = buff.readInt() * Constants.FILE_BLOCK_SIZE;
                buff.checkCapacity(len);
                if (len - min > 0) {
                    file.readFully(buff.getBytes(), min, len - min);
                }
                while (true) {
                    r = readRow(buff);
                    if (r == null) {
                        break;
View Full Code Here

                int last = storedEntriesPos.size() - 1;
                long pos = storedEntriesPos.get(last);
                storedEntriesPos.remove(last);
                long end = file.length();
                int bufferLength = (int) (end - pos);
                Data buff = Data.create(database, bufferLength);
                file.seek(pos);
                file.readFully(buff.getBytes(), 0, bufferLength);
                while (buff.length() < bufferLength) {
                    UndoLogRecord e = UndoLogRecord.loadFromBuffer(buff, this);
                    records.add(e);
                    memoryUndo++;
                }
                storedEntries -= records.size();
View Full Code Here

                    String fileName = database.createTempFile();
                    file = database.openFile(fileName, "rw", false);
                    file.setCheckedWriting(false);
                    file.setLength(FileStore.HEADER_LENGTH);
                }
                Data buff = Data.create(database, Constants.DEFAULT_PAGE_SIZE);
                for (int i = 0; i < records.size(); i++) {
                    UndoLogRecord r = records.get(i);
                    buff.checkCapacity(Constants.DEFAULT_PAGE_SIZE);
                    r.append(buff, this);
                    if (i == records.size() - 1 || buff.length() > Constants.UNDO_BLOCK_SIZE) {
                        storedEntriesPos.add(file.getFilePointer());
                        file.write(buff.getBytes(), 0, buff.length());
                        buff.reset();
                    }
                }
                storedEntries += records.size();
                memoryUndo = 0;
                records.clear();
                file.autoDelete();
                return;
            }
        } else {
            if (!entry.isStored()) {
                memoryUndo++;
            }
            if (memoryUndo > database.getMaxMemoryUndo() && database.isPersistent() && !database.isMultiVersion()) {
                if (file == null) {
                    String fileName = database.createTempFile();
                    file = database.openFile(fileName, "rw", false);
                    file.setCheckedWriting(false);
                    file.seek(FileStore.HEADER_LENGTH);
                    rowBuff = Data.create(database, Constants.DEFAULT_PAGE_SIZE);
                    Data buff = rowBuff;
                    for (int i = 0; i < records.size(); i++) {
                        UndoLogRecord r = records.get(i);
                        saveIfPossible(r, buff);
                    }
                } else {
View Full Code Here

    public int addRows(ArrayList<Value[]> rows) {
        if (sort != null) {
            sort.sort(rows);
        }
        Data buff = rowBuff;
        long start = file.getFilePointer();
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        int bufferLen = 0;
        for (Value[] row : rows) {
            buff.reset();
            buff.writeInt(0);
            for (int j = 0; j < columnCount; j++) {
                Value v = row[j];
                buff.checkCapacity(buff.getValueLen(v));
                buff.writeValue(v);
            }
            buff.fillAligned();
            int len = buff.length();
            buff.setInt(0, len);
            if (maxBufferSize > 0) {
                buffer.write(buff.getBytes(), 0, len);
                bufferLen += len;
                if (bufferLen > maxBufferSize) {
                    byte[] data = buffer.toByteArray();
                    buffer.reset();
                    file.write(data, 0, data.length);
                    bufferLen = 0;
                }
            } else {
                file.write(buff.getBytes(), 0, len);
            }
        }
        if (bufferLen > 0) {
            byte[] data = buffer.toByteArray();
            file.write(data, 0, data.length);
View Full Code Here

        }
    }

    private void readRow(ResultDiskTape tape) {
        int min = Constants.FILE_BLOCK_SIZE;
        Data buff = rowBuff;
        buff.reset();
        file.readFully(buff.getBytes(), 0, min);
        int len = buff.readInt();
        buff.checkCapacity(len);
        if (len - min > 0) {
            file.readFully(buff.getBytes(), min, len - min);
        }
        tape.pos += len;
        Value[] row = new Value[columnCount];
        for (int k = 0; k < columnCount; k++) {
            row[k] = buff.readValue();
        }
        tape.buffer.add(row);
    }
View Full Code Here

TOP

Related Classes of org.lealone.store.Data

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.