mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
Merge branch 'master' of git@github.com:mongodb/mongo
This commit is contained in:
commit
a4cbf3072f
@ -230,7 +230,7 @@ namespace mongo {
|
||||
OPWRITE;
|
||||
try {
|
||||
ss << "remove ";
|
||||
receivedDelete(m);
|
||||
receivedDelete(m, ss);
|
||||
}
|
||||
catch ( AssertionException& e ) {
|
||||
LOGSOME problem() << " Caught Assertion receivedDelete, continuing" << endl;
|
||||
@ -327,13 +327,14 @@ namespace mongo {
|
||||
bool upsert = flags & 1;
|
||||
{
|
||||
string s = query.toString();
|
||||
ss << " query: " << s;
|
||||
strncpy(currentOp.query, s.c_str(), sizeof(currentOp.query)-1);
|
||||
}
|
||||
bool updatedExisting = updateObjects(ns, toupdate, query, flags & 1, ss);
|
||||
recordUpdate( updatedExisting, ( upsert || updatedExisting ) ? 1 : 0 );
|
||||
}
|
||||
|
||||
void receivedDelete(Message& m) {
|
||||
void receivedDelete(Message& m, stringstream &ss) {
|
||||
DbMessage d(m);
|
||||
const char *ns = d.getns();
|
||||
assert(*ns);
|
||||
@ -345,6 +346,7 @@ namespace mongo {
|
||||
BSONObj pattern = d.nextJsObj();
|
||||
{
|
||||
string s = pattern.toString();
|
||||
ss << " query: " << s;
|
||||
strncpy(currentOp.query, s.c_str(), sizeof(currentOp.query)-1);
|
||||
}
|
||||
int n = deleteObjects(ns, pattern, justOne, true);
|
||||
@ -536,7 +538,7 @@ namespace mongo {
|
||||
}
|
||||
else if ( m.data->operation() == dbDelete ) {
|
||||
ss << "remove ";
|
||||
receivedDelete(m);
|
||||
receivedDelete(m, ss);
|
||||
}
|
||||
else if ( m.data->operation() == dbGetMore ) {
|
||||
DEV log = true;
|
||||
|
@ -91,7 +91,7 @@ namespace mongo {
|
||||
|
||||
void receivedKillCursors(Message& m);
|
||||
void receivedUpdate(Message& m, stringstream& ss);
|
||||
void receivedDelete(Message& m);
|
||||
void receivedDelete(Message& m, stringstream& ss);
|
||||
void receivedInsert(Message& m, stringstream& ss);
|
||||
void receivedGetMore(DbResponse& dbresponse, /*AbstractMessagingPort& dbMsgPort, */Message& m, stringstream& ss);
|
||||
void receivedQuery(DbResponse& dbresponse, /*AbstractMessagingPort& dbMsgPort, */Message& m, stringstream& ss, bool logit);
|
||||
|
@ -580,6 +580,13 @@ namespace NamespaceTests {
|
||||
// }
|
||||
// };
|
||||
|
||||
class Size {
|
||||
public:
|
||||
void run() {
|
||||
ASSERT_EQUALS( 496U, sizeof( NamespaceDetails ) );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace NamespaceDetailsTests
|
||||
|
||||
class All : public UnitTest::Suite {
|
||||
@ -605,6 +612,7 @@ namespace NamespaceTests {
|
||||
add< NamespaceDetailsTests::TwoExtent >();
|
||||
add< NamespaceDetailsTests::Migrate >();
|
||||
// add< NamespaceDetailsTests::BigCollection >();
|
||||
add< NamespaceDetailsTests::Size >();
|
||||
}
|
||||
};
|
||||
} // namespace NamespaceTests
|
||||
|
@ -100,7 +100,7 @@ namespace mongo {
|
||||
log() << "resolveBSONField can't handle type: " << (int)(e.type()) << endl;
|
||||
}
|
||||
|
||||
uassert( "not done" , 0 );
|
||||
uassert( "not done: toval" , 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -108,6 +108,23 @@ namespace mongo {
|
||||
JSContext * _context;
|
||||
};
|
||||
|
||||
class ObjectWrapper {
|
||||
public:
|
||||
ObjectWrapper( JSContext * cx , JSObject * obj ) : _context( cx ) , _object( obj ){}
|
||||
|
||||
JSObject * getJSObject( const char * name ){
|
||||
jsval v;
|
||||
assert( JS_GetProperty( _context , _object , name , &v ) );
|
||||
return JSVAL_TO_OBJECT( v );
|
||||
}
|
||||
|
||||
private:
|
||||
JSContext * _context;
|
||||
JSObject * _object;
|
||||
};
|
||||
|
||||
|
||||
|
||||
static JSClass global_class = {
|
||||
"global", JSCLASS_GLOBAL_FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
@ -128,8 +145,11 @@ namespace mongo {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool native_db_create( JSContext * cx , JSObject * obj , uintN argc, jsval *argv, jsval *rval );
|
||||
|
||||
JSFunctionSpec globalHelpers[] = {
|
||||
{ "print" , &native_print , 0 , 0 , 0 } ,
|
||||
{ "print" , &native_print , 0 , 0 , 0 } ,
|
||||
{ "createDB" , &native_db_create , 0 , 0 , 0 } ,
|
||||
{ 0 , 0 , 0 , 0 , 0 }
|
||||
};
|
||||
|
||||
@ -198,9 +218,14 @@ namespace mongo {
|
||||
}
|
||||
|
||||
JSBool mongo_local_constructor( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval ){
|
||||
Convertor c( cx );
|
||||
|
||||
DBClientBase * client = createDirectClient();
|
||||
cout << "client c: " << client << endl;
|
||||
JS_SetPrivate( cx , obj , (void*)client );
|
||||
|
||||
jsval host = c.toval( "EMBEDDED" );
|
||||
assert( JS_SetProperty( cx , obj , "host" , &host ) );
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
@ -231,6 +256,72 @@ namespace mongo {
|
||||
0 , 0 , 0 , 0
|
||||
};
|
||||
|
||||
// -------------- DB ---------------
|
||||
|
||||
|
||||
JSBool db_constructor( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval ){
|
||||
cout << "db_constructor" << endl;
|
||||
uassert( "wrong number of arguments to DB" , argc == 2 );
|
||||
assert( JS_SetProperty( cx , obj , "_mongo" , &(argv[0]) ) );
|
||||
assert( JS_SetProperty( cx , obj , "_name" , &(argv[1]) ) );
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool resolve_dbcollection( JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp ){
|
||||
Convertor c( cx );
|
||||
string collname = c.toString( id );
|
||||
|
||||
if ( collname == "prototype" || collname.find( "__" ) == 0 ||
|
||||
collname == "_mongo" || collname == "_name" )
|
||||
return JS_TRUE;
|
||||
|
||||
JSObject * proto = JS_GetPrototype( cx , obj );
|
||||
if ( proto ){
|
||||
JSBool res;
|
||||
assert( JS_HasProperty( cx , proto , collname.c_str() , &res ) );
|
||||
if ( res )
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
uassert( (string)"not done: resolve_dbcollection: " + collname , 0 );
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSClass db_class = {
|
||||
"DB" , JSCLASS_HAS_PRIVATE | JSCLASS_NEW_RESOLVE ,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, (JSResolveOp)(&resolve_dbcollection) , JS_ConvertStub, JS_FinalizeStub,
|
||||
0 , 0 , 0 ,
|
||||
db_constructor ,
|
||||
0 , 0 , 0 , 0
|
||||
};
|
||||
|
||||
static JSPropertySpec db_props[] = {
|
||||
{ "_mongo" , 0 , 0 } ,
|
||||
{ "_name" , 0 , 0 } ,
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
JSBool native_db_create( JSContext * cx , JSObject * obj , uintN argc, jsval *argv, jsval *rval ){
|
||||
uassert( "db needs 2 args" , argc == 2 );
|
||||
|
||||
ObjectWrapper a( cx , JS_GetGlobalObject( cx ) );
|
||||
JSObject * DB = a.getJSObject( "DB" );
|
||||
ObjectWrapper b( cx , DB );
|
||||
JSObject * DBprototype = b.getJSObject( "prototype" );
|
||||
uassert( "can't find DB prototype" , DBprototype );
|
||||
|
||||
JSObject * db = JS_NewObject( cx , &db_class , 0 , 0 );
|
||||
assert( JS_SetProperty( cx , db , "_mongo" , &(argv[0]) ) );
|
||||
assert( JS_SetProperty( cx , db , "_name" , &(argv[1]) ) );
|
||||
assert( JS_SetPrototype( cx , db , DBprototype ) );
|
||||
|
||||
*rval = OBJECT_TO_JSVAL( db );
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
// -------------- object id -------------
|
||||
|
||||
JSBool object_id_constructor( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval ){
|
||||
|
||||
OID oid;
|
||||
@ -238,7 +329,7 @@ namespace mongo {
|
||||
oid.init();
|
||||
}
|
||||
else {
|
||||
uassert( "not done yet" , 0 );
|
||||
uassert( "object_id_constructor 2nd case" , 0 );
|
||||
}
|
||||
|
||||
Convertor c( cx );
|
||||
@ -259,7 +350,7 @@ namespace mongo {
|
||||
|
||||
// ------ scope ------
|
||||
|
||||
|
||||
|
||||
class SMScope : public Scope {
|
||||
public:
|
||||
SMScope(){
|
||||
@ -303,12 +394,14 @@ namespace mongo {
|
||||
}
|
||||
|
||||
void localConnect( const char * dbName ){
|
||||
jsval mongo = OBJECT_TO_JSVAL( JS_NewObject( _context , &mongo_local_class , 0 , 0 ) );
|
||||
assert( JS_SetProperty( _context , _global , "Mongo" , &mongo ) );
|
||||
|
||||
jsval objectid = OBJECT_TO_JSVAL( JS_NewObject( _context , &object_id_class , 0 , 0 ) );
|
||||
assert( JS_SetProperty( _context , _global , "ObjectId" , &objectid ) );
|
||||
assert( JS_InitClass( _context , _global , 0 , &mongo_local_class , 0 , 0 , 0 , 0 , 0 , 0 ) );
|
||||
assert( JS_InitClass( _context , _global , 0 , &object_id_class , 0 , 0 , 0 , 0 , 0 , 0 ) );
|
||||
//assert( JS_InitClass( _context , _global , 0 , &db_class , 0 , 0 , db_props , 0 ,0 , 0 ) );
|
||||
|
||||
exec( jsconcatcode );
|
||||
|
||||
exec( "_mongo = new Mongo();" );
|
||||
exec( ((string)"db = _mongo.getDB( \"" + dbName + "\" ); ").c_str() );
|
||||
}
|
||||
|
||||
// ----- getters ------
|
||||
@ -345,6 +438,11 @@ namespace mongo {
|
||||
massert( "not implemented yet: getObject()" , 0 ); throw -1;
|
||||
}
|
||||
|
||||
JSObject * getJSObject( const char * field ){
|
||||
ObjectWrapper o( _context , _global );
|
||||
return o.getJSObject( field );
|
||||
}
|
||||
|
||||
int type( const char *field ){
|
||||
jsval val;
|
||||
assert( JS_GetProperty( _context , _global , field , &val ) );
|
||||
@ -490,7 +588,12 @@ namespace mongo {
|
||||
|
||||
|
||||
void SMEngine::runTest(){
|
||||
// this is deprecated
|
||||
SMScope s;
|
||||
|
||||
s.localConnect( "blah" );
|
||||
s.exec( "print( '_mongo:' + _mongo );" );
|
||||
s.exec( "assert( db.getMongo() )" );
|
||||
s.exec( "assert( db.blah , 'collection getting does not work' ); " );
|
||||
}
|
||||
|
||||
Scope * SMEngine::createScope(){
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
|
||||
if ( ( typeof DBCollection ) == "undefined" ){
|
||||
print( "defined DBCollection" );
|
||||
|
||||
DBCollection = function( mongo , db , shortName , fullName ){
|
||||
this._mongo = mongo;
|
||||
this._db = db;
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
if ( typeof DB == "undefined" ){
|
||||
DB = function( mongo , name ){
|
||||
assert( typeof createDB != "function" , "createDB defined, so shouldn't do this" );
|
||||
this._mongo = mongo;
|
||||
this._name = name;
|
||||
}
|
||||
|
@ -24,6 +24,12 @@ Mongo.prototype.setSlaveOk = function() {
|
||||
}
|
||||
|
||||
Mongo.prototype.getDB = function( name ){
|
||||
if ( typeof createDB == "function" ){
|
||||
var newdb = createDB( this , name );
|
||||
assert( this == newdb.getMongo() , "createDB sanity check 1" );
|
||||
assert( this == newdb._mongo , "createDB sanity check 2" );
|
||||
return newdb;
|
||||
}
|
||||
return new DB( this , name );
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
// query.js
|
||||
|
||||
if ( typeof DBQuery == "undefined" ){
|
||||
print( "defining DBQuery" );
|
||||
DBQuery = function( mongo , db , collection , ns , query , fields , limit , skip ){
|
||||
|
||||
this._mongo = mongo; // 0
|
||||
|
Loading…
Reference in New Issue
Block a user