void WiredTigerSizeStorer::loadFrom( WiredTigerSession* session, const std::string& uri ) { _checkMagic(); Map m; { WT_SESSION* s = session->getSession(); WT_CURSOR* c = NULL; int ret = s->open_cursor( s, uri.c_str(), NULL, NULL, &c ); if ( ret == ENOENT ) { // doesn't exist, we'll create later return; } invariantWTOK( ret ); while ( c->next(c) == 0 ) { WT_ITEM key; WT_ITEM value; invariantWTOK( c->get_key(c, &key ) ); invariantWTOK( c->get_value(c, &value ) ); std::string uriKey( reinterpret_cast<const char*>( key.data ), key.size ); BSONObj data( reinterpret_cast<const char*>( value.data ) ); LOG(2) << "WiredTigerSizeStorer::loadFrom " << uriKey << " -> " << data; Entry& e = m[uriKey]; e.numRecords = data["numRecords"].safeNumberLong(); e.dataSize = data["dataSize"].safeNumberLong(); e.dirty = false; e.rs = NULL; } invariantWTOK( c->close(c) ); } boost::mutex::scoped_lock lk( _entriesMutex ); _entries = m; }
OsStatus DialByNameDB::load() const { // Critical Section here OsLock lock( sLockMutex ); OsStatus result = OS_SUCCESS; if ( m_pFastDB != NULL ) { // Clean out the existing DB rows before loading // a new set from persistent storage removeAllRows (); // Query all Identities with 'AutoAttendant' permission set PermissionDB * pPermissionDB = PermissionDB::getInstance(); ResultSet permissionsResultSet; pPermissionDB->getIdentities ( "AutoAttendant", permissionsResultSet ); CredentialDB * pCredentialDB = CredentialDB::getInstance(); ResultSet credentialsResultSet; UtlString identity, permission; int numAutoAttendees = permissionsResultSet.getSize(); for (int index = 0; index < numAutoAttendees; index++) { // get the next identity UtlString identityKey("identity"); UtlHashMap record; permissionsResultSet.getIndex( index, record ); UtlString identity = *((UtlString*)record.findValue(&identityKey)); Url identityUrl (identity); pCredentialDB-> getAllCredentials ( identityUrl, credentialsResultSet ); // we should only have one credential! we're // only interested in the uri column's display name if ( credentialsResultSet.getSize() == 1) { UtlString uriKey("uri"); UtlHashMap record; credentialsResultSet.getIndex( 0, record ); UtlString uri = *((UtlString*)record.findValue(&uriKey)); // must have a display name present before inserting a row // @TODO convert to url and get display name UtlHashMap nvPairs; if (!uri.isNull()) { // Null Element value create a special // char string we have key and value so insert UtlString* contactValue = new UtlString( uri ); // Memory Leak fixes, make shallow copies of static keys UtlString* contactKey = new UtlString( gNp_contactKey ); nvPairs.insertKeyAndValue ( contactKey, contactValue ); } // Insert the item row into the IMDB insertRow ( nvPairs ); } } // Reset the changed flags after a successful load SIPDBManager::getInstance()-> setDatabaseChangedFlag("credential", FALSE); SIPDBManager::getInstance()-> setDatabaseChangedFlag("permission", FALSE); } else { result = OS_FAILED; } return result; }