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


Java Cursor.count方法代碼示例

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


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

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void mergeDuplicateEntries() {
  try {
    System.out.println("Starting to merge duplicate entries in the Database " + StringUtilities.now());
    Cursor myCursor = conceptToConceptVectorIndexStore.openCursor(null, null);
    DatabaseEntry searchKey = new DatabaseEntry();
    DatabaseEntry foundData = new DatabaseEntry();
    for (Integer key: indexedConceptsWithDuplicates) {
      myIntegerBinding.objectToEntry(key, searchKey);
      if (myCursor.getSearchKey(searchKey, foundData, null) == OperationStatus.SUCCESS) {
        if (myCursor.count() > 1) {
          ConceptToConceptVectorRecordIndexEntry entry = (ConceptToConceptVectorRecordIndexEntry) myDataBinding.entryToObject(foundData);
          //OperationStatus status = myCursor.delete();
          while (myCursor.getNextDup(searchKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
            ConceptToConceptVectorRecordIndexEntry addition = (ConceptToConceptVectorRecordIndexEntry) myDataBinding.entryToObject(foundData);
            entry.conceptVectorRecordIDs.addAll(addition.conceptVectorRecordIDs);
            entry.sumOfValuesInRecords += addition.sumOfValuesInRecords;
            myCursor.delete();
          }
          setEntryInStore(key, entry);
        }
      }
    }
    System.out.println("Done merging duplicate entries in the Database " + StringUtilities.now());
    myCursor.close();
  } catch (DatabaseException e) {
    e.printStackTrace();
  }
}
 
開發者ID:BiosemanticsDotOrg,項目名稱:GeneDiseasePaper,代碼行數:29,代碼來源:ConceptToRecordIndex.java

示例3: count

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public long count(KeyType key)
{
	Cursor cursor = null;
	try
	{
		cursor = db.openCursor(txn().getBJETransaction(), cursorConfig);
		DatabaseEntry keyEntry = new DatabaseEntry(keyConverter.toByteArray(key));
		DatabaseEntry value = new DatabaseEntry();
		OperationStatus status = cursor.getSearchKey(keyEntry, value, LockMode.DEFAULT);

		if (status == OperationStatus.SUCCESS)
			return cursor.count();
		else
			return 0;
	}
	catch (DatabaseException ex)
	{
		throw new HGException(ex);
	}
	finally
	{
		if (cursor != null)
		{
			try
			{
				cursor.close();
			}
			catch (Throwable t)
			{
			}
		}
	}
}
 
開發者ID:hypergraphdb,項目名稱:hypergraphdb,代碼行數:34,代碼來源:DefaultIndexImpl.java

示例4: getIncidenceSetCardinality

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public long getIncidenceSetCardinality(HGPersistentHandle handle)
{
	if (handle == null)
		throw new NullPointerException("HGStore.getIncidenceSetCardinality called with a null handle.");

	Cursor cursor = null;
	try
	{
		DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
		DatabaseEntry value = new DatabaseEntry();
		cursor = incidence_db.openCursor(txn().getBJETransaction(), cursorConfig);
		OperationStatus status = cursor.getSearchKey(key, value, LockMode.DEFAULT);
		if (status == OperationStatus.NOTFOUND)
			return 0;
		else
			return cursor.count();
	}
	catch (Exception ex)
	{
		throw new HGException("Failed to retrieve incidence set for handle " + handle + ": " + ex.toString(), ex);
	}
	finally
	{
		try
		{
			cursor.close();
		}
		catch (Throwable t)
		{
		}
	}
}
 
開發者ID:hypergraphdb,項目名稱:hypergraphdb,代碼行數:33,代碼來源:BJEStorageImplementation.java

示例5: checkData

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
    * Check what's in the database against what's in the expected map.
    */
   private void checkData(Map expectedMap)
       throws DatabaseException {

       StringDbt foundKey = new StringDbt();
       StringDbt foundData = new StringDbt();
       Cursor cursor = exampleDb.openCursor(null, null);
       OperationStatus status = cursor.getFirst(foundKey, foundData,
                                                LockMode.DEFAULT);

       /*
        * Make a copy of expectedMap so that we're free to delete out
        * of the set of expected results when we verify.
        * Also make a set of counts for each key value, to test count.
        */

       Map checkMap = new HashMap();
       Map countMap = new HashMap();
       Iterator iter = expectedMap.entrySet().iterator();
       while (iter.hasNext()) {
           Map.Entry entry = (Map.Entry) iter.next();
           Set copySet = new HashSet();
           copySet.addAll((Set) entry.getValue());
           checkMap.put(entry.getKey(), copySet);
           countMap.put(entry.getKey(), new Integer(copySet.size()));
       }

       while (status == OperationStatus.SUCCESS) {
           String foundKeyString = foundKey.getString();
           String foundDataString = foundData.getString();

           /* Check that the current value is in the check values map */
           Set dataVals = (Set) checkMap.get(foundKeyString);
           if (dataVals == null) {
               fail("Couldn't find " +
                    foundKeyString + "/" + foundDataString);
           } else if (dataVals.contains(foundDataString)) {
               dataVals.remove(foundDataString);
               if (dataVals.size() == 0) {
                   checkMap.remove(foundKeyString);
               }
           } else {
               fail("Couldn't find " +
                    foundKeyString + "/" +
                    foundDataString +
                    " in data vals");
           }

           /* Check that the count is right. */
           int count = cursor.count();
           assertEquals(((Integer)countMap.get(foundKeyString)).intValue(),
                        count);

           status = cursor.getNext(foundKey, foundData, LockMode.DEFAULT);
       }

cursor.close();

if (checkMap.size() != 0) {
    dumpExpected(checkMap);
    fail("checkMapSize = " + checkMap.size());
    		
}
       assertEquals(0, checkMap.size());
   }
 
開發者ID:nologic,項目名稱:nabs,代碼行數:68,代碼來源:CleanerTest.java

示例6: verifyData

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
protected void verifyData(Hashtable expectedData,
                             boolean checkInList,
		      int startDb,
                             int endDb)
       throws DatabaseException  {

       /* Run verify. */
       if (checkInList) {
           assertTrue(env.verify(null, System.err));
       } else {
           assertTrue(env.verify(null, System.err));
       }

       /*
        * Get a deep copy of expected data (cloning the data sets, not the
        * items within dataSet, since verifyData will remove items, and we
        * need to keep the expectedData set intact because we call verify
        * repeatedly.
        */
       Map useData = new Hashtable();
       Iterator iter = expectedData.entrySet().iterator();
       while (iter.hasNext()) {
           Map.Entry entry = (Map.Entry) iter.next();
           useData.put(entry.getKey(), ((HashSet) entry.getValue()).clone());
       }

       /* Generate an expected count map. */
       Map countMap = generateCountMap(expectedData);

       /* Check each db in turn. */
       DatabaseConfig dbConfig = new DatabaseConfig();
if (btreeComparisonFunction != null) {
    dbConfig.setBtreeComparator(btreeComparisonFunction.getClass());
}
       dbConfig.setTransactional(env.getConfig().getTransactional());
       dbConfig.setSortedDuplicates(true);
       dbConfig.setReadOnly(true);
       for (int d = startDb; d < endDb; d++) {
           Database checkDb = env.openDatabase(null, DB_NAME + d,
					dbConfig);
           Cursor myCursor = checkDb.openCursor(null, null);
           DatabaseEntry key = new DatabaseEntry();
           DatabaseEntry data = new DatabaseEntry();
           OperationStatus status =
	myCursor.getFirst(key, data, LockMode.DEFAULT);
           DbInternal.envGetEnvironmentImpl(env).verifyCursors();
           int numSeen = 0;

           while (status == OperationStatus.SUCCESS) {

               /* The key should have been in the expected data set. */
               removeExpectedData(useData, d, key, data, true);

               /* The count should be right. */
               int count = myCursor.count();
               assertEquals("Count not right for key " +
                            TestUtils.dumpByteArray(key.getData()),
                            getExpectedCount(countMap, d, key), count);

               status = myCursor.getNext(key, data, LockMode.DEFAULT);
               numSeen++;
           }

           myCursor.close();

           /* Should be nothing left in the expected data map. */
           if (DEBUG) {
               System.out.println("Finished db" + d + " numSeen=" +numSeen);
               dumpExpected(useData);
           }
           checkDb.close();
       }

       assertEquals(0, useData.size());
   }
 
開發者ID:nologic,項目名稱:nabs,代碼行數:76,代碼來源:RecoveryTestBase.java

示例7: checkData

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
    * Check what's in the database against what's in the expected map.
    */
   private void checkData(Map expectedMap) 
       throws DatabaseException {

       StringDbt foundKey = new StringDbt();
       StringDbt foundData = new StringDbt();
       Cursor cursor = exampleDb.openCursor(null, null);
       OperationStatus status = cursor.getFirst(foundKey, foundData,
                                                LockMode.DEFAULT);

       /* 
        * Make a copy of expectedMap so that we're free to delete out
        * of the set of expected results when we verify.
        * Also make a set of counts for each key value, to test count.
        */

       Map checkMap = new HashMap();
       Map countMap = new HashMap();
       Iterator iter = expectedMap.entrySet().iterator();
       while (iter.hasNext()) {
           Map.Entry entry = (Map.Entry) iter.next();
           Set copySet = new HashSet();
           copySet.addAll((Set) entry.getValue());
           checkMap.put(entry.getKey(), copySet);
           countMap.put(entry.getKey(), new Integer(copySet.size()));
       }     

       while (status == OperationStatus.SUCCESS) {
           String foundKeyString = foundKey.getString();
           String foundDataString = foundData.getString();

           /* Check that the current value is in the check values map */
           Set dataVals = (Set) checkMap.get(foundKeyString);
           if (dataVals == null) {
               fail("Couldn't find " +
                    foundKeyString + "/" + foundDataString);
           } else if (dataVals.contains(foundDataString)) {
               dataVals.remove(foundDataString);
               if (dataVals.size() == 0) {
                   checkMap.remove(foundKeyString);
               }
           } else {
               fail("Couldn't find " +
                    foundKeyString + "/" + 
                    foundDataString +
                    " in data vals");
           }

           /* Check that the count is right. */
           int count = cursor.count();
           assertEquals(((Integer)countMap.get(foundKeyString)).intValue(),
                        count);

           status = cursor.getNext(foundKey, foundData, LockMode.DEFAULT);
       }

cursor.close();

if (checkMap.size() != 0) {
    dumpExpected(checkMap);
    fail("checkMapSize = " + checkMap.size());
    		
}
       assertEquals(0, checkMap.size());
   }
 
開發者ID:nologic,項目名稱:nabs,代碼行數:68,代碼來源:CleanerTest.java

示例8: verifyData

import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
protected void verifyData(Hashtable expectedData,
                             boolean checkInList,
		      int startDb,
                             int endDb)
       throws DatabaseException  {

       /* Run verify. */
       if (checkInList) {
           assertTrue(env.verify(null, System.err));
       } else {
           assertTrue(env.verify(null, System.err));
       }

       /*
        * Get a deep copy of expected data (cloning the data sets, not the
        * items within dataSet, since verifyData will remove items, and we
        * need to keep the expectedData set intact because we call verify
        * repeatedly.
        */
       Map useData = new Hashtable();
       Iterator iter = expectedData.entrySet().iterator();
       while (iter.hasNext()) {
           Map.Entry entry = (Map.Entry) iter.next();
           useData.put(entry.getKey(), ((HashSet) entry.getValue()).clone());
       }

       /* Generate an expected count map. */
       Map countMap = generateCountMap(expectedData);

       /* Check each db in turn. */
       DatabaseConfig dbConfig = new DatabaseConfig();
if (btreeComparisonFunction != null) {
    dbConfig.setBtreeComparator(btreeComparisonFunction.getClass());
}
       dbConfig.setTransactional(env.getConfig().getTransactional());
       dbConfig.setSortedDuplicates(true);
       dbConfig.setReadOnly(true);
       for (int d = startDb; d < endDb; d++) {
           Database checkDb = env.openDatabase(null, DB_NAME + d,
					dbConfig);
           Cursor myCursor = checkDb.openCursor(null, null);
           DatabaseEntry key = new DatabaseEntry();
           DatabaseEntry data = new DatabaseEntry();
           OperationStatus status =
	myCursor.getFirst(key, data, LockMode.DEFAULT);
           DbInternal.envGetEnvironmentImpl(env).verifyCursors();
           int numSeen = 0;

           while (status == OperationStatus.SUCCESS) {

               /* The key should have been in the expected data set. */
               removeExpectedData(useData, d, key, data, true);

               /* The count should be right. */
               int count = myCursor.count();
               assertEquals("Count not right for key " +
                            TestUtils.dumpByteArray(key.getData()),
                            getExpectedCount(countMap, d, key), count);
               
               status = myCursor.getNext(key, data, LockMode.DEFAULT);
               numSeen++;
           }

           myCursor.close();

           /* Should be nothing left in the expected data map. */
           if (DEBUG) {
               System.out.println("Finished db" + d + " numSeen=" +numSeen);
               dumpExpected(useData);
           }
           checkDb.close();
       }

       assertEquals(0, useData.size());
   }
 
開發者ID:nologic,項目名稱:nabs,代碼行數:76,代碼來源:RecoveryTestBase.java


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