2009-02-20 16:46:42 +01:00
|
|
|
// stragegy.cpp
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "request.h"
|
|
|
|
#include "../client/connpool.h"
|
|
|
|
#include "../db/commands.h"
|
|
|
|
|
|
|
|
namespace mongo {
|
|
|
|
|
2009-02-24 03:47:25 +01:00
|
|
|
// ----- Strategy ------
|
|
|
|
|
2009-02-20 16:46:42 +01:00
|
|
|
void Strategy::doWrite( int op , Request& r , string server ){
|
|
|
|
ScopedDbConnection dbcon( server );
|
|
|
|
DBClientBase &_c = dbcon.conn();
|
|
|
|
|
|
|
|
/* TODO FIX - do not case and call DBClientBase::say() */
|
|
|
|
DBClientConnection&c = dynamic_cast<DBClientConnection&>(_c);
|
|
|
|
c.port().say( r.m() );
|
|
|
|
|
|
|
|
dbcon.done();
|
|
|
|
}
|
2009-02-22 05:39:41 +01:00
|
|
|
|
|
|
|
void Strategy::doQuery( Request& r , string server ){
|
|
|
|
try{
|
|
|
|
ScopedDbConnection dbcon( server );
|
|
|
|
DBClientBase &_c = dbcon.conn();
|
|
|
|
|
|
|
|
// TODO: This will not work with Paired connections. Fix.
|
|
|
|
DBClientConnection&c = dynamic_cast<DBClientConnection&>(_c);
|
|
|
|
Message response;
|
|
|
|
bool ok = c.port().call( r.m(), response);
|
|
|
|
uassert("mongos: error calling db", ok);
|
|
|
|
r.reply( response );
|
|
|
|
dbcon.done();
|
|
|
|
}
|
|
|
|
catch ( AssertionException& e ) {
|
|
|
|
BSONObjBuilder err;
|
|
|
|
err.append("$err", string("mongos: ") + (e.msg.empty() ? "assertion during query" : e.msg));
|
|
|
|
BSONObj errObj = err.done();
|
|
|
|
replyToQuery(QueryResult::ResultFlag_ErrSet, r.p() , r.m() , errObj);
|
|
|
|
}
|
|
|
|
}
|
2009-02-20 19:46:57 +01:00
|
|
|
|
2009-02-20 16:46:42 +01:00
|
|
|
void Strategy::insert( string server , const char * ns , const BSONObj& obj ){
|
|
|
|
ScopedDbConnection dbcon( server );
|
|
|
|
dbcon->insert( ns , obj );
|
2009-02-20 19:46:57 +01:00
|
|
|
dbcon.done();
|
2009-02-20 16:46:42 +01:00
|
|
|
}
|
2009-02-24 03:47:25 +01:00
|
|
|
|
2009-02-20 16:46:42 +01:00
|
|
|
}
|