Search in sources :

Example 1 with Block

use of org.apache.jena.dboe.base.block.Block in project jena by apache.

the class BlockAccessDirect method allocate.

@Override
public Block allocate(int blkSize) {
    if (blkSize > 0 && blkSize != this.blockSize)
        throw new FileException("Fixed blocksize only: request= " + blkSize + "fixed size=" + this.blockSize);
    int x = allocateId();
    ByteBuffer bb = ByteBuffer.allocate(blkSize);
    Block block = new Block(x, bb);
    return block;
}
Also used : Block(org.apache.jena.dboe.base.block.Block) ByteBuffer(java.nio.ByteBuffer)

Example 2 with Block

use of org.apache.jena.dboe.base.block.Block in project jena by apache.

the class BlockAccessMem method allocate.

@Override
public Block allocate(int blkSize) {
    checkNotClosed();
    if (blkSize > 0 && blkSize != this.blockSize)
        throw new FileException("Fixed blocksize only: request= " + blkSize + " / fixed size=" + this.blockSize);
    int x = blocks.size();
    ByteBuffer bb = ByteBuffer.allocate(blkSize);
    Block block = new Block(x, bb);
    blocks.add(block);
    return block;
}
Also used : Block(org.apache.jena.dboe.base.block.Block) ByteBuffer(java.nio.ByteBuffer)

Example 3 with Block

use of org.apache.jena.dboe.base.block.Block in project jena by apache.

the class BPTreeNode method promote.

@Override
final boolean promote() {
    if (bpTree.getNodeManager().isWritable(this.getId()))
        return false;
    // This calls reset is needed.
    // The id, records buffer and pointer buffers need resetting if the block changed.
    boolean promoteInPlace = bpTree.state().modifiableNodeBlock(getId());
    if (promoteInPlace) {
        bpTree.getNodeManager().promoteInPlace(this);
        return false;
    } else {
        Block oldBlock = block;
        boolean b = bpTree.getNodeManager().promoteDuplicate(this);
        if (b) {
            bpTree.getNodeManager().getBlockMgr().release(oldBlock);
        }
        return b;
    }
}
Also used : Block(org.apache.jena.dboe.base.block.Block)

Example 4 with Block

use of org.apache.jena.dboe.base.block.Block in project jena by apache.

the class BPTreeRecords method promote.

@Override
final boolean promote() {
    if (bprRecordsMgr.isWritable(getId()))
        return false;
    // reset() will be called if necessary.
    boolean promoteInPlace = (bpTree == null) ? true : bpTree.state().modifiableRecordsBlock(getId());
    if (promoteInPlace) {
        bprRecordsMgr.promoteInPlace(this);
        if (getBackingBlock().isReadOnly())
            bprRecordsMgr.getBlockMgr().promote(getBackingBlock());
        return false;
    } else {
        Block oldBlock = getBackingBlock();
        boolean b = bprRecordsMgr.promoteDuplicate(this);
        if (b)
            bprRecordsMgr.getBlockMgr().release(oldBlock);
        return b;
    }
}
Also used : Block(org.apache.jena.dboe.base.block.Block)

Example 5 with Block

use of org.apache.jena.dboe.base.block.Block in project jena by apache.

the class BlockAccessByteArray method read.

@Override
public Block read(long id) {
    // Variable length blocks.
    if (id < 0 || id >= length || id >= bytes.capacity())
        throw new FileException("Bad id (read): " + id);
    bytes.position((int) id);
    int len = bytes.getInt();
    ByteBuffer bb = ByteBuffer.allocate(len);
    // Copy out the bytes - copy for safety.
    bytes.get(bb.array(), 0, len);
    return new Block(id, bb);
}
Also used : Block(org.apache.jena.dboe.base.block.Block) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Block (org.apache.jena.dboe.base.block.Block)24 ByteBuffer (java.nio.ByteBuffer)7 Test (org.junit.Test)5 MappedByteBuffer (java.nio.MappedByteBuffer)2 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)1