當前位置: 首頁>>代碼示例>>Java>>正文


Java Cursor.getSearchKeyRange方法代碼示例

本文整理匯總了Java中com.sleepycat.je.Cursor.getSearchKeyRange方法的典型用法代碼示例。如果您正苦於以下問題:Java Cursor.getSearchKeyRange方法的具體用法?Java Cursor.getSearchKeyRange怎麽用?Java Cursor.getSearchKeyRange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sleepycat.je.Cursor的用法示例。


在下文中一共展示了Cursor.getSearchKeyRange方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: examineGTEBucket

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
 * Find a bucket that is GTE the target, and sees if that bucket is
 * the owner. If it is not the owner look at the previous bucket. 
 * @return null if no GTE bucket was found.
 */
private VLSNBucket examineGTEBucket(VLSN target, Cursor cursor) {

    /* getSearchKeyRange will return a bucket >= target if one exists */
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    LongBinding.longToEntry(target.getSequence(), key);
    OperationStatus status =
        cursor.getSearchKeyRange(key, data, LockMode.DEFAULT);

    if (status == OperationStatus.SUCCESS) {
        VLSNBucket bucket = VLSNBucket.readFromDatabase(data);
        if (bucket.owns(target)) {
            return bucket;
        }

        /*
         * The bucket we found is > than our target. Look at the
         * previous one.
         */
        status = cursor.getPrev(key, data, LockMode.DEFAULT);
        if (isValidBucket(status, key)) {
            VLSNBucket prevBucket = VLSNBucket.readFromDatabase(data);
            if (prevBucket.owns(target)) {
                return prevBucket;
            }
        }

        /*
         * There is no bucket that owns this target, return the greater
         * one.
         */
        return bucket;
    } 

    /* No bucket at a key >= the target. */
    return null;
}
 
開發者ID:prat0318,項目名稱:dbms,代碼行數:43,代碼來源:VLSNIndex.java

示例2: positionBeforeOrEqual

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
private boolean positionBeforeOrEqual(Cursor cursor,
                                      VLSN vlsn,
                                      DatabaseEntry key,
                                      DatabaseEntry data)
    throws DatabaseException {

    LongBinding.longToEntry(vlsn.getSequence(), key);
    VLSNBucket bucket = null;

    /* getSearchKeyRange will give us a bucket >= Y. */
    OperationStatus status =
        cursor.getSearchKeyRange(key, data, LockMode.DEFAULT);

    if (status == OperationStatus.SUCCESS) {
        bucket = VLSNBucket.readFromDatabase(data);
        if (bucket.owns(vlsn)) {
            return true;
        }

        /* The bucket we found is > than our VLSN. Get the previous one. */
        status = cursor.getPrev(key, data, LockMode.DEFAULT);
        if (isValidBucket(status, key)) {
            return true;
        }

        /* Hey, nothing else in the database. */
        return false;
    }
    /*
     * There was no bucket >= Y. Let's find the last bucket in this
     * database then. It should be a bucket that's < Y.
     */
    status =  cursor.getLast(key, data, LockMode.DEFAULT);
    if (isValidBucket(status, key)) {
        return true;
    }

    return false;
}
 
開發者ID:prat0318,項目名稱:dbms,代碼行數:40,代碼來源:VLSNIndex.java

