summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-02-06 17:16:41 -0500
committerAaron <aaron@10gen.com>2009-02-06 17:16:41 -0500
commitc2cde252670d4d35d15ac7a7f6d8bc82a749264a (patch)
tree411dd4a47bad719e1bfee8a76f892594d4c7ef41
parent3504f3249c62d205d66aab2f714d1bc06b4a0934 (diff)
parent21e105d3a2a3d203cfff6a675a62167b4d36552a (diff)
downloadmongo-c2cde252670d4d35d15ac7a7f6d8bc82a749264a.tar.gz
Merge branch 'master' of ssh://aaron@git.10gen.com/data/gitroot/p
-rw-r--r--SConstruct4
-rw-r--r--client/dbclient.h21
-rw-r--r--client/examples/tutorial.cpp20
-rw-r--r--db/repl.cpp2
-rw-r--r--dbtests/namespacetests.cpp2
-rw-r--r--dbtests/pairingtests.cpp8
-rw-r--r--stdafx.cpp2
-rw-r--r--stdafx.h8
8 files changed, 54 insertions, 13 deletions
diff --git a/SConstruct b/SConstruct
index e466cb27b0b..20f336b743c 100644
--- a/SConstruct
+++ b/SConstruct
@@ -6,7 +6,7 @@
# some common tasks
# build 64-bit mac and pushing to s3
-# scons --64 --dist=osx-x86_64 s3dist
+# scons --64 s3dist
# all s3 pushes require settings.py
import os
@@ -184,6 +184,7 @@ if "darwin" == os.sys.platform:
elif "linux2" == os.sys.platform:
useJavaHome = True
javaOS = "linux"
+ platform = "linux"
if not os.path.exists( javaHome ):
#fedora standarm jvm location
@@ -637,6 +638,7 @@ distFile = installDir + ".tgz"
env.Append( TARFLAGS=" -z " )
env.Tar( distFile , installDir )
+env.Alias( "dist" , distFile )
env.Alias( "s3dist" , [ "install" , distFile ] , [ s3dist ] )
env.AlwaysBuild( "s3dist" )
diff --git a/client/dbclient.h b/client/dbclient.h
index e9bbf18504c..9bd24a1fe0c 100644
--- a/client/dbclient.h
+++ b/client/dbclient.h
@@ -516,6 +516,11 @@ namespace mongo {
class DBClientPaired;
+ class ConnectException : public UserException {
+ public:
+ ConnectException(string msg) : UserException(msg) { }
+ };
+
/**
A basic connection to the database.
This is the main entry point for talking to a simple Mongo setup
@@ -539,7 +544,7 @@ namespace mongo {
DBClientConnection(bool _autoReconnect=false,DBClientPaired* cp=0) :
clientPaired(cp), failed(false), autoReconnect(_autoReconnect), lastReconnectTry(0) { }
- /**Connect to a Mongo database server.
+ /** Connect to a Mongo database server.
If autoReconnect is true, you can try to use the DBClientConnection even when
false was returned -- it will try to connect again.
@@ -550,6 +555,20 @@ namespace mongo {
*/
virtual bool connect(const char *serverHostname, string& errmsg);
+ /** Connect to a Mongo database server. Exception throwing version.
+ Throws a UserException if cannot connect.
+
+ If autoReconnect is true, you can try to use the DBClientConnection even when
+ false was returned -- it will try to connect again.
+
+ @param serverHostname host to connect to. can include port number ( 127.0.0.1 , 127.0.0.1:5555 )
+ */
+ void connect(string serverHostname) {
+ string errmsg;
+ if( !connect(serverHostname.c_str(), errmsg) )
+ throw new ConnectException(string("can't connect ") + errmsg);
+ }
+
virtual bool auth(const char *dbname, const char *username, const char *pwd, string& errmsg, bool digestPassword = true);
virtual auto_ptr<DBClientCursor> query(const char *ns, Query query, int nToReturn = 0, int nToSkip = 0,
diff --git a/client/examples/tutorial.cpp b/client/examples/tutorial.cpp
new file mode 100644
index 00000000000..801c890dd00
--- /dev/null
+++ b/client/examples/tutorial.cpp
@@ -0,0 +1,20 @@
+#include <iostream>
+#include "client/dbclient.h"
+
+// g++ -I ../.. -L ../.. tutorial.cpp -lmongoclient -lboost_thread -lboost_filesystem
+
+using namespace mongo;
+
+void run() {
+ DBClientConnection c;
+
+}
+
+int main() {
+ try {
+ run();
+ } catch( DBException &e ) {
+ cout << "caught " << e.what() << endl;
+ }
+ return 0;
+}
diff --git a/db/repl.cpp b/db/repl.cpp
index e612f0b90cf..504716d2379 100644
--- a/db/repl.cpp
+++ b/db/repl.cpp
@@ -678,7 +678,7 @@ namespace mongo {
_runCommands(ns, o, ss, bb, ob, true, 0);
}
}
- catch ( UserAssertionException& e ) {
+ catch ( UserException& e ) {
log() << "sync: caught user assertion " << e.msg << '\n';
}
}
diff --git a/dbtests/namespacetests.cpp b/dbtests/namespacetests.cpp
index bfb658165f4..486348a4cef 100644
--- a/dbtests/namespacetests.cpp
+++ b/dbtests/namespacetests.cpp
@@ -251,7 +251,7 @@ namespace NamespaceTests {
BSONObjSetDefaultOrder keys;
ASSERT_EXCEPTION( id().getKeysFromObject( b.done(), keys ),
- UserAssertionException );
+ UserException );
}
private:
virtual BSONObj key() const {
diff --git a/dbtests/pairingtests.cpp b/dbtests/pairingtests.cpp
index 8734998dfbc..541b0fd9959 100644
--- a/dbtests/pairingtests.cpp
+++ b/dbtests/pairingtests.cpp
@@ -94,16 +94,16 @@ namespace PairingTests {
checkFields( rp3, "", "", DBPort, "bar" );
ASSERT_EXCEPTION( ReplPair( "foo:", "bar" ),
- UserAssertionException );
+ UserException );
ASSERT_EXCEPTION( ReplPair( "foo:0", "bar" ),
- UserAssertionException );
+ UserException );
ASSERT_EXCEPTION( ReplPair( "foo:10000000", "bar" ),
- UserAssertionException );
+ UserException );
ASSERT_EXCEPTION( ReplPair( "foo", "" ),
- UserAssertionException );
+ UserException );
}
private:
void checkFields( const ReplPair &rp,
diff --git a/stdafx.cpp b/stdafx.cpp
index 88156f17473..7695b72a9d6 100644
--- a/stdafx.cpp
+++ b/stdafx.cpp
@@ -69,7 +69,7 @@ namespace mongo {
RARELY log() << "User Assertion " << msg << endl;
lastAssert[3].set(msg, getDbContext().c_str(), "", 0);
raiseError(msg);
- throw UserAssertionException(msg);
+ throw UserException(msg);
}
void msgasserted(const char *msg) {
diff --git a/stdafx.h b/stdafx.h
index 0e6a0654833..7e6c12d3662 100644
--- a/stdafx.h
+++ b/stdafx.h
@@ -129,13 +129,13 @@ namespace mongo {
virtual const char* what() const throw() { return msg.c_str(); }
};
- /* we use the same mechanism for bad things the user does -- which are really just errors */
- class UserAssertionException : public AssertionException {
+ /* UserExceptions are valid errors that a user can cause, like out of disk space or duplicate key */
+ class UserException : public AssertionException {
public:
- UserAssertionException(const char *_msg) {
+ UserException(const char *_msg) {
msg = _msg;
}
- UserAssertionException(string _msg) {
+ UserException(string _msg) {
msg = _msg;
}
virtual bool severe() {