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


Java Cursor.getSearchBoth方法代碼示例

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


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

示例1: delBoth

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
private void delBoth(int key, int data)
throws DatabaseException {

byte[] keyBytes = new byte[1];
keyBytes[0] = (byte) (key & 0xff);
DatabaseEntry keyDbt = new DatabaseEntry(keyBytes);

byte[] dataBytes = new byte[1];
dataBytes[0] = (byte) (data & 0xff);
DatabaseEntry dataDbt = new DatabaseEntry(dataBytes);

Cursor cursor = exampleDb.openCursor(null, null);
OperationStatus status =
    cursor.getSearchBoth(keyDbt, dataDbt, LockMode.DEFAULT);
if (status != OperationStatus.SUCCESS) {
    System.out.println("getSearchBoth returned " + status +
		       " for key " + key + "/" + data);
}

status = cursor.delete();
if (status != OperationStatus.SUCCESS) {
    System.out.println("Dbc.delete returned " + status +
		       " for key " + key + "/" + data);
}
cursor.close();
   }
 
開發者ID:nologic,項目名稱:nabs,代碼行數:27,代碼來源:DbCursorDuplicateDeleteTest.java

示例2: removeEntry

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void removeEntry(KeyType key, ValueType value)
{
	checkOpen();
	DatabaseEntry keyEntry = new DatabaseEntry(keyConverter.toByteArray(key));
	DatabaseEntry valueEntry = new DatabaseEntry(valueConverter.toByteArray(value));
	Cursor cursor = null;

	try
	{
		cursor = db.openCursor(txn().getBJETransaction(), cursorConfig);
		if (cursor.getSearchBoth(keyEntry, valueEntry, LockMode.DEFAULT) == OperationStatus.SUCCESS)
			cursor.delete();
	}
	catch (Exception ex)
	{
		throw new HGException("Failed to lookup index '" + name + "': " + ex.toString(), ex);
	}
	finally
	{
		if (cursor != null)
		{
			try
			{
				cursor.close();
			}
			catch (Throwable t)
			{
			}
		}
	}
}
 
開發者ID:hypergraphdb,項目名稱:hypergraphdb,代碼行數:32,代碼來源:DefaultIndexImpl.java

示例3: deleteData

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
 * Deletes the specified keys.
 */
