Search in sources :

Example 1 with Cursor

use of org.cojen.tupl.Cursor in project Tupl by cojen.

the class CompressedPageArray method isEmpty.

@Override
public boolean isEmpty() throws IOException {
    Cursor c = mPages.newCursor(Transaction.BOGUS);
    c.first();
    boolean isEmpty = c.key() == null;
    c.reset();
    return isEmpty;
}
Also used : Cursor(org.cojen.tupl.Cursor)

Example 2 with Cursor

use of org.cojen.tupl.Cursor in project Tupl by cojen.

the class CompressedPageArray method writePage.

@Override
public void writePage(long index, long srcPtr, int offset) throws IOException {
    try (Cursor c = mPages.newAccessor(Transaction.BOGUS, keyFor(index))) {
        var entry = mCompressors.access();
        try {
            PageCompressor compressor = entry.get();
            int len = compressor.compress(srcPtr, offset, pageSize());
            c.valueWrite(0, compressor.compressedBytes(), 0, len);
        } finally {
            entry.release();
        }
    }
}
Also used : PageCompressor(org.cojen.tupl.io.PageCompressor) Cursor(org.cojen.tupl.Cursor)

Example 3 with Cursor

use of org.cojen.tupl.Cursor in project Tupl by cojen.

the class CompressedPageArray method writePage.

@Override
public void writePage(long index, byte[] src, int offset) throws IOException {
    try (Cursor c = mPages.newAccessor(Transaction.BOGUS, keyFor(index))) {
        var entry = mCompressors.access();
        try {
            PageCompressor compressor = entry.get();
            int len = compressor.compress(src, offset, pageSize());
            c.valueWrite(0, compressor.compressedBytes(), 0, len);
        } finally {
            entry.release();
        }
    }
}
Also used : PageCompressor(org.cojen.tupl.io.PageCompressor) Cursor(org.cojen.tupl.Cursor)

Example 4 with Cursor

use of org.cojen.tupl.Cursor in project Tupl by cojen.

the class CompressedPageArray method pageCount.

@Override
public long pageCount() throws IOException {
    Cursor c = mPages.newCursor(Transaction.BOGUS);
    c.last();
    byte[] key = c.key();
    c.reset();
    return key == null ? 0 : (indexFor(key) + 1);
}
Also used : Cursor(org.cojen.tupl.Cursor)

Example 5 with Cursor

use of org.cojen.tupl.Cursor in project Tupl by cojen.

the class Primer method prime.

private void prime() {
    try {
        Cursor c = mView.newCursor(Transaction.BOGUS);
        try {
            c.autoload(false);
            while (true) {
                byte[] key;
                synchronized (this) {
                    if (mFinished) {
                        return;
                    }
                    int len = mDin.readUnsignedShort();
                    if (len == 0xffff) {
                        mFinished = true;
                        return;
                    }
                    key = new byte[len];
                    mDin.readFully(key);
                    if (mTaskCount < mTaskLimit)
                        spawn: {
                            try {
                                Runner.start(this::prime);
                            } catch (Throwable e) {
                                break spawn;
                            }
                            mTaskCount++;
                        }
                }
                c.findNearby(key);
            }
        } catch (IOException e) {
            synchronized (this) {
                if (mEx == null) {
                    mEx = e;
                }
            }
        } finally {
            c.reset();
        }
    } finally {
        synchronized (this) {
            mTaskCount--;
            notifyAll();
        }
    }
}
Also used : IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) Cursor(org.cojen.tupl.Cursor)

Aggregations

Cursor (org.cojen.tupl.Cursor)55 LockResult (org.cojen.tupl.LockResult)28 Transaction (org.cojen.tupl.Transaction)12 BoundedView (org.cojen.tupl.views.BoundedView)12 LockFailureException (org.cojen.tupl.LockFailureException)8 UnpositionedCursorException (org.cojen.tupl.UnpositionedCursorException)7 Index (org.cojen.tupl.Index)6 IOException (java.io.IOException)5 Database (org.cojen.tupl.Database)3 LockMode (org.cojen.tupl.LockMode)3 InterruptedIOException (java.io.InterruptedIOException)2 WeakReference (java.lang.ref.WeakReference)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)2 TimeUnit (java.util.concurrent.TimeUnit)2 CorruptDatabaseException (org.cojen.tupl.CorruptDatabaseException)2 UniqueConstraintException (org.cojen.tupl.UniqueConstraintException)2 View (org.cojen.tupl.View)2