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


Java Cursor類代碼示例

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


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

示例1: testReadLocks

import com.sleepycat.je.Cursor; //導入依賴的package包/類
/** 
 * Insert and then scan some records. Measure memory usage at different
 * points in this sequence, asserting that the memory usage count is
 * properly decremented.
 */
public void testReadLocks()
    throws DatabaseException {

    loadData();

    /* 
     * Now scan the database. Make sure all locking overhead is
     * released.
     */
    for (int t = 0; t < numTxns; t++) {
        Cursor c = db.openCursor(txns[t], null);
        while (c.getNext(keyEntry, dataEntry, null) == 
               OperationStatus.SUCCESS) {
        }
        c.close();
    }
    afterAction = mb.getCacheMemoryUsage();

    closeTxns(false);
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:26,代碼來源:TxnMemoryTest.java

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

示例3: copyLiveObjects

import com.sleepycat.je.Cursor; //導入依賴的package包/類
public void copyLiveObjects(final long deadTime, final Generation next, final List<Long> deletes) {
  s_logger.debug("Copying objects from {} to {}", this, next);
  final DatabaseEntry identifier = new DatabaseEntry();
  final DatabaseEntry target = new DatabaseEntry();
  final DatabaseEntry accessed = new DatabaseEntry();
  final Cursor cursor = _id2LastAccessed.openCursor(null, null);
  int count = 0;
  while (cursor.getNext(identifier, accessed, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
    final long lastAccess = LongBinding.entryToLong(accessed);
    if (lastAccess - deadTime > 0) {
      if (_id2Target.get(null, identifier, target, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
        next._id2Target.put(null, identifier, target);
        next._target2Id.put(null, target, identifier);
        next._id2LastAccessed.put(null, identifier, accessed);
        count++;
      } else {
        deletes.add(LongBinding.entryToLong(identifier));
      }
    } else {
      deletes.add(LongBinding.entryToLong(identifier));
    }
  }
  cursor.close();
  s_logger.info("Copied {} objects from {} to {}", new Object[] {count, this, next });
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:26,代碼來源:BerkeleyDBTempTargetRepository.java

示例4: readData

import com.sleepycat.je.Cursor; //導入依賴的package包/類
public void readData(int limit)
{
    Cursor cursor = scaffoldDatabase.openCursor(null, null);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    int i = 0;
    while(cursor.getNext(key, data, LockMode.DEFAULT) == OperationStatus.SUCCESS)
    {
        if(i >= limit)
            break;
        String keyString = new String(key.getData());
        System.out.println("hash: " + keyString);
        i++;
    }
    cursor.close();
}
 
開發者ID:ashish-gehani,項目名稱:SPADE,代碼行數:17,代碼來源:Scaffold.java

示例5: getGroundhogStatistics

import com.sleepycat.je.Cursor; //導入依賴的package包/類
public GroundhogStatistics getGroundhogStatistics() {
  GroundhogStatistics wholeGroundhogStatistics = new GroundhogStatistics();

  try {
    Cursor myCursor = conceptToConceptVectorIndexStore.openCursor(null, null);
    DatabaseEntry foundKey = new DatabaseEntry();
    DatabaseEntry foundData = new DatabaseEntry();
    while (myCursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
      ConceptToConceptVectorRecordIndexEntry entry = (ConceptToConceptVectorRecordIndexEntry) myDataBinding.entryToObject(foundData);
      Integer key = (Integer) myIntegerBinding.entryToObject(foundKey);
      ConceptStatistic conceptStatistic = new ConceptStatistic();
      conceptStatistic.docFrequency = entry.conceptVectorRecordIDs.size();
      conceptStatistic.termFrequency = Math.round(entry.sumOfValuesInRecords);
      // RvS: fix compile error by rounding off float to int

      wholeGroundhogStatistics.conceptStatistics.put(key, conceptStatistic);
      wholeGroundhogStatistics.allConceptOccurrences += entry.sumOfValuesInRecords;
    }
    myCursor.close();
  } catch (DatabaseException e) {
    e.printStackTrace();
  }

  return wholeGroundhogStatistics;
}
 
開發者ID:BiosemanticsDotOrg,項目名稱:GeneDiseasePaper,代碼行數:26,代碼來源:ConceptToRecordIndex.java

示例6: getGroundhogStatistics

import com.sleepycat.je.Cursor; //導入依賴的package包/類
public GroundhogStatistics getGroundhogStatistics() {
  GroundhogStatistics wholeGroundhogStatistics = new GroundhogStatistics();

  try {
    Cursor myCursor = conceptToConceptVectorIndexStore.openCursor(null, null);
    DatabaseEntry foundKey = new DatabaseEntry();
    DatabaseEntry foundData = new DatabaseEntry();
    while (myCursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
      ConceptToConceptVectorRecordIndexEntry entry = (ConceptToConceptVectorRecordIndexEntry) myDataBinding.entryToObject(foundData);
      Integer key = (Integer) myIntegerBinding.entryToObject(foundKey);
      ConceptStatistic conceptStatistic = new ConceptStatistic();
      conceptStatistic.docFrequency = entry.conceptVectorRecordIDs.size();
      conceptStatistic.termFrequency = entry.sumOfValuesInRecords.intValue();

      wholeGroundhogStatistics.conceptStatistics.put(key, conceptStatistic);
      wholeGroundhogStatistics.allConceptOccurrences += entry.sumOfValuesInRecords;
    }
    myCursor.close();
  } catch (DatabaseException e) {
    e.printStackTrace();
  }

  return wholeGroundhogStatistics;
}
 
開發者ID:BiosemanticsDotOrg,項目名稱:GeneDiseasePaper,代碼行數:25,代碼來源:ConceptToRecordIndex.java

示例7: privateLoadAllKeys

import com.sleepycat.je.Cursor; //導入依賴的package包/類
private Set privateLoadAllKeys() {
    Set keys = new java.util.HashSet((int) _db.count());
    Cursor cursor = null;
    try {
        cursor = _db.openCursor(null, null);
        DatabaseEntry foundKey = new DatabaseEntry();
        DatabaseEntry foundData = new DatabaseEntry();

        while (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
            keys.add((K) entryToObject(foundKey));
        }
    } catch (Exception e) {
        _logger.log(Level.SEVERE, e.getMessage(), e);
    } finally {
        cursor.close();
    }

    _logger.log(Level.INFO, this.getClass().getCanonicalName() + ":" + _mapName + ":loadAllKeys:" + keys.size());

    return keys;
}
 
開發者ID:hypergraphdb,項目名稱:hypergraphdb,代碼行數:22,代碼來源:BerkeleyDBStore.java

示例8: printEvents

import com.sleepycat.je.Cursor; //導入依賴的package包/類
/**
 * Print all events covered by this cursor up to the end date.  We know
 * that the cursor operates on long keys and Event data items, but there's
 * no type-safe way of expressing that within the JE base api.
 */
private void printEvents(DatabaseEntry firstKey,
                         DatabaseEntry firstData,
                         Cursor cursor, 
                         long endDate) 
    throws DatabaseException {
    
    System.out.println("time=" +
                       new Date(LongBinding.entryToLong(firstKey)) +
                       eventBinding.entryToObject(firstData));
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();

    while (cursor.getNext(key, data, null) ==
           OperationStatus.SUCCESS) {
        if (LongBinding.entryToLong(key) > endDate) {
            break;
        }
        System.out.println("time=" +
                           new Date(LongBinding.entryToLong(key)) +
                           eventBinding.entryToObject(data));
    }
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:28,代碼來源:EventExample.java

示例9: DataCursor

import com.sleepycat.je.Cursor; //導入依賴的package包/類
/**
 * Creates a join cursor.
 */
DataCursor(DataView view, DataCursor[] indexCursors,
           JoinConfig joinConfig, boolean closeIndexCursors)
    throws DatabaseException {

    if (view.isSecondary()) {
        throw new IllegalArgumentException(
            "The primary collection in a join must not be a secondary " +
            "database");
    }
    Cursor[] cursors = new Cursor[indexCursors.length];
    for (int i = 0; i < cursors.length; i += 1) {
        cursors[i] = indexCursors[i].cursor.getCursor();
    }
    joinCursor = view.db.join(cursors, joinConfig);
    init(view, false, null, null);
    if (closeIndexCursors) {
        indexCursorsToClose = indexCursors;
    }
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:23,代碼來源:DataCursor.java

示例10: closeCursor

import com.sleepycat.je.Cursor; //導入依賴的package包/類
/**
 * Closes a cursor.
 *
 * @param cursor the cursor to close.
 *
 * @throws DatabaseException if a database problem occurs.
 */
void closeCursor(Cursor cursor)
    throws DatabaseException {

    if (cursor == null) {
        return;
    }
    if (cdbMode) {
        WeakHashMap cdbCursorsMap = (WeakHashMap) localCdbCursors.get();
        if (cdbCursorsMap != null) {
            Database db = cursor.getDatabase();
            CdbCursors cdbCursors = (CdbCursors) cdbCursorsMap.get(db);
            if (cdbCursors != null) {
                if (cdbCursors.readCursors.remove(cursor) ||
                    cdbCursors.writeCursors.remove(cursor)) {
                    cursor.close();
                    return;
                }
            }
        }
        throw new IllegalStateException(
          "closing CDB cursor that was not known to be open");
    } else {
        cursor.close();
    }
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:33,代碼來源:CurrentTransaction.java

示例11: checkFirstRecord

import com.sleepycat.je.Cursor; //導入依賴的package包/類
/** 
 * First and only record in db1 should be {3,0}.
 */
private void checkFirstRecord()
    throws DatabaseException {

    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setAllowCreate(false);
    dbConfig.setReadOnly(true);
    dbConfig.setSortedDuplicates(true);
    Database db = env.openDatabase(null, "db1", dbConfig);
    Cursor cursor = db.openCursor(null, null);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    OperationStatus status = cursor.getFirst(key, data, null);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(3, value(key));
    assertEquals(0, value(data));
    cursor.close();
    db.close();
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:22,代碼來源:SR11297Test.java

示例12: dupCursor

import com.sleepycat.je.Cursor; //導入依賴的package包/類
/**
 * Duplicates a cursor for a given database.
 *
 * @param writeCursor true to open a write cursor in a CDB environment, and
 * ignored for other environments.
 *
 * @param samePosition is passed through to Cursor.dup().
 *
 * @return the open cursor.
 *
 * @throws DatabaseException if a database problem occurs.
 */
Cursor dupCursor(Cursor cursor, boolean writeCursor, boolean samePosition)
    throws DatabaseException {

    if (cdbMode) {
        WeakHashMap cdbCursorsMap = (WeakHashMap) localCdbCursors.get();
        if (cdbCursorsMap != null) {
            Database db = cursor.getDatabase();
            CdbCursors cdbCursors = (CdbCursors) cdbCursorsMap.get(db);
            if (cdbCursors != null) {
                List cursors = writeCursor ? cdbCursors.writeCursors
                                           : cdbCursors.readCursors;
                if (cursors.contains(cursor)) {
                    Cursor newCursor = cursor.dup(samePosition);
                    cursors.add(newCursor);
                    return newCursor;
                }
            }
        }
        throw new IllegalStateException("Cursor to dup not tracked");
    } else {
        return cursor.dup(samePosition);
    }
}
 
開發者ID:prat0318,項目名稱:dbms,代碼行數:36,代碼來源:CurrentTransaction.java

示例13: sendDiffArea

import com.sleepycat.je.Cursor; //導入依賴的package包/類
private void sendDiffArea(Cursor cursor, 
                          RemoteDiffRequest request, 
                          Protocol protocol)
    throws IOException {

    /* Get the records in the different area. */
    HashSet<Record> records = null;
    try {
        records = DiffRecordAnalyzer.getDiffArea(cursor, request);
    } catch (Exception e) {
        protocol.write(protocol.new Error(e.getMessage()), channel);
        throw new LDiffRecordRequestException(e.getMessage());
    }

    /* Write them out to the requested machine. */
    protocol.write(protocol.new DiffAreaStart(), channel);
    for (Record record: records) {
        protocol.write(protocol.new RemoteRecord(record), channel);
    }
    protocol.write(protocol.new DiffAreaEnd(), channel);
}
 
開發者ID:prat0318,項目名稱:dbms,代碼行數:22,代碼來源:LDiffService.java

示例14: JoinForwardCursor

import com.sleepycat.je.Cursor; //導入依賴的package包/類
JoinForwardCursor(Transaction txn, CursorConfig config, boolean doKeys)
    throws DatabaseException {

    this.doKeys = doKeys;
    try {
        cursors = new Cursor[conditions.size()];
        for (int i = 0; i < cursors.length; i += 1) {
            Condition cond = conditions.get(i);
            Cursor cursor = cond.openCursor(txn, config);
            if (cursor == null) {
                /* Leave joinCursor null. */
                doClose(null);
                return;
            }
            cursors[i] = cursor;
        }
        joinCursor = primary.getDatabase().join(cursors, null);
    } catch (DatabaseException e) {
        /* doClose will throw e. */
        doClose(e);
    }
}
 
開發者ID:prat0318,項目名稱:dbms,代碼行數:23,代碼來源:EntityJoin.java

示例15: testSearchKeySkipDeletedDup

import com.sleepycat.je.Cursor; //導入依賴的package包/類
/**
 * Tests that searchKey returns SUCCESS when it must skip over a deleted
 * duplicate.  This did not work at one point and was causing warnings
 * (Cursor Not Initialized) in duplicate.conf testing.
 */
public void testSearchKeySkipDeletedDup()
    throws DatabaseException, InterruptedException {

    openEnv(true);

    /* Insert {1,1} and {1,2}. */
    insert(1, 1);
    insert(1, 2);

    /* Delete {1,1}. */
    Transaction txn = env.beginTransaction(null, txnConfig);
    Cursor cursor = db.openCursor(txn, null);
    assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 1, 1));
    OperationStatus status = cursor.delete();
    assertEquals(OperationStatus.SUCCESS, status);

    /* Search for key 1 -- should not return NOTFOUND. */
    assertEquals(OperationStatus.SUCCESS, searchKey(cursor, 1, 2));

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


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