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


Java Cursor.getLast方法代碼示例

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


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

示例1: getTotalCount

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
 * 獲取總數
 * @param dbName
 * @return
 * @throws Exception
 */
public int getTotalCount(String dbName) throws Exception {
    int count = 0;
    Cursor cursor = null;
    try {
        Database db = this.getDb(dbName);
        cursor = db.openCursor(null, null);
        DatabaseEntry foundKey = new DatabaseEntry();
        DatabaseEntry foundData = new DatabaseEntry();
        if (cursor.getLast(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
            count = cursor.count();
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return count;
}
 
開發者ID:tiglabs,項目名稱:jsf-core,代碼行數:25,代碼來源:BerkeleyDb.java

示例2: findLast

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
 * <p>
 * Find the last entry, assuming ordered duplicates, corresponding to the
 * given key.
 * </p>
 * 
 * @param key
 *            The key whose last entry is sought.
 * @return The last (i.e. greatest, i.e. maximum) data value for that key or
 *         null if the set of entries for the key is empty.
 */
public ValueType findLast(KeyType key)
{
	checkOpen();
	DatabaseEntry keyEntry = new DatabaseEntry(keyConverter.toByteArray(key));
	DatabaseEntry value = new DatabaseEntry();
	ValueType result = null;
	Cursor cursor = null;
	try
	{
		cursor = db.openCursor(txn().getBJETransaction(), cursorConfig);
		OperationStatus status = cursor.getLast(keyEntry, value, LockMode.DEFAULT);
		if (status == OperationStatus.SUCCESS)
			result = valueConverter.fromByteArray(value.getData(), value.getOffset(), value.getSize());
	}
	catch (Exception ex)
	{
		throw new HGException("Failed to lookup index '" + name + "': " + ex.toString(), ex);
	}
	finally
	{
		if (cursor != null)
		{
			try
			{
				cursor.close();
			}
			catch (Throwable t)
			{
			}
		}
	}
	return result;
}
 
開發者ID:hypergraphdb,項目名稱:hypergraphdb,代碼行數:45,代碼來源:DefaultIndexImpl.java

示例3: 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

示例4: testGetLast_Success

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

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

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

    /* getLast returns key 1. */
    Transaction readerTxn = env.beginTransaction(null, txnConfig);
    Cursor cursor = db.openCursor(readerTxn, null);
    status = cursor.getLast(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(1, IntegerBinding.entryToInt(key));

    /* Insertions before current position are never blocked. */
    try {
        insert(0);
    } catch (DeadlockException e) {
        fail();
    }

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

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

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

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

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

示例5: testGetLast_Success_Dup

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

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

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

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

    /* Insertions before current position are never blocked. */
    try {
        insert(1, 1);
    } catch (DeadlockException e) {
        fail();
    }

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

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

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

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

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

示例6: testGetLast_NotFound

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

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

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

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

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

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

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

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

示例7: testGetLast_NotFound_Dup

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

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

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

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

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

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

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

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

示例8: 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

示例9: testGetLast_Success

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

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

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

    /* getLast returns key 1. */
    Transaction readerTxn = env.beginTransaction(null, txnConfig);
    Cursor cursor = db.openCursor(readerTxn, null);
    status = cursor.getLast(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(1, IntegerBinding.entryToInt(key));

    /* Insertions before current position are never blocked. */
    try {
        insert(0);
    } catch (DeadlockException e) {
        fail();
    }

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

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

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

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

示例10: testGetLast_Success_Dup

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

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

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

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

    /* Insertions before current position are never blocked. */
    try {
        insert(1, 1);
    } catch (DeadlockException e) {
        fail();
    }

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

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

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

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

示例11: testGetLast_NotFound

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

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

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

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

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

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

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

示例12: testGetLast_NotFound_Dup

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

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

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

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

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

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

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


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