summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-03-16 22:14:00 -0400
committerEliot Horowitz <eliot@10gen.com>2010-03-16 22:14:00 -0400
commitca5d99d53a37e76faccd1d428d3efc93f04a3ec0 (patch)
tree680b78a47ced2fd5aeec858f75fb997cb291ba7c
parentc96de7cbb648f3d73759fab3e70c185244a57618 (diff)
downloadmongo-ca5d99d53a37e76faccd1d428d3efc93f04a3ec0.tar.gz
replica pair and SCC support for v8 shell
-rw-r--r--scripting/v8_db.cpp43
1 files changed, 36 insertions, 7 deletions
diff --git a/scripting/v8_db.cpp b/scripting/v8_db.cpp
index 49b6efedfe3..4d14a03acdc 100644
--- a/scripting/v8_db.cpp
+++ b/scripting/v8_db.cpp
@@ -20,7 +20,7 @@
#include "v8_db.h"
#include "engine.h"
#include "util/base64.h"
-
+#include "../client/syncclusterconnection.h"
#include <iostream>
using namespace std;
@@ -148,15 +148,44 @@ namespace mongo {
strcpy( host , "127.0.0.1" );
}
- DBClientConnection * conn = new DBClientConnection( true );
-
+ DBClientWithCommands * conn = 0;
+ int commas = 0;
+ for ( int i=0; i<255; i++ ){
+ if ( host[i] == ',' )
+ commas++;
+ else if ( host[i] == 0 )
+ break;
+ }
+
+ if ( commas == 0 ){
+ DBClientConnection * c = new DBClientConnection( true );
+ string errmsg;
+ if ( ! c->connect( host , errmsg ) ){
+ delete c;
+ string x = "couldn't connect: ";
+ x += errmsg;
+ return v8::ThrowException( v8::String::New( x.c_str() ) );
+ }
+ conn = c;
+ }
+ else if ( commas == 1 ){
+ DBClientPaired * c = new DBClientPaired();
+ if ( ! c->connect( host ) ){
+ delete c;
+ return v8::ThrowException( v8::String::New( "couldn't connect to pair" ) );
+ }
+ conn = c;
+ }
+ else if ( commas == 2 ){
+ conn = new SyncClusterConnection( host );
+ }
+ else {
+ return v8::ThrowException( v8::String::New( "too many commas" ) );
+ }
+
Persistent<v8::Object> self = Persistent<v8::Object>::New( args.This() );
self.MakeWeak( conn , destroyConnection );
- string errmsg;
- if ( ! conn->connect( host , errmsg ) ){
- return v8::ThrowException( v8::String::New( "couldn't connect" ) );
- }
ScriptEngine::runConnectCallback( *conn );
// NOTE I don't believe the conn object will ever be freed.
args.This()->Set( CONN_STRING , External::New( conn ) );