Exemplo n.º 1
0
    void Scope::loadStored( bool ignoreNotConnected ){
        if ( _localDBName.size() == 0 ){
            if ( ignoreNotConnected )
                return;
            uassert( "need to have locallyConnected already" , _localDBName.size() );
        }
        if ( _loadedVersion == _lastVersion )
            return;
        
        _loadedVersion = _lastVersion;

        static DBClientBase * db = createDirectClient();
        
        auto_ptr<DBClientCursor> c = db->query( _localDBName + ".system.js" , Query() );
        while ( c->more() ){
            BSONObj o = c->next();

            BSONElement n = o["_id"];
            BSONElement v = o["value"];
            
            uassert( "name has to be a string" , n.type() == String );
            uassert( "value has to be set" , v.type() != EOO );
            
            setElement( n.valuestr() , v );
        }
    }
Exemplo n.º 2
0
    JSBool mongo_local_constructor( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval ){
        Convertor c( cx );

        shared_ptr< DBClientBase > client( createDirectClient() );
        assert( JS_SetPrivate( cx , obj , (void*)( new shared_ptr< DBClientBase >( client ) ) ) );

        jsval host = c.toval( "EMBEDDED" );
        assert( JS_SetProperty( cx , obj , "host" , &host ) );

        return JS_TRUE;
    }
Exemplo n.º 3
0
    void Scope::loadStored( bool ignoreNotConnected ){
        if ( _localDBName.size() == 0 ){
            if ( ignoreNotConnected )
                return;
            uassert( 10208 ,  "need to have locallyConnected already" , _localDBName.size() );
        }
        if ( _loadedVersion == _lastVersion )
            return;
        
        _loadedVersion = _lastVersion;

        string coll = _localDBName + ".system.js";
        
        static DBClientBase * db = createDirectClient();
        auto_ptr<DBClientCursor> c = db->query( coll , Query() );
        assert( c.get() );
        
        set<string> thisTime;
        
        while ( c->more() ){
            BSONObj o = c->next();

            BSONElement n = o["_id"];
            BSONElement v = o["value"];
            
            uassert( 10209 ,  "name has to be a string" , n.type() == String );
            uassert( 10210 ,  "value has to be set" , v.type() != EOO );
            
            setElement( n.valuestr() , v );

            thisTime.insert( n.valuestr() );
            _storedNames.insert( n.valuestr() );
            
        }

        // --- remove things from scope that were removed

        list<string> toremove;

        for ( set<string>::iterator i=_storedNames.begin(); i!=_storedNames.end(); i++ ){
            string n = *i;
            if ( thisTime.count( n ) == 0 )
                toremove.push_back( n );
        }
        
        for ( list<string>::iterator i=toremove.begin(); i!=toremove.end(); i++ ){
            string n = *i;
            _storedNames.erase( n );
            execSetup( (string)"delete " + n , "clean up scope" );
        }

    }
Exemplo n.º 4
0
    void Scope::loadStored(bool ignoreNotConnected) {
        if (_localDBName.size() == 0) {
            if (ignoreNotConnected)
                return;
            uassert(10208,  "need to have locallyConnected already", _localDBName.size());
        }

        if (_loadedVersion == _lastVersion)
            return;

        _loadedVersion = _lastVersion;
        string coll = _localDBName + ".system.js";

        DBClientBase* directDBClient = createDirectClient();
        auto_ptr<DBClientCursor> c = directDBClient->query(coll, Query(), 0, 0, NULL,
            QueryOption_SlaveOk, 0);
        massert(16669, "unable to get db client cursor from query", c.get());

        set<string> thisTime;
        while (c->more()) {
            BSONObj o = c->nextSafe();
            BSONElement n = o["_id"];
            BSONElement v = o["value"];

            uassert(10209, str::stream() << "name has to be a string: " << n, n.type() == String);
            uassert(10210, "value has to be set", v.type() != EOO);

            try {
                setElement(n.valuestr(), v);
                thisTime.insert(n.valuestr());
                _storedNames.insert(n.valuestr());
            }
            catch (const DBException& setElemEx) {
                log() << "unable to load stored JavaScript function " << n.valuestr()
                      << "(): " << setElemEx.what() << endl;
            }
        }

        // remove things from scope that were removed from the system.js collection
        for (set<string>::iterator i = _storedNames.begin(); i != _storedNames.end(); ) {
            if (thisTime.count(*i) == 0) {
                string toDelete = str::stream() << "delete " << *i;
                _storedNames.erase(i++);
                execSetup(toDelete, "clean up scope");
            }
            else {
                ++i;
            }
        }
    }