private void deleteData(int firstKey, int keyCount)
    throws DatabaseException {

    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();

    Transaction txn = env.beginTransaction(null, null);
    Cursor cursor = db.openCursor(txn, null);

    for (int i = 0; i < keyCount; i += 1) {
        int nextKey = firstKey + i;
        OperationStatus status;
        if (dups) {
            key.setData(MAIN_KEY_FOR_DUPS);
            data.setData(TestUtils.getTestArray(nextKey));
            status = cursor.getSearchBoth(key, data, null);
        } else {
            key.setData(TestUtils.getTestArray(nextKey));
            status = cursor.getSearchKey(key, data, null);
        }
        assertEquals(OperationStatus.SUCCESS, status);
        status = cursor.delete();
        assertEquals(OperationStatus.SUCCESS, status);
        existingKeys.remove(new Integer(nextKey));
    }

    cursor.close();
    txn.commit();
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:33,代碼來源:FileSelectionTest.java

示例4: updateData

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
 * Updates the specified keys.
 */
private void updateData(int firstKey, int keyCount)
    throws DatabaseException {

    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();

    Transaction txn = env.beginTransaction(null, null);
    Cursor cursor = db.openCursor(txn, null);

    for (int i = 0; i < keyCount; i += 1) {
        int nextKey = firstKey + i;
        OperationStatus status;
        if (dups) {
            key.setData(MAIN_KEY_FOR_DUPS);
            data.setData(TestUtils.getTestArray(nextKey));
            status = cursor.getSearchBoth(key, data, null);
            assertEquals(OperationStatus.SUCCESS, status);
            assertEquals(MAIN_KEY_FOR_DUPS.length, key.getSize());
            assertEquals(nextKey, TestUtils.getTestVal(data.getData()));
        } else {
            key.setData(TestUtils.getTestArray(nextKey));
            status = cursor.getSearchKey(key, data, null);
            assertEquals(OperationStatus.SUCCESS, status);
            assertEquals(nextKey, TestUtils.getTestVal(key.getData()));
            assertEquals(DATA_SIZE, data.getSize());
        }
        status = cursor.putCurrent(data);
        assertEquals(OperationStatus.SUCCESS, status);
    }

    cursor.close();
    txn.commit();
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:37,代碼來源:FileSelectionTest.java

示例5: verifyData

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
 * Verifies that the data written by writeData can be read.
 */
private void verifyData()
    throws DatabaseException {

    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();

    Transaction txn = env.beginTransaction(null, null);
    Cursor cursor = db.openCursor(txn, null);

    for (Iterator i = existingKeys.iterator(); i.hasNext();) {
        int nextKey = ((Integer) i.next()).intValue();
        OperationStatus status;
        if (dups) {
            key.setData(MAIN_KEY_FOR_DUPS);
            data.setData(TestUtils.getTestArray(nextKey));
            status = cursor.getSearchBoth(key, data, null);
            assertEquals(OperationStatus.SUCCESS, status);
            assertEquals(MAIN_KEY_FOR_DUPS.length, key.getSize());
            assertEquals(nextKey, TestUtils.getTestVal(data.getData()));
        } else {
            key.setData(TestUtils.getTestArray(nextKey));
            status = cursor.getSearchKey(key, data, null);
            assertEquals(OperationStatus.SUCCESS, status);
            assertEquals(nextKey, TestUtils.getTestVal(key.getData()));
            assertEquals(DATA_SIZE, data.getSize());
        }
    }

    cursor.close();
    txn.commit();
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:35,代碼來源:FileSelectionTest.java

示例6: searchBoth

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
 * Performs getSearchBoth on the given key and data.
 */
private OperationStatus searchBoth(Cursor cursor, int keyVal, int dataVal)
    throws DatabaseException {

    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    IntegerBinding.intToEntry(keyVal, key);
    IntegerBinding.intToEntry(dataVal, data);
    OperationStatus status = cursor.getSearchBoth(key, data, null);
    if (status == OperationStatus.SUCCESS) {
        assertEquals(keyVal, IntegerBinding.entryToInt(key));
        assertEquals(dataVal, IntegerBinding.entryToInt(data));
    }
    return status;
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:18,代碼來源:PhantomTest.java

示例7: getDiffArea

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
private static HashSet<Record> getDiffArea(Cursor cursor,
                                           byte[] beginKey,
                                           byte[] beginData,
                                           long diffSize) 
    throws Exception {

    HashSet<Record> records = new HashSet<Record>();
    LogManager logManager = DbInternal.getEnvironmentImpl
        (cursor.getDatabase().getEnvironment()).getLogManager();

    DatabaseEntry key = new DatabaseEntry(beginKey);
    DatabaseEntry data = new DatabaseEntry(beginData);
    boolean scanToEnd = (diffSize == DATABASE_END ? true : false);
    long count = 1;

    for (OperationStatus status = 
         cursor.getSearchBoth(key, data, LockMode.DEFAULT); 
         status == OperationStatus.SUCCESS;
         status = cursor.getNext(key, data, LockMode.DEFAULT)) {

        if (!scanToEnd && count > diffSize) {
            break;
        }
        records.add(new Record(key.getData(), data.getData(),
                               getVLSN(cursor, logManager)));
        count++;
    }

    return records;
}
 
開發者ID:prat0318,項目名稱:dbms,代碼行數:31,代碼來源:DiffRecordAnalyzer.java

示例8: testRetry

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
 * Test retries after cleaning fails because an LN was write-locked.
 */
public void testRetry()
    throws DatabaseException {

    openEnv(highUtilizationConfig);
    writeData();
    verifyData();

    /*
     * The first file is full of LNs.  Delete all but the last record to
     * cause it to be selected next for cleaning.
     */
    int firstKey = ((Integer) firstKeysInFiles.get(1)).intValue();
    int nextKey = ((Integer) firstKeysInFiles.get(2)).intValue();
    int count = nextKey - firstKey - 1;
    deleteData(firstKey, count);
    verifyData();

    /* Write-lock the last record to cause cleaning to fail. */
    Transaction txn = env.beginTransaction(null, null);
    Cursor cursor = db.openCursor(txn, null);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    OperationStatus status;
    if (dups) {
        key.setData(MAIN_KEY_FOR_DUPS);
        data.setData(TestUtils.getTestArray(nextKey - 1));
        status = cursor.getSearchBoth(key, data, LockMode.RMW);
    } else {
        key.setData(TestUtils.getTestArray(nextKey - 1));
        status = cursor.getSearchKey(key, data, LockMode.RMW);
    }
    assertEquals(OperationStatus.SUCCESS, status);
    status = cursor.delete();
    assertEquals(OperationStatus.SUCCESS, status);


    /* Cleaning should fail. */
    forceCleanOne();
    verifyDeletedFiles(null);
    forceCleanOne();
    verifyDeletedFiles(null);

    /* Release the write-lock. */
    cursor.close();
    txn.abort();
    verifyData();

    /* Cleaning should succeed, with all files deleted. */
    forceCleanOne();
    verifyDeletedFiles(new int[] {0, 1, 2});
    verifyData();

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


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