示例3: testGetSearchKeyRange_Success

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testGetSearchKeyRange_Success()
    throws DatabaseException, InterruptedException {

    openEnv(false);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    OperationStatus status;

    /* Insert key 1 and 3. */
    insert(1);
    insert(3);

    /* getSearchKeyRange for key 2 returns key 3. */
    Transaction readerTxn = env.beginTransaction(null, txnConfig);
    Cursor cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(3, IntegerBinding.entryToInt(key));

    /* Insert key 2 in a writer thread. */
    startInsert(2);

    /*
     * If serializable, getSearchKeyRange should return key 3 again;
     * otherwise getSearchKeyRange should see key 2.
     */
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    if (txnSerializable) {
        assertEquals(3, IntegerBinding.entryToInt(key));
    } else {
        assertEquals(2, IntegerBinding.entryToInt(key));
    }

    /* Close reader to allow writer to finish. */
    cursor.close();
    readerTxn.commitNoSync();
    waitForInsert();

    /* getSearchKeyRange returns key 2. */
    readerTxn = env.beginTransaction(null, txnConfig);
    cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(2, IntegerBinding.entryToInt(key));
    cursor.close();
    readerTxn.commit();

    closeEnv();
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:54,代碼來源:PhantomTest.java

示例4: testGetSearchKeyRange_Success_Dup

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testGetSearchKeyRange_Success_Dup()
    throws DatabaseException, InterruptedException {

    openEnv(true);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    OperationStatus status;

    /* Insert dups. */
    insert(1, 1);
    insert(1, 2);
    insert(3, 2);
    insert(3, 3);

    /* getSearchKeyRange for key 2 returns {3,2}. */
    Transaction readerTxn = env.beginTransaction(null, txnConfig);
    Cursor cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(3, IntegerBinding.entryToInt(key));
    assertEquals(2, IntegerBinding.entryToInt(data));
    assertEquals(OperationStatus.SUCCESS, status);

    /* Insert {3,1} in a writer thread. */
    startInsert(3, 1);

    /*
     * If serializable, getSearchKeyRange should return {3,2} again;
     * otherwise getSearchKeyRange should see {3,1}.
     */
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    if (txnSerializable) {
        assertEquals(3, IntegerBinding.entryToInt(key));
        assertEquals(2, IntegerBinding.entryToInt(data));
    } else {
        assertEquals(3, IntegerBinding.entryToInt(key));
        assertEquals(1, IntegerBinding.entryToInt(data));
    }

    /* Close reader to allow writer to finish. */
    cursor.close();
    readerTxn.commitNoSync();
    waitForInsert();

    /* getSearchKeyRange returns {3,1}. */
    readerTxn = env.beginTransaction(null, txnConfig);
    cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(3, IntegerBinding.entryToInt(key));
    assertEquals(1, IntegerBinding.entryToInt(data));
    cursor.close();
    readerTxn.commit();

    closeEnv();
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:60,代碼來源:PhantomTest.java

示例5: testGetSearchKeyRange_NotFound

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testGetSearchKeyRange_NotFound()
    throws DatabaseException, InterruptedException {

    openEnv(false);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    OperationStatus status;

    /* Insert key 1. */
    insert(1);

    /* getSearchKeyRange for key 2 returns NOTFOUND. */
    Transaction readerTxn = env.beginTransaction(null, txnConfig);
    Cursor cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.NOTFOUND, status);

    /* Insert key 3 in a writer thread. */
    startInsert(3);

    /*
     * If serializable, getSearchKeyRange should return NOTFOUND again;
     * otherwise getSearchKeyRange should see key 3.
     */
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    if (txnSerializable) {
        assertEquals(OperationStatus.NOTFOUND, status);
    } else {
        assertEquals(OperationStatus.SUCCESS, status);
        assertEquals(3, IntegerBinding.entryToInt(key));
    }

    /* Close reader to allow writer to finish. */
    cursor.close();
    readerTxn.commitNoSync();
    waitForInsert();

    /* getSearchKeyRange returns key 3. */
    readerTxn = env.beginTransaction(null, txnConfig);
    cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(3, IntegerBinding.entryToInt(key));
    cursor.close();
    readerTxn.commit();

    closeEnv();
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:52,代碼來源:PhantomTest.java

示例6: testGetSearchKeyRange_NotFound_Dup

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testGetSearchKeyRange_NotFound_Dup()
    throws DatabaseException, InterruptedException {

    openEnv(true);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    OperationStatus status;

    /* Insert dups. */
    insert(1, 1);
    insert(1, 2);

    /* getSearchKeyRange for key 2 returns NOTFOUND. */
    Transaction readerTxn = env.beginTransaction(null, txnConfig);
    Cursor cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.NOTFOUND, status);

    /* Insert {3,1} in a writer thread. */
    startInsert(3, 1);

    /*
     * If serializable, getSearchKeyRange should return NOTFOUND again;
     * otherwise getSearchKeyRange should see {3,1}.
     */
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    if (txnSerializable) {
        assertEquals(OperationStatus.NOTFOUND, status);
    } else {
        assertEquals(OperationStatus.SUCCESS, status);
        assertEquals(3, IntegerBinding.entryToInt(key));
        assertEquals(1, IntegerBinding.entryToInt(data));
    }

    /* Close reader to allow writer to finish. */
    cursor.close();
    readerTxn.commitNoSync();
    waitForInsert();

    /* getSearchKeyRange returns {3,1}. */
    readerTxn = env.beginTransaction(null, txnConfig);
    cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(3, IntegerBinding.entryToInt(key));
    assertEquals(1, IntegerBinding.entryToInt(data));
    cursor.close();
    readerTxn.commit();

    closeEnv();
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:55,代碼來源:PhantomTest.java

示例7: openAndInit

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
  * Opens the environment and db and writes 2 records (3 if dups are used).
  *
  * <p>Without dups: {0,0}, {1,0}. This gives two LNs in the main tree.</p>
  *
  * <p>With dups: {0,0}, {0,1}, {1,0}. This gives one LN in the main tree,
  * and a dup tree with two LNs.</p>
  */
 private void openAndInit(boolean transactional, boolean dups)
     throws DatabaseException {

     openEnv(transactional, dups, null);

     /*
      * We need at least 2 BINs, otherwise empty BINs won't be deleted.  So
      * we add keys until the BIN splits, then delete everything in the
      * first BIN except the first two keys.  Those are the keys we'll use
      * for testing, and are key values 0 and 1.
      */
     BIN firstBin = null;
     OperationStatus status;
     for (int i = 0;; i += 1) {
         DatabaseEntry key = new DatabaseEntry(new byte[] { (byte) i });
         status = db.put(null, key, entry0);
         assertEquals(OperationStatus.SUCCESS, status);
         Cursor cursor = db.openCursor(null, null);
         status = cursor.getLast(keyFound, dataFound, null);
         assertEquals(OperationStatus.SUCCESS, status);
         BIN b = DbInternal.getCursorImpl(cursor).getBIN();
         cursor.close();
         if (firstBin == null) {
             firstBin = b;
         } else if (firstBin != b) {
             /* Now delete all but the first two keys in the first BIN. */
             while (firstBin.getNEntries() > 2) {
                 cursor = db.openCursor(null, null);
                 keyFound.setData(entry2.getData());
                 status =
cursor.getSearchKeyRange(keyFound, dataFound, null);
                 assertEquals(OperationStatus.SUCCESS, status);
                 cursor.close();
                 status = db.delete(null, keyFound);
                 assertEquals(OperationStatus.SUCCESS, status);
                 env.compress();
             }
             break;
         }
     }

     /* Write dup records. */
     if (dups) {
         status = db.put(null, entry0, entry1);
         assertEquals(OperationStatus.SUCCESS, status);
     }

     /* Set in, bin, dbin. */
     initInternalNodes();
     assertSame(bin, firstBin);

     /* Check that all tree nodes are populated. */
     assertEquals(2, in.getNEntries());
     checkBinEntriesAndCursors(bin, 2, 0);
     if (dups) {
         checkBinEntriesAndCursors(dbin, 2, 0);
     } else {
         assertNull(dbin);
     }
 }
 
開發者ID:nologic,項目名稱:nabs,代碼行數:69,代碼來源:INCompressorTest.java

示例8: testGetSearchKeyRange_Success

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testGetSearchKeyRange_Success()
    throws DatabaseException, InterruptedException {

    openEnv(false);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    OperationStatus status;

    /* Insert key 1 and 3. */
    insert(1);
    insert(3);

    /* getSearchKeyRange for key 2 returns key 3. */
    Transaction readerTxn = env.beginTransaction(null, txnConfig);
    Cursor cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(3, IntegerBinding.entryToInt(key));

    /* Insert key 2 in a writer thread. */
    startInsert(2);
    
    /*
     * If serializable, getSearchKeyRange should return key 3 again;
     * otherwise getSearchKeyRange should see key 2.
     */
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    if (txnSerializable) {
        assertEquals(3, IntegerBinding.entryToInt(key));
    } else {
        assertEquals(2, IntegerBinding.entryToInt(key));
    }

    /* Close reader to allow writer to finish. */
    cursor.close();
    readerTxn.commitNoSync();
    waitForInsert();

    /* getSearchKeyRange returns key 2. */
    readerTxn = env.beginTransaction(null, txnConfig);
    cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(2, IntegerBinding.entryToInt(key));
    cursor.close();
    readerTxn.commit();

    closeEnv();
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:54,代碼來源:PhantomTest.java

示例9: testGetSearchKeyRange_Success_Dup

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testGetSearchKeyRange_Success_Dup()
    throws DatabaseException, InterruptedException {

    openEnv(true);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    OperationStatus status;

    /* Insert dups. */
    insert(1, 1);
    insert(1, 2);
    insert(3, 2);
    insert(3, 3);

    /* getSearchKeyRange for key 2 returns {3,2}. */
    Transaction readerTxn = env.beginTransaction(null, txnConfig);
    Cursor cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(3, IntegerBinding.entryToInt(key));
    assertEquals(2, IntegerBinding.entryToInt(data));
    assertEquals(OperationStatus.SUCCESS, status);

    /* Insert {3,1} in a writer thread. */
    startInsert(3, 1);
    
    /*
     * If serializable, getSearchKeyRange should return {3,2} again;
     * otherwise getSearchKeyRange should see {3,1}.
     */
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    if (txnSerializable) {
        assertEquals(3, IntegerBinding.entryToInt(key));
        assertEquals(2, IntegerBinding.entryToInt(data));
    } else {
        assertEquals(3, IntegerBinding.entryToInt(key));
        assertEquals(1, IntegerBinding.entryToInt(data));
    }

    /* Close reader to allow writer to finish. */
    cursor.close();
    readerTxn.commitNoSync();
    waitForInsert();

    /* getSearchKeyRange returns {3,1}. */
    readerTxn = env.beginTransaction(null, txnConfig);
    cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(3, IntegerBinding.entryToInt(key));
    assertEquals(1, IntegerBinding.entryToInt(data));
    cursor.close();
    readerTxn.commit();

    closeEnv();
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:60,代碼來源:PhantomTest.java

示例10: testGetSearchKeyRange_NotFound

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testGetSearchKeyRange_NotFound()
    throws DatabaseException, InterruptedException {

    openEnv(false);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    OperationStatus status;

    /* Insert key 1. */
    insert(1);

    /* getSearchKeyRange for key 2 returns NOTFOUND. */
    Transaction readerTxn = env.beginTransaction(null, txnConfig);
    Cursor cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.NOTFOUND, status);

    /* Insert key 3 in a writer thread. */
    startInsert(3);
    
    /*
     * If serializable, getSearchKeyRange should return NOTFOUND again;
     * otherwise getSearchKeyRange should see key 3.
     */
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    if (txnSerializable) {
        assertEquals(OperationStatus.NOTFOUND, status);
    } else {
        assertEquals(OperationStatus.SUCCESS, status);
        assertEquals(3, IntegerBinding.entryToInt(key));
    }

    /* Close reader to allow writer to finish. */
    cursor.close();
    readerTxn.commitNoSync();
    waitForInsert();

    /* getSearchKeyRange returns key 3. */
    readerTxn = env.beginTransaction(null, txnConfig);
    cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(3, IntegerBinding.entryToInt(key));
    cursor.close();
    readerTxn.commit();

    closeEnv();
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:52,代碼來源:PhantomTest.java

示例11: testGetSearchKeyRange_NotFound_Dup

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testGetSearchKeyRange_NotFound_Dup()
    throws DatabaseException, InterruptedException {

    openEnv(true);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    OperationStatus status;

    /* Insert dups. */
    insert(1, 1);
    insert(1, 2);

    /* getSearchKeyRange for key 2 returns NOTFOUND. */
    Transaction readerTxn = env.beginTransaction(null, txnConfig);
    Cursor cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.NOTFOUND, status);

    /* Insert {3,1} in a writer thread. */
    startInsert(3, 1);
    
    /*
     * If serializable, getSearchKeyRange should return NOTFOUND again;
     * otherwise getSearchKeyRange should see {3,1}.
     */
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    if (txnSerializable) {
        assertEquals(OperationStatus.NOTFOUND, status);
    } else {
        assertEquals(OperationStatus.SUCCESS, status);
        assertEquals(3, IntegerBinding.entryToInt(key));
        assertEquals(1, IntegerBinding.entryToInt(data));
    }

    /* Close reader to allow writer to finish. */
    cursor.close();
    readerTxn.commitNoSync();
    waitForInsert();

    /* getSearchKeyRange returns {3,1}. */
    readerTxn = env.beginTransaction(null, txnConfig);
    cursor = db.openCursor(readerTxn, null);
    IntegerBinding.intToEntry(2, key);
    status = cursor.getSearchKeyRange(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(3, IntegerBinding.entryToInt(key));
    assertEquals(1, IntegerBinding.entryToInt(data));
    cursor.close();
    readerTxn.commit();

    closeEnv();
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:55,代碼來源:PhantomTest.java

示例12: evolveIndex

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
private void evolveIndex(Format format,
                         EvolveEvent event,
                         EvolveListener listener)
    throws DatabaseException {

    /* We may make this configurable later. */
    final int WRITES_PER_TXN = 1;

    Class entityClass = format.getType();
    String entityClassName = format.getClassName();
    EntityMetadata meta = model.getEntityMetadata(entityClassName);
    String keyClassName = meta.getPrimaryKey().getClassName();
    keyClassName = SimpleCatalog.keyClassName(keyClassName);
    DatabaseConfig dbConfig = getPrimaryConfig(meta);

    PrimaryIndex<Object, Object> index = getPrimaryIndex
        (Object.class, keyClassName, entityClass, entityClassName);
    Database db = index.getDatabase();

    EntityBinding binding = index.getEntityBinding();
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();

    CursorConfig cursorConfig = null;
    Transaction txn = null;
    if (dbConfig.getTransactional()) {
        txn = env.beginTransaction(null, autoCommitTxnConfig);
        cursorConfig = CursorConfig.READ_COMMITTED;
    }

    Cursor cursor = null;
    int nWritten = 0;
    try {
        cursor = db.openCursor(txn, cursorConfig);
        OperationStatus status = cursor.getFirst(key, data, null);
        while (status == OperationStatus.SUCCESS) {
            boolean oneWritten = false;
            if (evolveNeeded(key, data, binding)) {
                cursor.putCurrent(data);
                oneWritten = true;
                nWritten += 1;
            }
            /* Update event stats, even if no listener. [#17024] */
            EvolveInternal.updateEvent
                (event, entityClassName, 1, oneWritten ? 1 : 0);
            if (listener != null) {
                if (!listener.evolveProgress(event)) {
                    break;
                }
            }
            if (txn != null && nWritten >= WRITES_PER_TXN) {
                cursor.close();
                cursor = null;
                txn.commit();
                txn = null;
                txn = env.beginTransaction(null, autoCommitTxnConfig);
                cursor = db.openCursor(txn, cursorConfig);
                DatabaseEntry saveKey = KeyRange.copy(key);
                status = cursor.getSearchKeyRange(key, data, null);
                if (status == OperationStatus.SUCCESS &&
                    KeyRange.equalBytes(key, saveKey)) {
                    status = cursor.getNext(key, data, null);
                }
            } else {
                status = cursor.getNext(key, data, null);
            }
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
        if (txn != null) {
            if (nWritten > 0) {
                txn.commit();
            } else {
                txn.abort();
            }
        }
    }
}
 
開發者ID:prat0318,項目名稱:dbms,代碼行數:81,代碼來源:Store.java

示例13: count

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
 * For future use as API method.  Implementation is incomplete.
 *
 * Counts entries in a key range by positioning a cursor on the beginning
 * key and skipping entries until the ending key is encountered.
 */
private long count(DatabaseEntry beginKey,
                   boolean beginInclusive,
                   DatabaseEntry endKey,
                   boolean endInclusive) {

    final DatabaseEntry key = new DatabaseEntry();
    final DatabaseEntry noData = new DatabaseEntry();
    noData.setPartial(0, 0, true);
    final Locker locker = BasicLocker.createBasicLocker(envImpl);
    try {
        final Cursor c = DbInternal.makeCursor(this, locker,
                                               null /*cursorConfig*/);
        try {
            /* Position cursor on beginning key. */
            if (beginKey != null) {
                key.setData(beginKey.getData(), beginKey.getOffset(),
                            beginKey.getSize());
                if (c.getSearchKeyRange(key, noData,
                                        LockMode.READ_UNCOMMITTED) !=
                    OperationStatus.SUCCESS) {
                    return 0;
                }
                if (!beginInclusive && key.equals(beginKey)) {
                    if (c.getNext(key, noData,
                                  LockMode.READ_UNCOMMITTED) !=
                        OperationStatus.SUCCESS) {
                        return 0;
                    }
                }
            } else {
                if (c.getFirst(key, noData, LockMode.READ_UNCOMMITTED) !=
                    OperationStatus.SUCCESS) {
                    return 0;
                }
            }

            /* Create RangeConstraint for ending key. */
            RangeConstraint rangeConstraint = null; // INCOMPLETE

            /* Skip entries to get count. */
            return DbInternal.getCursorImpl(c).skip
                (true /*forward*/, 0 /*maxCount*/, rangeConstraint);
        } finally {
            c.close();
        }
    } finally {
        locker.operationEnd(true);
    }
}
 
開發者ID:prat0318,項目名稱:dbms,代碼行數:56,代碼來源:DatabaseImpl.java


注:本文中的com.sleepycat.je.Cursor.getSearchKeyRange方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。