mirror of
				https://github.com/Telecominfraproject/wlan-cloud-lib-poco.git
				synced 2025-10-31 02:27:56 +00:00 
			
		
		
		
	MongoDB: fixes for style and consistency
This commit is contained in:
		| @@ -15,62 +15,68 @@ | |||||||
| // SPDX-License-Identifier:	BSL-1.0 | // SPDX-License-Identifier:	BSL-1.0 | ||||||
| // | // | ||||||
|  |  | ||||||
|  |  | ||||||
| #ifndef MongoDB_Array_INCLUDED | #ifndef MongoDB_Array_INCLUDED | ||||||
| #define MongoDB_Array_INCLUDED | #define MongoDB_Array_INCLUDED | ||||||
|  |  | ||||||
| #include "Poco/NumberFormatter.h" |  | ||||||
|  |  | ||||||
|  | #include "Poco/NumberFormatter.h" | ||||||
| #include "Poco/MongoDB/MongoDB.h" | #include "Poco/MongoDB/MongoDB.h" | ||||||
| #include "Poco/MongoDB/Document.h" | #include "Poco/MongoDB/Document.h" | ||||||
|  |  | ||||||
|  |  | ||||||
| namespace Poco { | namespace Poco { | ||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
| class MongoDB_API Array : public Document |  | ||||||
| 	/// Implements the BSON Array | class MongoDB_API Array: public Document | ||||||
|  | 	/// This class represents a BSON Array. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	typedef SharedPtr<Array> Ptr; | 	typedef SharedPtr<Array> Ptr; | ||||||
|  |  | ||||||
| 	Array(); | 	Array(); | ||||||
| 		/// Constructor | 		/// Creates an empty Array. | ||||||
|  |  | ||||||
| 	virtual ~Array(); | 	virtual ~Array(); | ||||||
| 		/// Destructor | 		/// Destroys the Array. | ||||||
|  |  | ||||||
| 	template<typename T> | 	template<typename T> | ||||||
| 	T get(int pos) const | 	T get(int pos) const | ||||||
| 		/// Returns the element on the given index and tries to convert | 		/// Returns the element at the given index and tries to convert | ||||||
| 		/// it to the template type. When the element is not found, a | 		/// it to the template type. If the element is not found, a | ||||||
| 		/// NotFoundException will be thrown. When the element can't be | 		/// Poco::NotFoundException will be thrown. If the element cannot be | ||||||
| 		/// converted a BadCastException will be thrown. | 		/// converted a BadCastException will be thrown. | ||||||
| 	{ | 	{ | ||||||
| 		return Document::get<T>(Poco::NumberFormatter::format(pos)); | 		return Document::get<T>(Poco::NumberFormatter::format(pos)); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	template<typename T> | 	template<typename T> | ||||||
| 	T get(int pos, const T& def) const | 	T get(int pos, const T& deflt) const | ||||||
| 		/// Returns the element on the given index and tries to convert | 		/// Returns the element at the given index and tries to convert | ||||||
| 		/// it to the template type. When the element is not found, or | 		/// it to the template type. If the element is not found, or | ||||||
| 		/// has the wrong type, the def argument will be returned. | 		/// has the wrong type, the deflt argument will be returned. | ||||||
| 	{ | 	{ | ||||||
| 		return Document::get<T>(Poco::NumberFormatter::format(pos), def); | 		return Document::get<T>(Poco::NumberFormatter::format(pos), deflt); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	Element::Ptr get(int pos) const; | 	Element::Ptr get(int pos) const; | ||||||
| 		/// Returns the element on the given index. | 		/// Returns the element at the given index. | ||||||
| 		/// An empty element will be returned when the element is not found. | 		/// An empty element will be returned if the element is not found. | ||||||
|  |  | ||||||
| 	template<typename T> | 	template<typename T> | ||||||
| 	bool isType(int pos) const | 	bool isType(int pos) const | ||||||
| 		/// Returns true when the type of the element equals the TypeId of ElementTrait | 		/// Returns true if the type of the element equals the TypeId of ElementTrait, | ||||||
|  | 		/// otherwise false. | ||||||
| 	{ | 	{ | ||||||
| 		return Document::isType<T>(Poco::NumberFormatter::format(pos)); | 		return Document::isType<T>(Poco::NumberFormatter::format(pos)); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	std::string toString(int indent = 0) const; | 	std::string toString(int indent = 0) const; | ||||||
|  | 		/// Returns a string representation of the Array. | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
| // BSON Embedded Array | // BSON Embedded Array | ||||||
| // spec: document | // spec: document | ||||||
| template<> | template<> | ||||||
| @@ -103,4 +109,4 @@ inline void BSONWriter::write<Array::Ptr>(Array::Ptr& from) | |||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_Array_INCLUDED | #endif // MongoDB_Array_INCLUDED | ||||||
|   | |||||||
| @@ -29,16 +29,17 @@ namespace MongoDB { | |||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API BSONReader | class MongoDB_API BSONReader | ||||||
| 	/// Class for reading BSON from a Poco::BinaryReader | 	/// Class for reading BSON using a Poco::BinaryReader | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	BSONReader(const Poco::BinaryReader& reader) : _reader(reader) | 	BSONReader(const Poco::BinaryReader& reader): | ||||||
| 		/// Constructor | 		_reader(reader) | ||||||
|  | 		/// Creates the BSONReader using the given BinaryWriter. | ||||||
| 	{ | 	{ | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	virtual ~BSONReader() | 	virtual ~BSONReader() | ||||||
| 		/// Destructor | 		/// Destroys the BSONReader. | ||||||
| 	{ | 	{ | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -55,11 +56,13 @@ public: | |||||||
| 		/// A cstring is a string terminated with a 0x00. | 		/// A cstring is a string terminated with a 0x00. | ||||||
|  |  | ||||||
| private: | private: | ||||||
|  |  | ||||||
| 	Poco::BinaryReader _reader; | 	Poco::BinaryReader _reader; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
| inline std::string BSONReader::readCString() | inline std::string BSONReader::readCString() | ||||||
| { | { | ||||||
| 	std::string val; | 	std::string val; | ||||||
|   | |||||||
| @@ -29,16 +29,17 @@ namespace MongoDB { | |||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API BSONWriter | class MongoDB_API BSONWriter | ||||||
| 	/// Class for writing BSON to a Poco::BinaryWriter. | 	/// Class for writing BSON using a Poco::BinaryWriter. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	BSONWriter(const Poco::BinaryWriter& writer) : _writer(writer) | 	BSONWriter(const Poco::BinaryWriter& writer):  | ||||||
| 		/// Constructor | 		_writer(writer) | ||||||
|  | 		/// Creates the BSONWriter. | ||||||
| 	{ | 	{ | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	virtual ~BSONWriter() | 	virtual ~BSONWriter() | ||||||
| 		/// Destructor | 		/// Destroys the BSONWriter. | ||||||
| 	{ | 	{ | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -52,13 +53,16 @@ public: | |||||||
|  |  | ||||||
| 	void writeCString(const std::string& value); | 	void writeCString(const std::string& value); | ||||||
| 		/// Writes a cstring to the writer. A cstring is a string | 		/// Writes a cstring to the writer. A cstring is a string | ||||||
| 		/// terminated with 0x00 | 		/// terminated a null character. | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	Poco::BinaryWriter _writer; | 	Poco::BinaryWriter _writer; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
| inline void BSONWriter::writeCString(const std::string& value) | inline void BSONWriter::writeCString(const std::string& value) | ||||||
| { | { | ||||||
| 	_writer.writeRaw(value); | 	_writer.writeRaw(value); | ||||||
|   | |||||||
| @@ -35,47 +35,49 @@ namespace MongoDB { | |||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API Binary | class MongoDB_API Binary | ||||||
| 	/// Implements BSON Binary. It's a wrapper around a Poco::Buffer<unsigned char>. | 	/// Implements BSON Binary. | ||||||
|  | 	/// | ||||||
|  | 	/// A Binary stores its data in a Poco::Buffer<unsigned char>. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	typedef SharedPtr<Binary> Ptr; | 	typedef SharedPtr<Binary> Ptr; | ||||||
|  |  | ||||||
| 	Binary(); | 	Binary(); | ||||||
| 		/// Constructor | 		/// Creates an empty Binary with subtype 0. | ||||||
|  |  | ||||||
| 	Binary(Poco::Int32 size, unsigned char subtype); | 	Binary(Poco::Int32 size, unsigned char subtype); | ||||||
| 		/// Constructor | 		/// Creates a Binary with a buffer of the given size and the given subtype. | ||||||
|  |  | ||||||
| 	Binary(const UUID& uuid); | 	Binary(const UUID& uuid); | ||||||
| 		/// Constructor for setting a UUID in a binary element | 		/// Creates a Binary containing an UUID. | ||||||
| 		 | 		 | ||||||
| 	Binary(const std::string& data, unsigned char subtype = 0); | 	Binary(const std::string& data, unsigned char subtype = 0); | ||||||
| 		/// Constructor for getting binary data from a string. | 		/// Creates a Binary with the contents of the given string and the given subtype. | ||||||
| 		 | 		 | ||||||
| 	Binary(const void* data, Poco::Int32 size, unsigned char subtype = 0); | 	Binary(const void* data, Poco::Int32 size, unsigned char subtype = 0); | ||||||
| 		/// Constructor for getting binary data from a buffer.		 | 		/// Creates a Binary with the contents of the given buffer and the given subtype.		 | ||||||
|  |  | ||||||
| 	virtual ~Binary(); | 	virtual ~Binary(); | ||||||
| 		/// Destructor | 		/// Destroys the Binary. | ||||||
|  |  | ||||||
| 	Buffer<unsigned char>& buffer(); | 	Buffer<unsigned char>& buffer(); | ||||||
| 		/// Returns a reference to the buffer | 		/// Returns a reference to the internal buffer | ||||||
|  |  | ||||||
| 	unsigned char subtype() const; | 	unsigned char subtype() const; | ||||||
| 		/// Returns the subtype | 		/// Returns the subtype. | ||||||
|  |  | ||||||
| 	void subtype(unsigned char type); | 	void subtype(unsigned char type); | ||||||
| 		/// Sets the subtype | 		/// Sets the subtype. | ||||||
|  |  | ||||||
| 	std::string toString(int indent = 0) const; | 	std::string toString(int indent = 0) const; | ||||||
| 		/// Returns the binary encoded in Base64 | 		/// Returns the contents of the Binary as Base64-encoded string. | ||||||
| 		 | 		 | ||||||
| 	std::string toRawString() const; | 	std::string toRawString() const; | ||||||
| 		/// Returns the raw content as a string. | 		/// Returns the raw content of the Binary as a string. | ||||||
|  |  | ||||||
| 	UUID uuid() const; | 	UUID uuid() const; | ||||||
| 		/// Returns the UUID when the binary subtype is 0x04. | 		/// Returns the UUID when the binary subtype is 0x04. | ||||||
| 		/// Otherwise BadCastException will be thrown | 		/// Otherwise, throws a Poco::BadCastException. | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	Buffer<unsigned char> _buffer; | 	Buffer<unsigned char> _buffer; | ||||||
| @@ -83,6 +85,9 @@ private: | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
| inline unsigned char Binary::subtype() const | inline unsigned char Binary::subtype() const | ||||||
| { | { | ||||||
| 	return _subtype; | 	return _subtype; | ||||||
|   | |||||||
| @@ -33,60 +33,80 @@ namespace MongoDB { | |||||||
|  |  | ||||||
| class MongoDB_API Connection | class MongoDB_API Connection | ||||||
| 	/// Represents a connection to a MongoDB server | 	/// Represents a connection to a MongoDB server | ||||||
|  | 	/// using the MongoDB wire protocol. | ||||||
|  | 	///  | ||||||
|  | 	/// See https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/ | ||||||
|  | 	/// for more information on the wire protocol. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	typedef Poco::SharedPtr<Connection> Ptr; | 	typedef Poco::SharedPtr<Connection> Ptr; | ||||||
|  |  | ||||||
| 	Connection(); | 	Connection(); | ||||||
| 		/// Default constructor. Use this when you want to | 		/// Creates an unconnected Connection. | ||||||
| 		/// connect later on. | 		/// | ||||||
|  | 		/// Use this when you want to connect later on. | ||||||
|  |  | ||||||
| 	Connection(const std::string& hostAndPort); | 	Connection(const std::string& hostAndPort); | ||||||
| 		/// Constructor which connects to the given MongoDB host/port. | 		/// Creates a Connection connected to the given MongoDB instance at host:port. | ||||||
|  | 		/// | ||||||
| 		/// The host and port must be separated with a colon. | 		/// The host and port must be separated with a colon. | ||||||
|  |  | ||||||
| 	Connection(const std::string& host, int port); | 	Connection(const std::string& host, int port); | ||||||
| 		/// Constructor which connects to the given MongoDB host/port. | 		/// Creates a Connection connected to the given MongoDB instance at host and port. | ||||||
|  |  | ||||||
| 	Connection(const Net::SocketAddress& addrs); | 	Connection(const Poco::Net::SocketAddress& addrs); | ||||||
| 		/// Constructor which connects to the given MongoDB host/port. | 		/// Creates a Connection connected to the given MongoDB instance at the given address. | ||||||
|  |  | ||||||
|  | 	Connection(const Poco::Net::StreamSocket& socket); | ||||||
|  | 		/// Creates a Connection connected to the given MongoDB instance using the given socket, | ||||||
|  | 		/// which must already be connected. | ||||||
|  |  | ||||||
| 	virtual ~Connection(); | 	virtual ~Connection(); | ||||||
| 		/// Destructor | 		/// Destroys the Connection. | ||||||
|  |  | ||||||
| 	Net::SocketAddress address() const; | 	Poco::Net::SocketAddress address() const; | ||||||
| 		/// Returns the address of the MongoDB connection | 		/// Returns the address of the MongoDB server. | ||||||
|  |  | ||||||
| 	void connect(const std::string& hostAndPort); | 	void connect(const std::string& hostAndPort); | ||||||
| 		/// Connects to the given MongoDB server. The host and port must be separated | 		/// Connects to the given MongoDB server.  | ||||||
| 		/// with a colon. | 		/// | ||||||
|  | 		/// The host and port must be separated with a colon. | ||||||
|  |  | ||||||
| 	void connect(const std::string& host, int port); | 	void connect(const std::string& host, int port); | ||||||
| 		/// Connects to the given MongoDB server. | 		/// Connects to the given MongoDB server. | ||||||
|  |  | ||||||
| 	void connect(const Net::SocketAddress& addrs); | 	void connect(const Poco::Net::SocketAddress& addrs); | ||||||
| 		/// Connects to the given MongoDB server. | 		/// Connects to the given MongoDB server. | ||||||
| 		 | 		 | ||||||
|  | 	void connect(const Poco::Net::StreamSocket& socket); | ||||||
|  | 		/// Connects using an already connected socket. | ||||||
|  |  | ||||||
| 	void disconnect(); | 	void disconnect(); | ||||||
| 		/// Disconnects from the MongoDB server | 		/// Disconnects from the MongoDB server. | ||||||
|  |  | ||||||
| 	void sendRequest(RequestMessage& request); | 	void sendRequest(RequestMessage& request); | ||||||
| 		/// Sends a request to the MongoDB server | 		/// Sends a request to the MongoDB server. | ||||||
| 		/// Only use this when the request hasn't a response. | 		///  | ||||||
|  | 		/// Used for one-way requests without a response. | ||||||
|  |  | ||||||
| 	void sendRequest(RequestMessage& request, ResponseMessage& response); | 	void sendRequest(RequestMessage& request, ResponseMessage& response); | ||||||
| 		/// Sends a request to the MongoDB server and receives the response. | 		/// Sends a request to the MongoDB server and receives the response. | ||||||
| 		/// Use this when a response is expected: only a query or getmore | 		///  | ||||||
|  | 		/// Use this when a response is expected: only a "query" or "getmore" | ||||||
| 		/// request will return a response. | 		/// request will return a response. | ||||||
|  |  | ||||||
| private: | protected: | ||||||
| 	Net::SocketAddress _address; |  | ||||||
| 	Net::StreamSocket _socket; |  | ||||||
| 	void connect(); | 	void connect(); | ||||||
| 		/// Connects to the MongoDB server |  | ||||||
|  | private: | ||||||
|  | 	Poco::Net::SocketAddress _address; | ||||||
|  | 	Poco::Net::StreamSocket _socket; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
| inline Net::SocketAddress Connection::address() const | inline Net::SocketAddress Connection::address() const | ||||||
| { | { | ||||||
| 	return _address; | 	return _address; | ||||||
| @@ -96,4 +116,4 @@ inline Net::SocketAddress Connection::address() const | |||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_Connection_INCLUDED | #endif // MongoDB_Connection_INCLUDED | ||||||
|   | |||||||
| @@ -30,26 +30,27 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API Cursor : public Document | class MongoDB_API Cursor: public Document | ||||||
| 	/// Cursor is an helper class for querying multiple documents | 	/// Cursor is an helper class for querying multiple documents. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	Cursor(const std::string& dbname, const std::string& collectionName, QueryRequest::Flags flags = QueryRequest::QUERY_NONE); | 	Cursor(const std::string& dbname, const std::string& collectionName, QueryRequest::Flags flags = QueryRequest::QUERY_DEFAULT); | ||||||
| 		/// Constructor | 		/// Creates a Cursor for the given database and collection, using the specified flags. | ||||||
|  |  | ||||||
| 	Cursor(const std::string& fullCollectionName, QueryRequest::Flags flags = QueryRequest::QUERY_NONE); | 	Cursor(const std::string& fullCollectionName, QueryRequest::Flags flags = QueryRequest::QUERY_DEFAULT); | ||||||
| 		/// Constructor | 		/// Creates a Cursor for the given database and collection ("database.collection"), using the specified flags. | ||||||
|  |  | ||||||
| 	virtual ~Cursor(); | 	virtual ~Cursor(); | ||||||
| 		/// Destructor | 		/// Destroys the Cursor. | ||||||
|  |  | ||||||
| 	ResponseMessage& next(Connection& connection); | 	ResponseMessage& next(Connection& connection); | ||||||
| 		/// Try to get the next documents. As long as ResponseMessage has a | 		/// Tries to get the next documents. As long as ResponseMessage has a | ||||||
| 		/// cursor id next can be called to retrieve the next bunch of documents. | 		/// cursor ID next can be called to retrieve the next bunch of documents. | ||||||
| 		/// kill must be called when not all documents are needed. | 		/// | ||||||
|  | 		/// The cursor must be killed (see kill()) when not all documents are needed. | ||||||
|  |  | ||||||
| 	QueryRequest& query(); | 	QueryRequest& query(); | ||||||
| 		/// Returns the associated query | 		/// Returns the associated query. | ||||||
|  |  | ||||||
| 	void kill(Connection& connection); | 	void kill(Connection& connection); | ||||||
| 		/// Kills the cursor and reset it so that it can be reused. | 		/// Kills the cursor and reset it so that it can be reused. | ||||||
| @@ -60,6 +61,9 @@ private: | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
| inline QueryRequest& Cursor::query() | inline QueryRequest& Cursor::query() | ||||||
| { | { | ||||||
| 	return _query; | 	return _query; | ||||||
| @@ -69,4 +73,4 @@ inline QueryRequest& Cursor::query() | |||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_Cursor_INCLUDED | #endif // MongoDB_Cursor_INCLUDED | ||||||
|   | |||||||
| @@ -39,13 +39,13 @@ class MongoDB_API Database | |||||||
| 	/// the database. | 	/// the database. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	Database(const std::string& db); | 	explicit Database(const std::string& name); | ||||||
| 		/// Constructor | 		/// Creates a Database for the database with the given name. | ||||||
|  |  | ||||||
| 	virtual ~Database(); | 	virtual ~Database(); | ||||||
| 		/// Destructor | 		/// Destroys the Database. | ||||||
| 		 | 		 | ||||||
| 	bool authenticate(Connection& connection, const std::string& username, const std::string& password, const std::string& method = AUTH_MONGODB_CR); | 	bool authenticate(Connection& connection, const std::string& username, const std::string& password, const std::string& method = AUTH_SCRAM_SHA1); | ||||||
| 		/// Authenticates against the database using the given connection, | 		/// Authenticates against the database using the given connection, | ||||||
| 		/// username and password, as well as authentication method. | 		/// username and password, as well as authentication method. | ||||||
| 		/// | 		/// | ||||||
| @@ -54,31 +54,37 @@ public: | |||||||
| 		/// authentication methods. | 		/// authentication methods. | ||||||
| 		/// | 		/// | ||||||
| 		/// Returns true if authentication was successful, otherwise false. | 		/// Returns true if authentication was successful, otherwise false. | ||||||
|  | 		/// | ||||||
|  | 		/// May throw a Poco::ProtocolException if authentication fails for a reason other than | ||||||
|  | 		/// invalid credentials. | ||||||
|  |  | ||||||
| 	Int64 count(Connection& connection, const std::string& collectionName) const; | 	Int64 count(Connection& connection, const std::string& collectionName) const; | ||||||
| 		/// Sends a count request for the given collection to MongoDB. When | 		/// Sends a count request for the given collection to MongoDB.  | ||||||
| 		/// the command fails, -1 is returned. | 		/// | ||||||
|  | 		/// If the command fails, -1 is returned. | ||||||
|  |  | ||||||
| 	Poco::SharedPtr<Poco::MongoDB::QueryRequest> createCommand() const; | 	Poco::SharedPtr<Poco::MongoDB::QueryRequest> createCommand() const; | ||||||
| 		/// Creates a QueryRequest for a command. | 		/// Creates a QueryRequest for a command. | ||||||
|  |  | ||||||
| 	Poco::SharedPtr<Poco::MongoDB::QueryRequest> createCountRequest(const std::string& collectionName) const; | 	Poco::SharedPtr<Poco::MongoDB::QueryRequest> createCountRequest(const std::string& collectionName) const; | ||||||
| 		/// Creates a QueryRequest to count the given collection. The collectionname must not contain | 		/// Creates a QueryRequest to count the given collection.  | ||||||
| 		/// the database name! | 		/// The collectionname must not contain the database name. | ||||||
|  |  | ||||||
| 	Poco::SharedPtr<Poco::MongoDB::DeleteRequest> createDeleteRequest(const std::string& collectionName) const; | 	Poco::SharedPtr<Poco::MongoDB::DeleteRequest> createDeleteRequest(const std::string& collectionName) const; | ||||||
| 		/// Creates a DeleteRequest to delete documents in the given collection. | 		/// Creates a DeleteRequest to delete documents in the given collection. | ||||||
| 		/// The collectionname must not contain the database name! | 		/// The collectionname must not contain the database name. | ||||||
|  |  | ||||||
| 	Poco::SharedPtr<Poco::MongoDB::InsertRequest> createInsertRequest(const std::string& collectionName) const; | 	Poco::SharedPtr<Poco::MongoDB::InsertRequest> createInsertRequest(const std::string& collectionName) const; | ||||||
| 		/// Creates an InsertRequest to insert new documents in the given collection. | 		/// Creates an InsertRequest to insert new documents in the given collection. | ||||||
| 		/// The collectionname must not contain the database name! | 		/// The collectionname must not contain the database name. | ||||||
|  |  | ||||||
| 	Poco::SharedPtr<Poco::MongoDB::QueryRequest> createQueryRequest(const std::string& collectionName) const; | 	Poco::SharedPtr<Poco::MongoDB::QueryRequest> createQueryRequest(const std::string& collectionName) const; | ||||||
| 		/// Creates a QueryRequest. The collectionname must not contain the database name! | 		/// Creates a QueryRequest.  | ||||||
|  | 		/// The collectionname must not contain the database name. | ||||||
|  |  | ||||||
| 	Poco::SharedPtr<Poco::MongoDB::UpdateRequest> createUpdateRequest(const std::string& collectionName) const; | 	Poco::SharedPtr<Poco::MongoDB::UpdateRequest> createUpdateRequest(const std::string& collectionName) const; | ||||||
| 		/// Creates an UpdateRequest. The collectionname must not contain the database name! | 		/// Creates an UpdateRequest.  | ||||||
|  | 		/// The collectionname must not contain the database name. | ||||||
|  |  | ||||||
| 	Poco::MongoDB::Document::Ptr ensureIndex(Connection& connection, | 	Poco::MongoDB::Document::Ptr ensureIndex(Connection& connection, | ||||||
| 		const std::string& collection, | 		const std::string& collection, | ||||||
| @@ -92,7 +98,7 @@ public: | |||||||
| 		/// For more info look at the ensureIndex information on the MongoDB website. | 		/// For more info look at the ensureIndex information on the MongoDB website. | ||||||
|  |  | ||||||
| 	Document::Ptr getLastErrorDoc(Connection& connection) const; | 	Document::Ptr getLastErrorDoc(Connection& connection) const; | ||||||
| 		/// Sends the getLastError command to the database and returns the document | 		/// Sends the getLastError command to the database and returns the error document. | ||||||
|  |  | ||||||
| 	std::string getLastError(Connection& connection) const; | 	std::string getLastError(Connection& connection) const; | ||||||
| 		/// Sends the getLastError command to the database and returns the err element | 		/// Sends the getLastError command to the database and returns the err element | ||||||
| @@ -113,6 +119,9 @@ private: | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
| inline Poco::SharedPtr<Poco::MongoDB::QueryRequest> Database::createCommand() const | inline Poco::SharedPtr<Poco::MongoDB::QueryRequest> Database::createCommand() const | ||||||
| { | { | ||||||
| 	Poco::SharedPtr<Poco::MongoDB::QueryRequest> cmd = createQueryRequest("$cmd"); | 	Poco::SharedPtr<Poco::MongoDB::QueryRequest> cmd = createQueryRequest("$cmd"); | ||||||
|   | |||||||
| @@ -29,51 +29,57 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API DeleteRequest : public RequestMessage | class MongoDB_API DeleteRequest: public RequestMessage | ||||||
| 	/// Class for creating an OP_DELETE client request. This request | 	/// A DeleteRequest is used to delete one ore more documents from a database. | ||||||
| 	/// is used to delete one ore more documents from a database. |  | ||||||
| 	/// | 	/// | ||||||
| 	/// Specific flags for this request | 	/// Specific flags for this request | ||||||
| 	///  - DELETE_NONE | 	///   - DELETE_DEFAULT: default delete operation | ||||||
| 	///      No flags | 	///   - DELETE_SINGLE_REMOVE: delete only the first document | ||||||
| 	///  - DELETE_SINGLE_REMOVE |  | ||||||
| 	///      Delete only the first document |  | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	typedef enum | 	enum Flags | ||||||
| 	{ | 	{ | ||||||
| 		DELETE_NONE = 0, | 		DELETE_DEFAULT = 0, | ||||||
| 		DELETE_SINGLE_REMOVE = 1 | 			/// Default | ||||||
| 	} Flags; |  | ||||||
|  |  | ||||||
| 	DeleteRequest(const std::string& collectionName, Flags flags = DELETE_NONE); | 		DELETE_SINGLE_REMOVE = 1 | ||||||
| 		/// Constructor. The full collection name is the concatenation of the database  | 			/// Delete only the first document. | ||||||
|  | 	}; | ||||||
|  |  | ||||||
|  | 	DeleteRequest(const std::string& collectionName, Flags flags = DELETE_DEFAULT); | ||||||
|  | 		/// Creates a DeleteRequest for the given collection using the given flags.  | ||||||
|  | 		/// | ||||||
|  | 		/// The full collection name is the concatenation of the database  | ||||||
| 		/// name with the collection name, using a "." for the concatenation. For example,  | 		/// name with the collection name, using a "." for the concatenation. For example,  | ||||||
| 		/// for the database "foo" and the collection "bar", the full collection name is  | 		/// for the database "foo" and the collection "bar", the full collection name is  | ||||||
| 		/// "foo.bar". | 		/// "foo.bar". | ||||||
|  |  | ||||||
| 	DeleteRequest(const std::string& collectionName, bool justOne); | 	DeleteRequest(const std::string& collectionName, bool justOne); | ||||||
| 		/// Constructor. The full collection name is the concatenation of the database | 		/// Creates a DeleteRequest for the given collection. | ||||||
|  | 		///  | ||||||
|  | 		/// The full collection name is the concatenation of the database | ||||||
| 		/// name with the collection name, using a "." for the concatenation. For example, | 		/// name with the collection name, using a "." for the concatenation. For example, | ||||||
| 		/// for the database "foo" and the collection "bar", the full collection name is | 		/// for the database "foo" and the collection "bar", the full collection name is | ||||||
| 		/// "foo.bar". When justOne is true, only the first matching document will | 		/// "foo.bar".  | ||||||
|  | 		/// | ||||||
|  | 		/// If justOne is true, only the first matching document will | ||||||
| 		/// be removed (the same as using flag DELETE_SINGLE_REMOVE). | 		/// be removed (the same as using flag DELETE_SINGLE_REMOVE). | ||||||
|  |  | ||||||
| 	virtual ~DeleteRequest(); | 	virtual ~DeleteRequest(); | ||||||
| 		/// Destructor | 		/// Destructor | ||||||
|  |  | ||||||
| 	Flags flags() const; | 	Flags flags() const; | ||||||
| 		/// Returns flags | 		/// Returns the flags. | ||||||
|  |  | ||||||
| 	void flags(Flags flag); | 	void flags(Flags flag); | ||||||
| 		/// Sets flags | 		/// Sets the flags. | ||||||
|  |  | ||||||
| 	Document& selector(); | 	Document& selector(); | ||||||
| 		/// Returns the selector document | 		/// Returns the selector document. | ||||||
|  |  | ||||||
| protected: | protected: | ||||||
| 	void buildRequest(BinaryWriter& writer); | 	void buildRequest(BinaryWriter& writer); | ||||||
| 		/// Writes the OP_DELETE request to the writer | 		/// Writes the OP_DELETE request to the writer. | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	Flags       _flags; | 	Flags       _flags; | ||||||
| @@ -82,6 +88,9 @@ private: | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /// | ||||||
|  | /// inlines | ||||||
|  | /// | ||||||
| inline DeleteRequest::Flags DeleteRequest::flags() const | inline DeleteRequest::Flags DeleteRequest::flags() const | ||||||
| { | { | ||||||
| 	return _flags; | 	return _flags; | ||||||
| @@ -103,4 +112,4 @@ inline Document& DeleteRequest::selector() | |||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_DeleteRequest_INCLUDED | #endif // MongoDB_DeleteRequest_INCLUDED | ||||||
|   | |||||||
| @@ -25,6 +25,7 @@ | |||||||
| #include "Poco/MongoDB/MongoDB.h" | #include "Poco/MongoDB/MongoDB.h" | ||||||
| #include "Poco/MongoDB/Element.h" | #include "Poco/MongoDB/Element.h" | ||||||
| #include <algorithm> | #include <algorithm> | ||||||
|  | #include <cstdlib> | ||||||
|  |  | ||||||
|  |  | ||||||
| namespace Poco { | namespace Poco { | ||||||
| @@ -34,7 +35,8 @@ namespace MongoDB { | |||||||
| class ElementFindByName | class ElementFindByName | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	ElementFindByName(const std::string& name) : _name(name) | 	ElementFindByName(const std::string& name):  | ||||||
|  | 		_name(name) | ||||||
| 	{ | 	{ | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -49,26 +51,28 @@ private: | |||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API Document | class MongoDB_API Document | ||||||
| 	/// Represents a BSON document | 	/// Represents a MongoDB (BSON) document. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	typedef SharedPtr<Document> Ptr; | 	typedef SharedPtr<Document> Ptr; | ||||||
| 	typedef std::vector<Document::Ptr> Vector; | 	typedef std::vector<Document::Ptr> Vector; | ||||||
|  |  | ||||||
| 	Document(); | 	Document(); | ||||||
| 		/// Constructor | 		/// Creates an empty Document. | ||||||
|  |  | ||||||
| 	virtual ~Document(); | 	virtual ~Document(); | ||||||
| 		/// Destructor | 		/// Destroys the Document. | ||||||
|  |  | ||||||
| 	Document& addElement(Element::Ptr element); | 	Document& addElement(Element::Ptr element); | ||||||
| 		/// Add an element to the document. | 		/// Add an element to the document. | ||||||
|  | 		/// | ||||||
| 		/// The active document is returned to allow chaining of the add methods. | 		/// The active document is returned to allow chaining of the add methods. | ||||||
|  |  | ||||||
| 	template<typename T> | 	template<typename T> | ||||||
| 	Document& add(const std::string& name, T value) | 	Document& add(const std::string& name, T value) | ||||||
| 		/// Creates an element with the given name and value and | 		/// Creates an element with the given name and value and | ||||||
| 		/// adds it to the document. | 		/// adds it to the document. | ||||||
|  | 		/// | ||||||
| 		/// The active document is returned to allow chaining of the add methods. | 		/// The active document is returned to allow chaining of the add methods. | ||||||
| 	{ | 	{ | ||||||
| 		return addElement(new ConcreteElement<T>(name, value)); | 		return addElement(new ConcreteElement<T>(name, value)); | ||||||
| @@ -77,6 +81,7 @@ public: | |||||||
| 	Document& add(const std::string& name, const char* value) | 	Document& add(const std::string& name, const char* value) | ||||||
| 		/// Creates an element with the given name and value and | 		/// Creates an element with the given name and value and | ||||||
| 		/// adds it to the document. | 		/// adds it to the document. | ||||||
|  | 		/// | ||||||
| 		/// The active document is returned to allow chaining of the add methods. | 		/// The active document is returned to allow chaining of the add methods. | ||||||
| 	{ | 	{ | ||||||
| 		return addElement(new ConcreteElement<std::string>(name, std::string(value))); | 		return addElement(new ConcreteElement<std::string>(name, std::string(value))); | ||||||
| @@ -94,10 +99,10 @@ public: | |||||||
| 		/// Puts all element names into std::vector. | 		/// Puts all element names into std::vector. | ||||||
|  |  | ||||||
| 	bool empty() const; | 	bool empty() const; | ||||||
| 		/// Returns true when the document doesn't contain any documents. | 		/// Returns true if the document doesn't contain any documents. | ||||||
|  |  | ||||||
| 	bool exists(const std::string& name); | 	bool exists(const std::string& name); | ||||||
| 		/// Returns true when the document has an element with the given name | 		/// Returns true if the document has an element with the given name. | ||||||
|  |  | ||||||
| 	template<typename T> | 	template<typename T> | ||||||
| 	T get(const std::string& name) const | 	T get(const std::string& name) const | ||||||
| @@ -107,16 +112,16 @@ public: | |||||||
| 		/// converted a BadCastException will be thrown. | 		/// converted a BadCastException will be thrown. | ||||||
| 	{ | 	{ | ||||||
| 		Element::Ptr element = get(name); | 		Element::Ptr element = get(name); | ||||||
| 		if ( element.isNull() ) | 		if (element.isNull()) | ||||||
| 		{ | 		{ | ||||||
| 			throw NotFoundException(name); | 			throw NotFoundException(name); | ||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
| 		{ | 		{ | ||||||
| 			if ( ElementTraits<T>::TypeId == element->type() ) | 			if (ElementTraits<T>::TypeId == element->type()) | ||||||
| 			{ | 			{ | ||||||
| 				ConcreteElement<T>* concrete = dynamic_cast<ConcreteElement<T>* >(element.get()); | 				ConcreteElement<T>* concrete = dynamic_cast<ConcreteElement<T>* >(element.get()); | ||||||
| 				if ( concrete != NULL ) | 				if (concrete != 0) | ||||||
| 				{ | 				{ | ||||||
| 					return concrete->value(); | 					return concrete->value(); | ||||||
| 				} | 				} | ||||||
| @@ -132,15 +137,15 @@ public: | |||||||
| 		/// has the wrong type, the def argument will be returned. | 		/// has the wrong type, the def argument will be returned. | ||||||
| 	{ | 	{ | ||||||
| 		Element::Ptr element = get(name); | 		Element::Ptr element = get(name); | ||||||
| 		if ( element.isNull() ) | 		if (element.isNull()) | ||||||
| 		{ | 		{ | ||||||
| 			return def; | 			return def; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if ( ElementTraits<T>::TypeId == element->type() ) | 		if (ElementTraits<T>::TypeId == element->type()) | ||||||
| 		{ | 		{ | ||||||
| 			ConcreteElement<T>* concrete = dynamic_cast<ConcreteElement<T>* >(element.get()); | 			ConcreteElement<T>* concrete = dynamic_cast<ConcreteElement<T>* >(element.get()); | ||||||
| 			if ( concrete != NULL ) | 			if (concrete != 0) | ||||||
| 			{ | 			{ | ||||||
| 				return concrete->value(); | 				return concrete->value(); | ||||||
| 			} | 			} | ||||||
| @@ -154,17 +159,17 @@ public: | |||||||
| 		/// An empty element will be returned when the element is not found. | 		/// An empty element will be returned when the element is not found. | ||||||
|  |  | ||||||
| 	Int64 getInteger(const std::string& name) const; | 	Int64 getInteger(const std::string& name) const; | ||||||
| 		/// Returns an integer. Useful when MongoDB returns int32, int64 | 		/// Returns an integer. Useful when MongoDB returns Int32, Int64 | ||||||
| 		/// or double for a number (count for example). This method will always | 		/// or double for a number (count for example). This method will always | ||||||
| 		/// return an Int64. When the element is not found, a | 		/// return an Int64. When the element is not found, a | ||||||
| 		/// NotFoundException will be thrown. | 		/// Poco::NotFoundException will be thrown. | ||||||
|  |  | ||||||
| 	template<typename T> | 	template<typename T> | ||||||
| 	bool isType(const std::string& name) const | 	bool isType(const std::string& name) const | ||||||
| 		/// Returns true when the type of the element equals the TypeId of ElementTrait | 		/// Returns true when the type of the element equals the TypeId of ElementTrait. | ||||||
| 	{ | 	{ | ||||||
| 		Element::Ptr element = get(name); | 		Element::Ptr element = get(name); | ||||||
| 		if ( element.isNull() ) | 		if (element.isNull()) | ||||||
| 		{ | 		{ | ||||||
| 			return false; | 			return false; | ||||||
| 		} | 		} | ||||||
| @@ -175,7 +180,7 @@ public: | |||||||
| 	void read(BinaryReader& reader); | 	void read(BinaryReader& reader); | ||||||
| 		/// Reads a document from the reader | 		/// Reads a document from the reader | ||||||
|  |  | ||||||
| 	size_t size() const; | 	std::size_t size() const; | ||||||
| 		/// Returns the number of elements in the document. | 		/// Returns the number of elements in the document. | ||||||
|  |  | ||||||
| 	virtual std::string toString(int indent = 0) const; | 	virtual std::string toString(int indent = 0) const; | ||||||
| @@ -189,6 +194,9 @@ protected: | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
| inline Document& Document::addElement(Element::Ptr element) | inline Document& Document::addElement(Element::Ptr element) | ||||||
| { | { | ||||||
| 	_elements.push_back(element); | 	_elements.push_back(element); | ||||||
| @@ -218,7 +226,7 @@ inline bool Document::empty() const | |||||||
|  |  | ||||||
| inline void Document::elementNames(std::vector<std::string>& keys) const | inline void Document::elementNames(std::vector<std::string>& keys) const | ||||||
| { | { | ||||||
| 	for(ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it) | 	for (ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it) | ||||||
| 	{ | 	{ | ||||||
| 		keys.push_back((*it)->name()); | 		keys.push_back((*it)->name()); | ||||||
| 	} | 	} | ||||||
| @@ -231,7 +239,7 @@ inline bool Document::exists(const std::string& name) | |||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| inline size_t Document::size() const | inline std::size_t Document::size() const | ||||||
| { | { | ||||||
| 	return _elements.size(); | 	return _elements.size(); | ||||||
| } | } | ||||||
| @@ -264,6 +272,7 @@ inline void BSONWriter::write<Document::Ptr>(Document::Ptr& from) | |||||||
| 	from->write(_writer); | 	from->write(_writer); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -42,19 +42,19 @@ namespace MongoDB { | |||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API Element | class MongoDB_API Element | ||||||
| 	/// Represents an element of a Document or an Array | 	/// Represents an Element of a Document or an Array. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	typedef Poco::SharedPtr<Element> Ptr; | 	typedef Poco::SharedPtr<Element> Ptr; | ||||||
|  |  | ||||||
| 	Element(const std::string& name); | 	explicit Element(const std::string& name); | ||||||
| 		/// Constructor | 		/// Creates the Element with the given name. | ||||||
|  |  | ||||||
| 	virtual ~Element(); | 	virtual ~Element(); | ||||||
| 		/// Destructor | 		/// Destructor | ||||||
|  |  | ||||||
| 	std::string name() const; | 	const std::string& name() const; | ||||||
| 		/// Returns the name of the element | 		/// Returns the name of the element. | ||||||
|  |  | ||||||
| 	virtual std::string toString(int indent = 0) const = 0; | 	virtual std::string toString(int indent = 0) const = 0; | ||||||
| 		/// Returns a string representation of the element. | 		/// Returns a string representation of the element. | ||||||
| @@ -71,7 +71,10 @@ private: | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
| inline std::string Element::name() const | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
|  | inline const std::string& Element::name() const | ||||||
| { | { | ||||||
| 	return _name; | 	return _name; | ||||||
| } | } | ||||||
| @@ -114,7 +117,7 @@ struct ElementTraits<std::string> | |||||||
|  |  | ||||||
| 		oss << '"'; | 		oss << '"'; | ||||||
|  |  | ||||||
| 		for(std::string::const_iterator it = value.begin(); it != value.end(); ++it) | 		for (std::string::const_iterator it = value.begin(); it != value.end(); ++it) | ||||||
| 		{ | 		{ | ||||||
| 			switch (*it) | 			switch (*it) | ||||||
| 			{ | 			{ | ||||||
| @@ -350,10 +353,12 @@ struct ElementTraits<Int64> | |||||||
|  |  | ||||||
|  |  | ||||||
| template<typename T> | template<typename T> | ||||||
| class ConcreteElement : public Element | class ConcreteElement: public Element | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	ConcreteElement(const std::string& name, const T& init) : Element(name), _value(init) | 	ConcreteElement(const std::string& name, const T& init): | ||||||
|  | 		Element(name),  | ||||||
|  | 		_value(init) | ||||||
| 	{ | 	{ | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -28,31 +28,31 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API GetMoreRequest : public RequestMessage | class MongoDB_API GetMoreRequest: public RequestMessage | ||||||
| 	/// Class for creating an OP_GETMORE client request. This request is used | 	/// A GetMoreRequest is used to query the database for more documents in a collection  | ||||||
| 	/// to query the database for more documents in a collection after | 	/// after a query request is send (OP_GETMORE). | ||||||
| 	/// a query request is send. |  | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	GetMoreRequest(const std::string& collectionName, Int64 cursorID); | 	GetMoreRequest(const std::string& collectionName, Int64 cursorID); | ||||||
| 		/// Constructor. The full collection name is the concatenation of the database  | 		/// Creates a GetMoreRequest for the give collection and cursor.  | ||||||
|  | 		/// | ||||||
|  | 		/// The full collection name is the concatenation of the database  | ||||||
| 		/// name with the collection name, using a "." for the concatenation. For example,  | 		/// name with the collection name, using a "." for the concatenation. For example,  | ||||||
| 		/// for the database "foo" and the collection "bar", the full collection name is  | 		/// for the database "foo" and the collection "bar", the full collection name is  | ||||||
| 		/// "foo.bar". The cursorID has been returned by the response on the query request. | 		/// "foo.bar". The cursorID has been returned by the response on the query request. | ||||||
| 		/// By default the numberToReturn is set to 100. | 		/// By default the numberToReturn is set to 100. | ||||||
|  |  | ||||||
|  |  | ||||||
| 	virtual ~GetMoreRequest(); | 	virtual ~GetMoreRequest(); | ||||||
| 		/// Destructor | 		/// Destroys the GetMoreRequest. | ||||||
|  |  | ||||||
| 	Int32 getNumberToReturn() const; | 	Int32 getNumberToReturn() const; | ||||||
| 		/// Returns the limit of returned documents | 		/// Returns the limit of returned documents. | ||||||
|  |  | ||||||
| 	void setNumberToReturn(Int32 n); | 	void setNumberToReturn(Int32 n); | ||||||
| 		/// Sets the limit of returned documents | 		/// Sets the limit of returned documents. | ||||||
|  |  | ||||||
| 	Int64 cursorID() const; | 	Int64 cursorID() const; | ||||||
| 		/// Returns the cursor id | 		/// Returns the cursor ID. | ||||||
|  |  | ||||||
| protected: | protected: | ||||||
| 	void buildRequest(BinaryWriter& writer); | 	void buildRequest(BinaryWriter& writer); | ||||||
| @@ -88,4 +88,4 @@ inline Int64 GetMoreRequest::cursorID() const | |||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_GetMoreRequest_INCLUDED | #endif // MongoDB_GetMoreRequest_INCLUDED | ||||||
|   | |||||||
| @@ -29,26 +29,34 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API InsertRequest : public RequestMessage | class MongoDB_API InsertRequest: public RequestMessage | ||||||
| 	/// Class for creating an OP_INSERT client request. This request is used | 	/// A request for inserting one or more documents to the database | ||||||
| 	/// to insert one or more documents to the database. | 	/// (OP_INSERT). | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	typedef enum | 	enum Flags | ||||||
| 	{ | 	{ | ||||||
| 		INSERT_NONE = 0, | 		INSERT_DEFAULT = 0, | ||||||
| 		INSERT_CONTINUE_ON_ERROR = 1 | 			/// If specified, perform a normal insert operation. | ||||||
| 	} Flags; |  | ||||||
| 		 | 		 | ||||||
| 	InsertRequest(const std::string& collectionName, Flags flags = INSERT_NONE ); | 		INSERT_CONTINUE_ON_ERROR = 1 | ||||||
| 		/// Constructor. | 			/// If set, the database will not stop processing a bulk insert if one  | ||||||
|  | 			/// fails (e.g. due to duplicate IDs). This makes bulk insert behave similarly  | ||||||
|  | 			/// to a series of single inserts, except lastError will be set if any insert  | ||||||
|  | 			/// fails, not just the last one. If multiple errors occur, only the most  | ||||||
|  | 			/// recent will be reported. | ||||||
|  | 	}; | ||||||
|  |  | ||||||
|  | 	InsertRequest(const std::string& collectionName, Flags flags = INSERT_DEFAULT); | ||||||
|  | 		/// Creates an InsertRequest. | ||||||
|  | 		/// | ||||||
| 		/// The full collection name is the concatenation of the database  | 		/// The full collection name is the concatenation of the database  | ||||||
| 		/// name with the collection name, using a "." for the concatenation. For example,  | 		/// name with the collection name, using a "." for the concatenation. For example,  | ||||||
| 		/// for the database "foo" and the collection "bar", the full collection name is  | 		/// for the database "foo" and the collection "bar", the full collection name is  | ||||||
| 		/// "foo.bar". | 		/// "foo.bar". | ||||||
|  |  | ||||||
| 	virtual ~InsertRequest(); | 	virtual ~InsertRequest(); | ||||||
| 		/// Destructor | 		/// Destroys the InsertRequest. | ||||||
|  |  | ||||||
| 	Document& addNewDocument(); | 	Document& addNewDocument(); | ||||||
| 		/// Adds a new document for insertion. A reference to the empty document is | 		/// Adds a new document for insertion. A reference to the empty document is | ||||||
| @@ -56,20 +64,21 @@ public: | |||||||
| 		/// on destruction. | 		/// on destruction. | ||||||
|  |  | ||||||
| 	Document::Vector& documents(); | 	Document::Vector& documents(); | ||||||
| 		/// Returns the documents to insert into the database | 		/// Returns the documents to insert into the database. | ||||||
|  |  | ||||||
| protected: | protected: | ||||||
|  |  | ||||||
| 	void buildRequest(BinaryWriter& writer); | 	void buildRequest(BinaryWriter& writer); | ||||||
|  |  | ||||||
| private: | private: | ||||||
|  |  | ||||||
| 	Int32 _flags; | 	Int32 _flags; | ||||||
| 	std::string _fullCollectionName; | 	std::string _fullCollectionName; | ||||||
| 	Document::Vector _documents; | 	Document::Vector _documents; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
| inline Document& InsertRequest::addNewDocument() | inline Document& InsertRequest::addNewDocument() | ||||||
| { | { | ||||||
| 	Document::Ptr doc = new Document(); | 	Document::Ptr doc = new Document(); | ||||||
| @@ -87,4 +96,4 @@ inline Document::Vector& InsertRequest::documents() | |||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_InsertRequest_INCLUDED | #endif // MongoDB_InsertRequest_INCLUDED | ||||||
|   | |||||||
| @@ -32,31 +32,34 @@ namespace MongoDB { | |||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API JavaScriptCode | class MongoDB_API JavaScriptCode | ||||||
| 	/// Represents JavaScript type in BSON | 	/// Represents JavaScript type in BSON. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	typedef SharedPtr<JavaScriptCode> Ptr; | 	typedef SharedPtr<JavaScriptCode> Ptr; | ||||||
|  |  | ||||||
| 	JavaScriptCode(); | 	JavaScriptCode(); | ||||||
| 		/// Constructor | 		/// Creates an empty JavaScriptCode object. | ||||||
|  |  | ||||||
| 	virtual ~JavaScriptCode(); | 	virtual ~JavaScriptCode(); | ||||||
| 		/// Destructor | 		/// Destroys the JavaScriptCode. | ||||||
|  |  | ||||||
| 	void setCode(const std::string& s); | 	void setCode(const std::string& code); | ||||||
| 		/// Set the code | 		/// Sets the JavaScript code. | ||||||
|  |  | ||||||
| 	std::string getCode() const; | 	std::string getCode() const; | ||||||
| 		/// Get the code | 		/// Returns the JavaScript code. | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	std::string _code; | 	std::string _code; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
| inline void JavaScriptCode::setCode(const std::string& s) | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
|  | inline void JavaScriptCode::setCode(const std::string& code) | ||||||
| { | { | ||||||
| 	_code = s; | 	_code = code; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -65,6 +68,7 @@ inline std::string JavaScriptCode::getCode() const | |||||||
| 	return _code; | 	return _code; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| // BSON JavaScript code | // BSON JavaScript code | ||||||
| // spec: string | // spec: string | ||||||
| template<> | template<> | ||||||
|   | |||||||
| @@ -28,20 +28,20 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API KillCursorsRequest : public RequestMessage | class MongoDB_API KillCursorsRequest: public RequestMessage | ||||||
| 	/// Class for creating an OP_KILL_CURSORS client request. This | 	/// Class for creating an OP_KILL_CURSORS client request. This | ||||||
| 	/// request is used to kill cursors, which are still open,  | 	/// request is used to kill cursors, which are still open,  | ||||||
| 	/// returned by query requests. | 	/// returned by query requests. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	KillCursorsRequest(); | 	KillCursorsRequest(); | ||||||
| 		/// Constructor | 		/// Creates a KillCursorsRequest. | ||||||
|  |  | ||||||
| 	virtual ~KillCursorsRequest(); | 	virtual ~KillCursorsRequest(); | ||||||
| 		/// Destructor | 		/// Destroys the KillCursorsRequest. | ||||||
| 		 | 		 | ||||||
| 	std::vector<Int64>& cursors(); | 	std::vector<Int64>& cursors(); | ||||||
| 		/// Return the cursors | 		/// The internal list of cursors. | ||||||
| 		 | 		 | ||||||
| protected: | protected: | ||||||
| 	void buildRequest(BinaryWriter& writer); | 	void buildRequest(BinaryWriter& writer); | ||||||
| @@ -49,6 +49,9 @@ protected: | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
| inline std::vector<Int64>& KillCursorsRequest::cursors() | inline std::vector<Int64>& KillCursorsRequest::cursors() | ||||||
| { | { | ||||||
| 	return _cursors; | 	return _cursors; | ||||||
| @@ -58,4 +61,4 @@ inline std::vector<Int64>& KillCursorsRequest::cursors() | |||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_KillCursorsRequest_INCLUDED | #endif // MongoDB_KillCursorsRequest_INCLUDED | ||||||
|   | |||||||
| @@ -33,11 +33,11 @@ namespace MongoDB { | |||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API Message | class MongoDB_API Message | ||||||
| 	/// Base class for all messages send or retrieved from MongoDB server | 	/// Base class for all messages send or retrieved from MongoDB server. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	Message(MessageHeader::OpCode opcode); | 	explicit Message(MessageHeader::OpCode opcode); | ||||||
| 		/// Constructor | 		/// Creates a Message using the given OpCode. | ||||||
| 	 | 	 | ||||||
| 	virtual ~Message(); | 	virtual ~Message(); | ||||||
| 		/// Destructor | 		/// Destructor | ||||||
| @@ -53,6 +53,9 @@ protected: | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
| inline MessageHeader& Message::header() | inline MessageHeader& Message::header() | ||||||
| { | { | ||||||
| 	return _header; | 	return _header; | ||||||
| @@ -69,4 +72,4 @@ inline void Message::messageLength(Poco::Int32 length) | |||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_Message_INCLUDED | #endif // MongoDB_Message_INCLUDED | ||||||
|   | |||||||
| @@ -29,54 +29,54 @@ namespace MongoDB { | |||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API MessageHeader | class MongoDB_API MessageHeader | ||||||
| 	/// Represents the header which is always prepended to a request | 	/// Represents the message header which is always prepended to a  | ||||||
| 	/// or response of MongoDB | 	/// MongoDB request or response message. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	static const unsigned int MSG_HEADER_SIZE = 16; | 	static const unsigned int MSG_HEADER_SIZE = 16; | ||||||
|  |  | ||||||
| 	typedef enum | 	enum OpCode | ||||||
| 	{ | 	{ | ||||||
| 		  Reply = 1 | 		OP_REPLY = 1, | ||||||
| 		, Msg = 1000 | 		OP_MSG = 1000, | ||||||
| 		, Update = 2001 | 		OP_UPDATE = 2001, | ||||||
| 		, Insert = 2002 | 		OP_INSERT = 2002, | ||||||
| 		, Query = 2004 | 		OP_QUERY = 2004, | ||||||
| 		, GetMore = 2005 | 		OP_GET_MORE = 2005, | ||||||
| 		, Delete = 2006 | 		OP_DELETE = 2006, | ||||||
| 		, KillCursors = 2007 | 		OP_KILL_CURSORS = 2007 | ||||||
| 	} OpCode; | 	}; | ||||||
|  |  | ||||||
|  | 	explicit MessageHeader(OpCode); | ||||||
|  | 		/// Creates the MessageHeader using the given OpCode. | ||||||
|  |  | ||||||
| 	virtual ~MessageHeader(); | 	virtual ~MessageHeader(); | ||||||
| 		/// Destructor | 		/// Destroys the MessageHeader. | ||||||
|  |  | ||||||
| 	void read(BinaryReader& reader); | 	void read(BinaryReader& reader); | ||||||
| 		/// Reads the header | 		/// Reads the header using the given BinaryReader. | ||||||
|  |  | ||||||
| 	void write(BinaryWriter& writer); | 	void write(BinaryWriter& writer); | ||||||
| 		/// Writes the header | 		/// Writes the header using the given BinaryWriter. | ||||||
|  |  | ||||||
| 	Int32 getMessageLength() const; | 	Int32 getMessageLength() const; | ||||||
| 		/// Returns the message length | 		/// Returns the message length. | ||||||
|  |  | ||||||
| 	OpCode opCode() const; | 	OpCode opCode() const; | ||||||
| 		/// Returns the OpCode | 		/// Returns the OpCode. | ||||||
|  |  | ||||||
| 	Int32 getRequestID() const; | 	Int32 getRequestID() const; | ||||||
| 		/// Returns the request id of the current message | 		/// Returns the request ID of the current message. | ||||||
|  |  | ||||||
| 	void setRequestID(Int32 id); | 	void setRequestID(Int32 id); | ||||||
| 		/// Sets the request id of the current message | 		/// Sets the request ID of the current message. | ||||||
|  |  | ||||||
| 	Int32 responseTo() const; | 	Int32 responseTo() const; | ||||||
| 		/// Returns the request id from the original request.  | 		/// Returns the request id from the original request.  | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	MessageHeader(OpCode opcode); |  | ||||||
| 		/// Constructor. |  | ||||||
|  |  | ||||||
| 	void setMessageLength(Int32 length); | 	void setMessageLength(Int32 length); | ||||||
| 		/// Sets the message length | 		/// Sets the message length. | ||||||
|  |  | ||||||
| 	Int32 _messageLength; | 	Int32 _messageLength; | ||||||
| 	Int32 _requestID; | 	Int32 _requestID; | ||||||
| @@ -87,6 +87,9 @@ private: | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
| inline MessageHeader::OpCode MessageHeader::opCode() const | inline MessageHeader::OpCode MessageHeader::opCode() const | ||||||
| { | { | ||||||
| 	return _opCode; | 	return _opCode; | ||||||
| @@ -126,4 +129,4 @@ inline Int32 MessageHeader::responseTo() const | |||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_MessageHeader_INCLUDED | #endif // MongoDB_MessageHeader_INCLUDED | ||||||
|   | |||||||
| @@ -46,15 +46,17 @@ class MongoDB_API ObjectId | |||||||
| public: | public: | ||||||
| 	typedef SharedPtr<ObjectId> Ptr; | 	typedef SharedPtr<ObjectId> Ptr; | ||||||
|  |  | ||||||
| 	ObjectId(const std::string& id); | 	explicit ObjectId(const std::string& id); | ||||||
| 		/// Constructor. The string must contain a hexidecimal representation | 		/// Creates an ObjectId from a string.  | ||||||
| 		/// of an object id. This means a string of 24 characters. | 		/// | ||||||
|  | 		/// The string must contain a hexidecimal representation | ||||||
|  | 		/// of an object ID. This means a string of 24 characters. | ||||||
|  |  | ||||||
| 	ObjectId(const ObjectId& copy); | 	ObjectId(const ObjectId& copy); | ||||||
| 		/// Copy constructor. | 		/// Creates an ObjectId by copying another one. | ||||||
|  |  | ||||||
| 	virtual ~ObjectId(); | 	virtual ~ObjectId(); | ||||||
| 		/// Destructor | 		/// Destroys the ObjectId. | ||||||
|  |  | ||||||
| 	Timestamp timestamp() const; | 	Timestamp timestamp() const; | ||||||
| 		/// Returns the timestamp which is stored in the first four bytes of the id | 		/// Returns the timestamp which is stored in the first four bytes of the id | ||||||
| @@ -65,22 +67,22 @@ public: | |||||||
| 		/// of the ID char array. | 		/// of the ID char array. | ||||||
|  |  | ||||||
| private: | private: | ||||||
|  |  | ||||||
| 	ObjectId(); | 	ObjectId(); | ||||||
| 		/// Constructor. Creates an empty Id |  | ||||||
|  | 	static int fromHex(char c);	 | ||||||
|  | 	static char fromHex(const char* c); | ||||||
| 	 | 	 | ||||||
| 	unsigned char _id[12]; | 	unsigned char _id[12]; | ||||||
|  |  | ||||||
| 	friend class BSONWriter; | 	friend class BSONWriter; | ||||||
| 	friend class BSONReader; | 	friend class BSONReader; | ||||||
| 	friend class Document; | 	friend class Document; | ||||||
| 	 |  | ||||||
| 	static int fromHex(char c); |  | ||||||
| 	 |  | ||||||
| 	static char fromHex(const char* c); |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
| inline Timestamp ObjectId::timestamp() const | inline Timestamp ObjectId::timestamp() const | ||||||
| { | { | ||||||
| 	int time; | 	int time; | ||||||
| @@ -92,6 +94,7 @@ inline Timestamp ObjectId::timestamp() const | |||||||
| 	return Timestamp::fromEpochTime((time_t) time); | 	return Timestamp::fromEpochTime((time_t) time); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| inline int ObjectId::fromHex(char c) | inline int ObjectId::fromHex(char c) | ||||||
| { | { | ||||||
| 	if ( '0' <= c && c <= '9' ) | 	if ( '0' <= c && c <= '9' ) | ||||||
| @@ -103,11 +106,13 @@ inline int ObjectId::fromHex(char c) | |||||||
| 	return 0xff; | 	return 0xff; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| inline char ObjectId::fromHex(const char* c) | inline char ObjectId::fromHex(const char* c) | ||||||
| { | { | ||||||
| 	return (char)((fromHex(c[0]) << 4 ) | fromHex(c[1])); | 	return (char)((fromHex(c[0]) << 4 ) | fromHex(c[1])); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| // BSON Embedded Document | // BSON Embedded Document | ||||||
| // spec: ObjectId | // spec: ObjectId | ||||||
| template<> | template<> | ||||||
| @@ -141,4 +146,4 @@ inline void BSONWriter::write<ObjectId::Ptr>(ObjectId::Ptr& from) | |||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_ObjectId_INCLUDED | #endif // MongoDB_ObjectId_INCLUDED | ||||||
|   | |||||||
| @@ -33,13 +33,13 @@ class PoolableObjectFactory<MongoDB::Connection, MongoDB::Connection::Ptr> | |||||||
| 	/// are created with the given address. | 	/// are created with the given address. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	PoolableObjectFactory(Net::SocketAddress& address) | 	PoolableObjectFactory(Net::SocketAddress& address): | ||||||
| 		: _address(address) | 		_address(address) | ||||||
| 	{ | 	{ | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	PoolableObjectFactory(const std::string& address) | 	PoolableObjectFactory(const std::string& address): | ||||||
| 		: _address(address) | 		_address(address) | ||||||
| 	{ | 	{ | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -105,8 +105,7 @@ private: | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
| } // namespace MongoDB | } } // namespace Poco::MongoDB | ||||||
| } // namespace Poco |  | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_PoolableConnectionFactory_INCLUDED | #endif // MongoDB_PoolableConnectionFactory_INCLUDED | ||||||
|   | |||||||
| @@ -29,59 +29,89 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API QueryRequest : public RequestMessage | class MongoDB_API QueryRequest: public RequestMessage | ||||||
| 	/// Class for creating an OP_QUERY client request. This request | 	/// A request to query documents in a MongoDB database | ||||||
| 	/// is used to query documents from the database. | 	/// using an OP_QUERY request. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	typedef enum | 	enum Flags | ||||||
| 	{ | 	{ | ||||||
| 		QUERY_NONE = 0,  | 		QUERY_DEFAULT = 0,  | ||||||
| 		QUERY_TAILABLECURSOR = 2,  | 			/// Do not set any flags. | ||||||
| 		QUERY_SLAVE_OK = 4,  |  | ||||||
| 		//QUERY_OPLOG_REPLAY = 8 (internal replication use only - drivers should not implement) |  | ||||||
| 		QUERY_NOCUROSR_TIMEOUT = 16, |  | ||||||
| 		QUERY_AWAIT_DATA = 32, |  | ||||||
| 		QUERY_EXHAUST = 64, |  | ||||||
| 		QUERY_PARTIAL = 128 |  | ||||||
| 	} Flags; |  | ||||||
| 	 | 	 | ||||||
| 	QueryRequest(const std::string& collectionName, Flags flags = QUERY_NONE); | 		QUERY_TAILABLE_CURSOR = 2,  | ||||||
| 		/// Constructor. | 			/// Tailable means cursor is not closed when the last data is retrieved.  | ||||||
|  | 			/// Rather, the cursor marks the final object’s position.  | ||||||
|  | 			/// You can resume using the cursor later, from where it was located,  | ||||||
|  | 			/// if more data were received. Like any "latent cursor", the cursor may  | ||||||
|  | 			/// become invalid at some point (CursorNotFound) – for example if the final  | ||||||
|  | 			/// object it references were deleted. | ||||||
|  | 	 | ||||||
|  | 		QUERY_SLAVE_OK = 4,  | ||||||
|  | 			/// Allow query of replica slave. Normally these return an error except  | ||||||
|  | 			/// for namespace "local". | ||||||
|  | 			 | ||||||
|  | 		// QUERY_OPLOG_REPLAY = 8 (internal replication use only - drivers should not implement) | ||||||
|  | 		 | ||||||
|  | 		QUERY_NO_CURSOR_TIMEOUT = 16, | ||||||
|  | 			/// The server normally times out idle cursors after an inactivity period  | ||||||
|  | 			/// (10 minutes) to prevent excess memory use. Set this option to prevent that. | ||||||
|  | 	 | ||||||
|  | 		QUERY_AWAIT_DATA = 32, | ||||||
|  | 			/// Use with QUERY_TAILABLECURSOR. If we are at the end of the data, block for  | ||||||
|  | 			/// a while rather than returning no data. After a timeout period, we do  | ||||||
|  | 			/// return as normal. | ||||||
|  |  | ||||||
|  | 		QUERY_EXHAUST = 64, | ||||||
|  | 			/// Stream the data down full blast in multiple "more" packages, on the  | ||||||
|  | 			/// assumption that the client will fully read all data queried.  | ||||||
|  | 			/// Faster when you are pulling a lot of data and know you want to pull  | ||||||
|  | 			/// it all down.  | ||||||
|  | 			/// Note: the client is not allowed to not read all the data unless it  | ||||||
|  | 			/// closes the connection. | ||||||
|  |  | ||||||
|  | 		QUERY_PARTIAL = 128 | ||||||
|  | 			/// Get partial results from a mongos if some shards are down  | ||||||
|  | 			/// (instead of throwing an error). | ||||||
|  | 	}; | ||||||
|  |  | ||||||
|  | 	QueryRequest(const std::string& collectionName, Flags flags = QUERY_DEFAULT); | ||||||
|  | 		/// Creates a QueryRequest. | ||||||
|  | 		/// | ||||||
| 		/// The full collection name is the concatenation of the database  | 		/// The full collection name is the concatenation of the database  | ||||||
| 		/// name with the collection name, using a "." for the concatenation. For example,  | 		/// name with the collection name, using a "." for the concatenation. For example,  | ||||||
| 		/// for the database "foo" and the collection "bar", the full collection name is  | 		/// for the database "foo" and the collection "bar", the full collection name is  | ||||||
| 		/// "foo.bar". | 		/// "foo.bar". | ||||||
|  |  | ||||||
| 	virtual ~QueryRequest(); | 	virtual ~QueryRequest(); | ||||||
| 		/// Destructor | 		/// Destroys the QueryRequest. | ||||||
|  |  | ||||||
| 	Flags getFlags() const; | 	Flags getFlags() const; | ||||||
| 		/// Returns the flags | 		/// Returns the flags. | ||||||
|  |  | ||||||
| 	void setFlags(Flags flag); | 	void setFlags(Flags flag); | ||||||
| 		/// Set the flags | 		/// Set the flags. | ||||||
|  |  | ||||||
| 	std::string fullCollectionName() const; | 	std::string fullCollectionName() const; | ||||||
| 		/// Returns the <db>.<collection> used for this query | 		/// Returns the <db>.<collection> used for this query. | ||||||
|  |  | ||||||
| 	Int32 getNumberToSkip() const; | 	Int32 getNumberToSkip() const; | ||||||
| 		/// Returns the number of documents to skip | 		/// Returns the number of documents to skip. | ||||||
|  |  | ||||||
| 	void setNumberToSkip(Int32 n); | 	void setNumberToSkip(Int32 n); | ||||||
| 		/// Sets the number of documents to skip | 		/// Sets the number of documents to skip. | ||||||
|  |  | ||||||
| 	Int32 getNumberToReturn() const; | 	Int32 getNumberToReturn() const; | ||||||
| 		/// Returns the number to return | 		/// Returns the number of documents to return. | ||||||
|  |  | ||||||
| 	void setNumberToReturn(Int32 n); | 	void setNumberToReturn(Int32 n); | ||||||
| 		/// Sets the number to return (limit) | 		/// Sets the number of documents to return (limit). | ||||||
|  |  | ||||||
| 	Document& selector(); | 	Document& selector(); | ||||||
| 		/// Returns the selector document | 		/// Returns the selector document. | ||||||
|  |  | ||||||
| 	Document& returnFieldSelector(); | 	Document& returnFieldSelector(); | ||||||
| 		/// Returns the field selector document | 		/// Returns the field selector document. | ||||||
|  |  | ||||||
| protected: | protected: | ||||||
| 	void buildRequest(BinaryWriter& writer); | 	void buildRequest(BinaryWriter& writer); | ||||||
| @@ -96,6 +126,9 @@ private: | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
| inline QueryRequest::Flags QueryRequest::getFlags() const | inline QueryRequest::Flags QueryRequest::getFlags() const | ||||||
| { | { | ||||||
| 	return _flags; | 	return _flags; | ||||||
| @@ -153,4 +186,4 @@ inline void QueryRequest::setNumberToReturn(Int32 n) | |||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_QueryRequest_INCLUDED | #endif // MongoDB_QueryRequest_INCLUDED | ||||||
|   | |||||||
| @@ -30,34 +30,34 @@ namespace MongoDB { | |||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API RegularExpression | class MongoDB_API RegularExpression | ||||||
| 	/// Represents a regular expression in BSON format | 	/// Represents a regular expression in BSON format. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	typedef SharedPtr<RegularExpression> Ptr; | 	typedef SharedPtr<RegularExpression> Ptr; | ||||||
|  |  | ||||||
| 	RegularExpression(); | 	RegularExpression(); | ||||||
| 		/// Constructor | 		/// Creates an empty RegularExpression. | ||||||
|  |  | ||||||
| 	RegularExpression(const std::string& pattern, const std::string& options); | 	RegularExpression(const std::string& pattern, const std::string& options); | ||||||
| 		/// Constructor | 		/// Creates a RegularExpression using the given pattern and options. | ||||||
|  |  | ||||||
| 	virtual ~RegularExpression(); | 	virtual ~RegularExpression(); | ||||||
| 		/// Destructor | 		/// Destroys the RegularExpression. | ||||||
|  |  | ||||||
| 	SharedPtr<Poco::RegularExpression> createRE() const; | 	SharedPtr<Poco::RegularExpression> createRE() const; | ||||||
| 		/// Tries to create a Poco::RegularExpression | 		/// Tries to create a Poco::RegularExpression from the MongoDB regular expression. | ||||||
|  |  | ||||||
| 	std::string getOptions() const; | 	std::string getOptions() const; | ||||||
| 		/// Returns the options | 		/// Returns the options string. | ||||||
|  |  | ||||||
| 	void setOptions(const std::string& options); | 	void setOptions(const std::string& options); | ||||||
| 		/// Sets the options | 		/// Sets the options string. | ||||||
|  |  | ||||||
| 	std::string getPattern() const; | 	std::string getPattern() const; | ||||||
| 		/// Returns the pattern | 		/// Returns the pattern. | ||||||
|  |  | ||||||
| 	void setPattern(const std::string& pattern); | 	void setPattern(const std::string& pattern); | ||||||
| 		/// Sets the pattern | 		/// Sets the pattern. | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	std::string _pattern; | 	std::string _pattern; | ||||||
| @@ -65,6 +65,9 @@ private: | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /// | ||||||
|  | /// inlines | ||||||
|  | /// | ||||||
| inline std::string RegularExpression::getPattern() const | inline std::string RegularExpression::getPattern() const | ||||||
| { | { | ||||||
| 	return _pattern; | 	return _pattern; | ||||||
|   | |||||||
| @@ -30,21 +30,26 @@ namespace MongoDB { | |||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API ReplicaSet | class MongoDB_API ReplicaSet | ||||||
| 	/// Class for working with a replicaset | 	/// Class for working with a MongoDB replica set. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	ReplicaSet(const std::vector<Net::SocketAddress>& addresses); | 	explicit ReplicaSet(const std::vector<Net::SocketAddress>& addresses); | ||||||
| 		/// Constructor | 		/// Creates the ReplicaSet using the given server addresses. | ||||||
|  |  | ||||||
| 	virtual ~ReplicaSet(); | 	virtual ~ReplicaSet(); | ||||||
| 		/// Destructor | 		/// Destroys the ReplicaSet. | ||||||
|  |  | ||||||
| 	Connection::Ptr findMaster(); | 	Connection::Ptr findMaster(); | ||||||
| 		/// Tries to find the master MongoDB instance from the addresses | 		/// Tries to find the master MongoDB instance from the addresses | ||||||
|  | 		/// passed to the constructor. | ||||||
|  | 		/// | ||||||
|  | 		/// Returns the Connection to the master, or null if no master | ||||||
|  | 		/// instance was found. | ||||||
|  |  | ||||||
| private: | protected: | ||||||
| 	Connection::Ptr isMaster(const Net::SocketAddress& host); | 	Connection::Ptr isMaster(const Net::SocketAddress& host); | ||||||
|  |  | ||||||
|  | private: | ||||||
| 	std::vector<Net::SocketAddress> _addresses; | 	std::vector<Net::SocketAddress> _addresses; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -29,18 +29,18 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API RequestMessage : public Message | class MongoDB_API RequestMessage: public Message | ||||||
| 	/// Base class for a request | 	/// Base class for a request sent to the MongoDB server. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	RequestMessage(MessageHeader::OpCode opcode); | 	explicit RequestMessage(MessageHeader::OpCode opcode); | ||||||
| 		/// Constructor | 		/// Creates a RequestMessage using the given opcode. | ||||||
|  |  | ||||||
| 	virtual ~RequestMessage(); | 	virtual ~RequestMessage(); | ||||||
| 		/// Destructor | 		/// Destroys the RequestMessage. | ||||||
|  |  | ||||||
| 	void send(std::ostream& ostr); | 	void send(std::ostream& ostr); | ||||||
| 		/// Sends the request to stream | 		/// Writes the request to stream. | ||||||
|  |  | ||||||
| protected: | protected: | ||||||
| 	virtual void buildRequest(BinaryWriter& ss) = 0; | 	virtual void buildRequest(BinaryWriter& ss) = 0; | ||||||
| @@ -50,4 +50,4 @@ protected: | |||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_RequestMessage_INCLUDED | #endif // MongoDB_RequestMessage_INCLUDED | ||||||
|   | |||||||
| @@ -24,42 +24,43 @@ | |||||||
| #include "Poco/MongoDB/Message.h" | #include "Poco/MongoDB/Message.h" | ||||||
| #include "Poco/MongoDB/Document.h" | #include "Poco/MongoDB/Document.h" | ||||||
| #include <istream> | #include <istream> | ||||||
|  | #include <cstdlib> | ||||||
|  |  | ||||||
|  |  | ||||||
| namespace Poco { | namespace Poco { | ||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDB_API ResponseMessage : public Message | class MongoDB_API ResponseMessage: public Message | ||||||
| 	/// Class that represents a response (OP_REPLY) from MongoDB | 	/// This class represents a response (OP_REPLY) from MongoDB. | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	ResponseMessage(); | 	ResponseMessage(); | ||||||
| 		/// Constructor | 		/// Creates an empty ResponseMessage. | ||||||
|  |  | ||||||
| 	virtual ~ResponseMessage(); | 	virtual ~ResponseMessage(); | ||||||
| 		/// Destructor | 		/// Destroys the ResponseMessage. | ||||||
|  |  | ||||||
| 	Int64 cursorID() const; | 	Int64 cursorID() const; | ||||||
| 		/// Returns the cursor id | 		/// Returns the cursor ID. | ||||||
|  |  | ||||||
| 	void clear(); | 	void clear(); | ||||||
| 		/// Clears the response | 		/// Clears the response. | ||||||
|  |  | ||||||
| 	size_t count() const; | 	std::size_t count() const; | ||||||
| 		/// Returns the number of documents in the response | 		/// Returns the number of documents in the response. | ||||||
|  |  | ||||||
| 	Document::Vector& documents(); | 	Document::Vector& documents(); | ||||||
| 		/// Returns the retrieved documents | 		/// Returns a vector containing the received documents. | ||||||
|  |  | ||||||
| 	bool empty() const; | 	bool empty() const; | ||||||
| 		/// Returns true when the response doesn't contain any documents | 		/// Returns true if the response does not contain any documents. | ||||||
|  |  | ||||||
| 	bool hasDocuments() const; | 	bool hasDocuments() const; | ||||||
| 		/// Returns true when there is at least one document | 		/// Returns true if there is at least one document in the response. | ||||||
|  |  | ||||||
| 	void read(std::istream& istr); | 	void read(std::istream& istr); | ||||||
| 		/// Reads the response from the stream | 		/// Reads the response from the stream. | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	Int32 _responseFlags; | 	Int32 _responseFlags; | ||||||
| @@ -70,7 +71,10 @@ private: | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
| inline size_t ResponseMessage::count() const | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
|  | inline std::size_t ResponseMessage::count() const | ||||||
| { | { | ||||||
| 	return _documents.size(); | 	return _documents.size(); | ||||||
| } | } | ||||||
| @@ -103,4 +107,4 @@ inline bool ResponseMessage::hasDocuments() const | |||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_ResponseMessage_INCLUDED | #endif // MongoDB_ResponseMessage_INCLUDED | ||||||
|   | |||||||
| @@ -29,39 +29,42 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| class UpdateRequest : public RequestMessage | class UpdateRequest: public RequestMessage | ||||||
| 	/// Class for creating an OP_UPDATE client request. This request is used | 	/// This request is used to update a document in a database | ||||||
| 	/// to update a document. | 	/// using the OP_UPDATE client request.  | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	typedef enum | 	enum Flags | ||||||
| 	{ | 	{ | ||||||
| 		UPDATE_NOFLAGS = 0, | 		UPDATE_DEFAULT = 0, | ||||||
| 		// If set, the database will insert the supplied object into the | 			/// If set, the database will insert the supplied object into the | ||||||
| 		// collection if no matching document is found. | 			/// collection if no matching document is found. | ||||||
| 		UPDATE_UPSERT = 1, |  | ||||||
| 		// if set, the database will update all matching objects in the collection. |  | ||||||
| 		// Otherwise only updates first matching doc. |  | ||||||
| 		UPDATE_MULTIUPDATE = 2 |  | ||||||
| 	} Flags; |  | ||||||
| 			 | 			 | ||||||
| 	UpdateRequest(const std::string& collectionName, Flags flags = UPDATE_NOFLAGS); | 		UPDATE_UPSERT = 1, | ||||||
| 		/// Constructor. | 			/// If set, the database will update all matching objects in the collection. | ||||||
|  | 			/// Otherwise only updates first matching doc. | ||||||
|  |  | ||||||
|  | 		UPDATE_MULTIUPDATE = 2 | ||||||
|  | 			/// If set to, updates multiple documents that meet the query criteria. | ||||||
|  | 			/// Otherwise only updates one document. | ||||||
|  | 	}; | ||||||
|  |  | ||||||
|  | 	UpdateRequest(const std::string& collectionName, Flags flags = UPDATE_DEFAULT); | ||||||
|  | 		/// Creates the UpdateRequest. | ||||||
|  | 		/// | ||||||
| 		/// The full collection name is the concatenation of the database  | 		/// The full collection name is the concatenation of the database  | ||||||
| 		/// name with the collection name, using a "." for the concatenation. For example,  | 		/// name with the collection name, using a "." for the concatenation. For example,  | ||||||
| 		/// for the database "foo" and the collection "bar", the full collection name is  | 		/// for the database "foo" and the collection "bar", the full collection name is  | ||||||
| 		/// "foo.bar". | 		/// "foo.bar". | ||||||
|  |  | ||||||
| 	virtual ~UpdateRequest(); | 	virtual ~UpdateRequest(); | ||||||
| 		/// Destructor | 		/// Destroys the UpdateRequest. | ||||||
| 		 |  | ||||||
|  |  | ||||||
| 	Document& selector(); | 	Document& selector(); | ||||||
| 		/// Returns the selector document | 		/// Returns the selector document. | ||||||
| 		 |  | ||||||
|  |  | ||||||
| 	Document& update(); | 	Document& update(); | ||||||
| 		/// The document to update | 		/// Returns the document to update. | ||||||
|  |  | ||||||
| 	Flags flags() const; | 	Flags flags() const; | ||||||
| 		/// Returns the flags | 		/// Returns the flags | ||||||
| @@ -72,7 +75,6 @@ public: | |||||||
| protected: | protected: | ||||||
| 	void buildRequest(BinaryWriter& writer); | 	void buildRequest(BinaryWriter& writer); | ||||||
|  |  | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	Flags       _flags; | 	Flags       _flags; | ||||||
| 	std::string _fullCollectionName; | 	std::string _fullCollectionName; | ||||||
| @@ -81,21 +83,27 @@ private: | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // | ||||||
|  | // inlines | ||||||
|  | // | ||||||
| inline UpdateRequest::Flags UpdateRequest::flags() const | inline UpdateRequest::Flags UpdateRequest::flags() const | ||||||
| { | { | ||||||
| 	return _flags; | 	return _flags; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| inline void UpdateRequest::flags(UpdateRequest::Flags flags) | inline void UpdateRequest::flags(UpdateRequest::Flags flags) | ||||||
| { | { | ||||||
| 	_flags = flags; | 	_flags = flags; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| inline Document& UpdateRequest::selector() | inline Document& UpdateRequest::selector() | ||||||
| { | { | ||||||
| 	return _selector; | 	return _selector; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| inline Document& UpdateRequest::update() | inline Document& UpdateRequest::update() | ||||||
| { | { | ||||||
| 	return _update; | 	return _update; | ||||||
| @@ -105,4 +113,4 @@ inline Document& UpdateRequest::update() | |||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //MongoDB_UpdateRequest_INCLUDED | #endif // MongoDB_UpdateRequest_INCLUDED | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  Array | // Module:  Array | ||||||
| // | // | ||||||
| // Implementation of the Array class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -24,7 +22,8 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| Array::Array() : Document() | Array::Array():  | ||||||
|  | 	Document() | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -47,26 +46,26 @@ std::string Array::toString(int indent) const | |||||||
|  |  | ||||||
| 	oss << "["; | 	oss << "["; | ||||||
|  |  | ||||||
| 	if ( indent > 0 ) oss << std::endl; | 	if (indent > 0) oss << std::endl; | ||||||
|  |  | ||||||
| 	for(ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it) | 	for (ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it) | ||||||
| 	{ | 	{ | ||||||
| 		if ( it != _elements.begin() ) | 		if (it != _elements.begin()) | ||||||
| 		{ | 		{ | ||||||
| 			oss << ","; | 			oss << ","; | ||||||
| 			if ( indent > 0 ) oss << std::endl; | 			if (indent > 0) oss << std::endl; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		for(int i = 0; i < indent; ++i) oss << ' '; | 		for (int i = 0; i < indent; ++i) oss << ' '; | ||||||
|  |  | ||||||
| 		oss << (*it)->toString(indent > 0 ? indent + 2 : 0); | 		oss << (*it)->toString(indent > 0 ? indent + 2 : 0); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if ( indent > 0 ) | 	if (indent > 0) | ||||||
| 	{ | 	{ | ||||||
| 		oss << std::endl; | 		oss << std::endl; | ||||||
| 		if ( indent >= 2 ) indent -= 2; | 		if (indent >= 2) indent -= 2; | ||||||
| 		for(int i = 0; i < indent; ++i) oss << ' '; | 		for (int i = 0; i < indent; ++i) oss << ' '; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	oss << "]"; | 	oss << "]"; | ||||||
| @@ -75,4 +74,4 @@ std::string Array::toString(int indent) const | |||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| }} // Namespace Poco::Mongo | } } // Namespace Poco::Mongo | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  Binary | // Module:  Binary | ||||||
| // | // | ||||||
| // Implementation of the Binary class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -76,9 +74,10 @@ std::string Binary::toString(int indent) const | |||||||
| 	return oss.str(); | 	return oss.str(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| UUID Binary::uuid() const | UUID Binary::uuid() const | ||||||
| { | { | ||||||
| 	if ( _subtype == 0x04 && _buffer.size() == 16 ) | 	if (_subtype == 0x04 && _buffer.size() == 16) | ||||||
| 	{ | 	{ | ||||||
| 		UUID uuid; | 		UUID uuid; | ||||||
| 		uuid.copyFrom((const char*) _buffer.begin()); | 		uuid.copyFrom((const char*) _buffer.begin()); | ||||||
| @@ -87,4 +86,5 @@ UUID Binary::uuid() const | |||||||
| 	throw BadCastException("Invalid subtype"); | 	throw BadCastException("Invalid subtype"); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| } } // namespace Poco::MongoDB | } } // namespace Poco::MongoDB | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  Connection | // Module:  Connection | ||||||
| // | // | ||||||
| // Implementation of the Connection class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -18,41 +16,55 @@ | |||||||
|  |  | ||||||
| #include "Poco/Net/SocketStream.h" | #include "Poco/Net/SocketStream.h" | ||||||
| #include "Poco/MongoDB/Connection.h" | #include "Poco/MongoDB/Connection.h" | ||||||
| #include <iostream> |  | ||||||
|  |  | ||||||
|  |  | ||||||
| namespace Poco { | namespace Poco { | ||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| Connection::Connection() : _address(), _socket() | Connection::Connection(): | ||||||
|  | 	_address(), | ||||||
|  | 	_socket() | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| Connection::Connection(const std::string& hostAndPort) : _address(hostAndPort), _socket() | Connection::Connection(const std::string& hostAndPort): | ||||||
|  | 	_address(hostAndPort), | ||||||
|  | 	_socket() | ||||||
| { | { | ||||||
| 	connect(); | 	connect(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| Connection::Connection(const std::string& host, int port) : _address(host, port), _socket() | Connection::Connection(const std::string& host, int port): | ||||||
|  | 	_address(host, port), | ||||||
|  | 	_socket() | ||||||
| { | { | ||||||
| 	connect(); | 	connect(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| Connection::Connection(const Net::SocketAddress& addrs) : _address(addrs), _socket() | Connection::Connection(const Poco::Net::SocketAddress& addrs): | ||||||
|  | 	_address(addrs), | ||||||
|  | 	_socket() | ||||||
| { | { | ||||||
| 	connect(); | 	connect(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | Connection::Connection(const Poco::Net::StreamSocket& socket): | ||||||
|  | 	_address(socket.peerAddress()), | ||||||
|  | 	_socket(socket) | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| Connection::~Connection() | Connection::~Connection() | ||||||
| { | { | ||||||
| 	try | 	try | ||||||
| 	{ | 	{ | ||||||
| 		_socket.close(); | 		disconnect(); | ||||||
| 	} | 	} | ||||||
| 	catch (...) | 	catch (...) | ||||||
| 	{ | 	{ | ||||||
| @@ -68,25 +80,32 @@ void Connection::connect() | |||||||
|  |  | ||||||
| void Connection::connect(const std::string& hostAndPort) | void Connection::connect(const std::string& hostAndPort) | ||||||
| { | { | ||||||
| 	_address = Net::SocketAddress(hostAndPort); | 	_address = Poco::Net::SocketAddress(hostAndPort); | ||||||
| 	connect(); | 	connect(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void Connection::connect(const std::string& host, int port) | void Connection::connect(const std::string& host, int port) | ||||||
| { | { | ||||||
| 	_address = Net::SocketAddress(host, port); | 	_address = Poco::Net::SocketAddress(host, port); | ||||||
| 	connect(); | 	connect(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void Connection::connect(const Net::SocketAddress& addrs) | void Connection::connect(const Poco::Net::SocketAddress& addrs) | ||||||
| { | { | ||||||
| 	_address = addrs; | 	_address = addrs; | ||||||
| 	connect(); | 	connect(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | void Connection::connect(const Poco::Net::StreamSocket& socket) | ||||||
|  | { | ||||||
|  | 	_address = socket.peerAddress(); | ||||||
|  | 	_socket = socket; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void Connection::disconnect() | void Connection::disconnect() | ||||||
| { | { | ||||||
| 	_socket.close(); | 	_socket.close(); | ||||||
| @@ -95,7 +114,7 @@ void Connection::disconnect() | |||||||
|  |  | ||||||
| void Connection::sendRequest(RequestMessage& request) | void Connection::sendRequest(RequestMessage& request) | ||||||
| { | { | ||||||
| 	Net::SocketOutputStream sos(_socket); | 	Poco::Net::SocketOutputStream sos(_socket); | ||||||
| 	request.send(sos); | 	request.send(sos); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -104,8 +123,9 @@ void Connection::sendRequest(RequestMessage& request, ResponseMessage& response) | |||||||
| { | { | ||||||
| 	sendRequest(request); | 	sendRequest(request); | ||||||
|  |  | ||||||
| 	Net::SocketInputStream sis(_socket); | 	Poco::Net::SocketInputStream sis(_socket); | ||||||
| 	response.read(sis); | 	response.read(sis); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| } } // Poco::MongoDB | } } // Poco::MongoDB | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  Cursor | // Module:  Cursor | ||||||
| // | // | ||||||
| // Implementation of the Cursor class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -25,14 +23,14 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| Cursor::Cursor(const std::string& db, const std::string& collection, QueryRequest::Flags flags) | Cursor::Cursor(const std::string& db, const std::string& collection, QueryRequest::Flags flags): | ||||||
| 	: _query(db + '.' + collection, flags) | 	_query(db + '.' + collection, flags) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| Cursor::Cursor(const std::string& fullCollectionName, QueryRequest::Flags flags) | Cursor::Cursor(const std::string& fullCollectionName, QueryRequest::Flags flags): | ||||||
| 	: _query(fullCollectionName, flags) | 	_query(fullCollectionName, flags) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -42,7 +40,6 @@ Cursor::~Cursor() | |||||||
| 	try | 	try | ||||||
| 	{ | 	{ | ||||||
| 		poco_assert_dbg(!_response.cursorID()); | 		poco_assert_dbg(!_response.cursorID()); | ||||||
|  |  | ||||||
| 	} | 	} | ||||||
| 	catch (...) | 	catch (...) | ||||||
| 	{ | 	{ | ||||||
| @@ -52,7 +49,7 @@ Cursor::~Cursor() | |||||||
|  |  | ||||||
| ResponseMessage& Cursor::next(Connection& connection) | ResponseMessage& Cursor::next(Connection& connection) | ||||||
| { | { | ||||||
| 	if ( _response.cursorID() == 0 ) | 	if (_response.cursorID() == 0) | ||||||
| 	{ | 	{ | ||||||
| 		connection.sendRequest(_query, _response); | 		connection.sendRequest(_query, _response); | ||||||
| 	} | 	} | ||||||
| @@ -69,7 +66,7 @@ ResponseMessage& Cursor::next(Connection& connection) | |||||||
|  |  | ||||||
| void Cursor::kill(Connection& connection) | void Cursor::kill(Connection& connection) | ||||||
| { | { | ||||||
| 	if ( _response.cursorID() != 0 ) | 	if (_response.cursorID() != 0) | ||||||
| 	{ | 	{ | ||||||
| 		KillCursorsRequest killRequest; | 		KillCursorsRequest killRequest; | ||||||
| 		killRequest.cursors().push_back(_response.cursorID()); | 		killRequest.cursors().push_back(_response.cursorID()); | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  Database | // Module:  Database | ||||||
| // | // | ||||||
| // Implementation of the Database class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -158,19 +156,11 @@ bool Database::authCR(Connection& connection, const std::string& username, const | |||||||
| 	if (response.documents().size() > 0) | 	if (response.documents().size() > 0) | ||||||
| 	{ | 	{ | ||||||
| 		Document::Ptr pDoc = response.documents()[0]; | 		Document::Ptr pDoc = response.documents()[0]; | ||||||
| 		try | 		if (pDoc->get<double>("ok") != 1) return false; | ||||||
| 		{ |  | ||||||
| 			double ok = pDoc->get<double>("ok");    |  | ||||||
| 			if (ok != 1) return false; |  | ||||||
| 		nonce = pDoc->get<std::string>("nonce", ""); | 		nonce = pDoc->get<std::string>("nonce", ""); | ||||||
| 			if (nonce.empty()) return false; | 		if (nonce.empty()) throw Poco::ProtocolException("no nonce received"); | ||||||
| 	} | 	} | ||||||
| 		catch (Poco::NotFoundException&) | 	else throw Poco::ProtocolException("empty response for getnonce"); | ||||||
| 		{ |  | ||||||
| 			return false; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	else return false; |  | ||||||
|  |  | ||||||
| 	std::string credsDigest = hashCredentials(username, password); | 	std::string credsDigest = hashCredentials(username, password); | ||||||
|  |  | ||||||
| @@ -191,15 +181,9 @@ bool Database::authCR(Connection& connection, const std::string& username, const | |||||||
| 	if (response.documents().size() > 0) | 	if (response.documents().size() > 0) | ||||||
| 	{ | 	{ | ||||||
| 		Document::Ptr pDoc = response.documents()[0]; | 		Document::Ptr pDoc = response.documents()[0]; | ||||||
| 		try |  | ||||||
| 		{ |  | ||||||
| 		return pDoc->get<double>("ok") == 1; | 		return pDoc->get<double>("ok") == 1; | ||||||
| 	} | 	} | ||||||
| 		catch (Poco::NotFoundException&) | 	else throw Poco::ProtocolException("empty response for authenticate"); | ||||||
| 		{ |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	return false; |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -224,8 +208,6 @@ bool Database::authSCRAM(Connection& connection, const std::string& username, co | |||||||
| 	if (response.documents().size() > 0) | 	if (response.documents().size() > 0) | ||||||
| 	{ | 	{ | ||||||
| 		Document::Ptr pDoc = response.documents()[0]; | 		Document::Ptr pDoc = response.documents()[0]; | ||||||
| 		try |  | ||||||
| 		{ |  | ||||||
| 		if (pDoc->get<double>("ok") == 1) | 		if (pDoc->get<double>("ok") == 1) | ||||||
| 		{ | 		{ | ||||||
| 			Binary::Ptr pPayload = pDoc->get<Binary::Ptr>("payload"); | 			Binary::Ptr pPayload = pDoc->get<Binary::Ptr>("payload"); | ||||||
| @@ -234,12 +216,7 @@ bool Database::authSCRAM(Connection& connection, const std::string& username, co | |||||||
| 		} | 		} | ||||||
| 		else return false; | 		else return false; | ||||||
| 	} | 	} | ||||||
| 		catch (Poco::NotFoundException&) | 	else throw Poco::ProtocolException("empty response for saslStart"); | ||||||
| 		{ |  | ||||||
| 			return false; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	else return false; |  | ||||||
| 	 | 	 | ||||||
| 	std::map<std::string, std::string> kvm = parseKeyValueList(serverFirstMsg); | 	std::map<std::string, std::string> kvm = parseKeyValueList(serverFirstMsg); | ||||||
| 	const std::string serverNonce = kvm["r"]; | 	const std::string serverNonce = kvm["r"]; | ||||||
| @@ -287,8 +264,6 @@ bool Database::authSCRAM(Connection& connection, const std::string& username, co | |||||||
| 	if (response.documents().size() > 0) | 	if (response.documents().size() > 0) | ||||||
| 	{ | 	{ | ||||||
| 		Document::Ptr pDoc = response.documents()[0]; | 		Document::Ptr pDoc = response.documents()[0]; | ||||||
| 		try |  | ||||||
| 		{ |  | ||||||
| 		if (pDoc->get<double>("ok") == 1) | 		if (pDoc->get<double>("ok") == 1) | ||||||
| 		{ | 		{ | ||||||
| 			Binary::Ptr pPayload = pDoc->get<Binary::Ptr>("payload"); | 			Binary::Ptr pPayload = pDoc->get<Binary::Ptr>("payload"); | ||||||
| @@ -296,12 +271,7 @@ bool Database::authSCRAM(Connection& connection, const std::string& username, co | |||||||
| 		} | 		} | ||||||
| 		else return false; | 		else return false; | ||||||
| 	} | 	} | ||||||
| 		catch (Poco::NotFoundException&) | 	else throw Poco::ProtocolException("empty response for saslContinue"); | ||||||
| 		{ |  | ||||||
| 			return false; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	else return false; |  | ||||||
|  |  | ||||||
| 	Poco::HMACEngine<Poco::SHA1Engine> hmacSKey(saltedPassword); | 	Poco::HMACEngine<Poco::SHA1Engine> hmacSKey(saltedPassword); | ||||||
| 	hmacSKey.update(std::string("Server Key")); | 	hmacSKey.update(std::string("Server Key")); | ||||||
| @@ -314,7 +284,8 @@ bool Database::authSCRAM(Connection& connection, const std::string& username, co | |||||||
| 	kvm = parseKeyValueList(serverSecondMsg); | 	kvm = parseKeyValueList(serverSecondMsg); | ||||||
| 	std::string serverSignatureReceived = kvm["v"]; | 	std::string serverSignatureReceived = kvm["v"]; | ||||||
| 	 | 	 | ||||||
| 	if (serverSignature != serverSignatureReceived) return false; | 	if (serverSignature != serverSignatureReceived) 	 | ||||||
|  | 		throw Poco::ProtocolException("server signature verification failed"); | ||||||
| 	 | 	 | ||||||
| 	pCommand = createCommand(); | 	pCommand = createCommand(); | ||||||
| 	pCommand->selector() | 	pCommand->selector() | ||||||
| @@ -328,8 +299,7 @@ bool Database::authSCRAM(Connection& connection, const std::string& username, co | |||||||
| 		Document::Ptr pDoc = response.documents()[0]; | 		Document::Ptr pDoc = response.documents()[0]; | ||||||
| 		return pDoc->get<double>("ok") == 1; | 		return pDoc->get<double>("ok") == 1; | ||||||
| 	} | 	} | ||||||
|  | 	else throw Poco::ProtocolException("empty response for saslContinue"); | ||||||
| 	return false; |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -340,7 +310,7 @@ Int64 Database::count(Connection& connection, const std::string& collectionName) | |||||||
| 	Poco::MongoDB::ResponseMessage response; | 	Poco::MongoDB::ResponseMessage response; | ||||||
| 	connection.sendRequest(*countRequest, response); | 	connection.sendRequest(*countRequest, response); | ||||||
|  |  | ||||||
| 	if ( response.documents().size() > 0 ) | 	if (response.documents().size() > 0) | ||||||
| 	{ | 	{ | ||||||
| 		Poco::MongoDB::Document::Ptr doc = response.documents()[0]; | 		Poco::MongoDB::Document::Ptr doc = response.documents()[0]; | ||||||
| 		return doc->getInteger("n"); | 		return doc->getInteger("n"); | ||||||
| @@ -357,22 +327,22 @@ Poco::MongoDB::Document::Ptr Database::ensureIndex(Connection& connection, const | |||||||
| 	index->add("name", indexName); | 	index->add("name", indexName); | ||||||
| 	index->add("key", keys); | 	index->add("key", keys); | ||||||
|  |  | ||||||
| 	if ( version > 0 ) | 	if (version > 0) | ||||||
| 	{ | 	{ | ||||||
| 		index->add("version", version); | 		index->add("version", version); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if ( unique ) | 	if (unique) | ||||||
| 	{ | 	{ | ||||||
| 		index->add("unique", true); | 		index->add("unique", true); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if ( background ) | 	if (background) | ||||||
| 	{ | 	{ | ||||||
| 		index->add("background", true); | 		index->add("background", true); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if ( ttl > 0 ) | 	if (ttl > 0) | ||||||
| 	{ | 	{ | ||||||
| 		index->add("expireAfterSeconds", ttl); | 		index->add("expireAfterSeconds", ttl); | ||||||
| 	} | 	} | ||||||
| @@ -396,7 +366,7 @@ Document::Ptr Database::getLastErrorDoc(Connection& connection) const | |||||||
| 	Poco::MongoDB::ResponseMessage response; | 	Poco::MongoDB::ResponseMessage response; | ||||||
| 	connection.sendRequest(*request, response); | 	connection.sendRequest(*request, response); | ||||||
|  |  | ||||||
| 	if ( response.documents().size() > 0 ) | 	if (response.documents().size() > 0) | ||||||
| 	{ | 	{ | ||||||
| 		errorDoc = response.documents()[0]; | 		errorDoc = response.documents()[0]; | ||||||
| 	} | 	} | ||||||
| @@ -408,7 +378,7 @@ Document::Ptr Database::getLastErrorDoc(Connection& connection) const | |||||||
| std::string Database::getLastError(Connection& connection) const | std::string Database::getLastError(Connection& connection) const | ||||||
| { | { | ||||||
| 	Document::Ptr errorDoc = getLastErrorDoc(connection); | 	Document::Ptr errorDoc = getLastErrorDoc(connection); | ||||||
| 	if ( !errorDoc.isNull() && errorDoc->isType<std::string>("err") ) | 	if (!errorDoc.isNull() && errorDoc->isType<std::string>("err")) | ||||||
| 	{ | 	{ | ||||||
| 		return errorDoc->get<std::string>("err"); | 		return errorDoc->get<std::string>("err"); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  DeleteRequest | // Module:  DeleteRequest | ||||||
| // | // | ||||||
| // Implementation of the DeleteRequest class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -23,8 +21,8 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| DeleteRequest::DeleteRequest(const std::string& collectionName, DeleteRequest::Flags flags)  | DeleteRequest::DeleteRequest(const std::string& collectionName, DeleteRequest::Flags flags): | ||||||
| 	: RequestMessage(MessageHeader::Delete),  | 	RequestMessage(MessageHeader::OP_DELETE),  | ||||||
| 	_flags(flags),  | 	_flags(flags),  | ||||||
| 	_fullCollectionName(collectionName), | 	_fullCollectionName(collectionName), | ||||||
| 	_selector() | 	_selector() | ||||||
| @@ -32,9 +30,9 @@ DeleteRequest::DeleteRequest(const std::string& collectionName, DeleteRequest::F | |||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| DeleteRequest::DeleteRequest(const std::string& collectionName, bool justOne) | DeleteRequest::DeleteRequest(const std::string& collectionName, bool justOne): | ||||||
| 	: RequestMessage(MessageHeader::Delete), | 	RequestMessage(MessageHeader::OP_DELETE), | ||||||
| 	_flags(justOne ? DELETE_SINGLE_REMOVE : DELETE_NONE), | 	_flags(justOne ? DELETE_SINGLE_REMOVE : DELETE_DEFAULT), | ||||||
| 	_fullCollectionName(collectionName), | 	_fullCollectionName(collectionName), | ||||||
| 	_selector() | 	_selector() | ||||||
| { | { | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  Document | // Module:  Document | ||||||
| // | // | ||||||
| // Implementation of the Document class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -44,7 +42,7 @@ Element::Ptr Document::get(const std::string& name) const | |||||||
| 	Element::Ptr element; | 	Element::Ptr element; | ||||||
|  |  | ||||||
| 	ElementSet::const_iterator it = std::find_if(_elements.begin(), _elements.end(), ElementFindByName(name)); | 	ElementSet::const_iterator it = std::find_if(_elements.begin(), _elements.end(), ElementFindByName(name)); | ||||||
| 	if ( it != _elements.end() ) | 	if (it != _elements.end()) | ||||||
| 	{ | 	{ | ||||||
| 		return *it; | 		return *it; | ||||||
| 	} | 	} | ||||||
| @@ -52,29 +50,31 @@ Element::Ptr Document::get(const std::string& name) const | |||||||
| 	return element; | 	return element; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| Int64 Document::getInteger(const std::string& name) const | Int64 Document::getInteger(const std::string& name) const | ||||||
| { | { | ||||||
| 	Element::Ptr element = get(name); | 	Element::Ptr element = get(name); | ||||||
| 	if ( element.isNull() ) throw NotFoundException(name); | 	if (element.isNull()) throw Poco::NotFoundException(name); | ||||||
|  |  | ||||||
| 	if ( ElementTraits<double>::TypeId == element->type() ) | 	if (ElementTraits<double>::TypeId == element->type()) | ||||||
| 	{ | 	{ | ||||||
| 		ConcreteElement<double>* concrete = dynamic_cast<ConcreteElement<double>* >(element.get()); | 		ConcreteElement<double>* concrete = dynamic_cast<ConcreteElement<double>*>(element.get()); | ||||||
| 		if ( concrete != NULL ) return concrete->value(); | 		if (concrete) return concrete->value(); | ||||||
| 	} | 	} | ||||||
| 	else if ( ElementTraits<Int32>::TypeId == element->type() ) | 	else if (ElementTraits<Int32>::TypeId == element->type()) | ||||||
| 	{ | 	{ | ||||||
| 		ConcreteElement<Int32>* concrete = dynamic_cast<ConcreteElement<Int32>* >(element.get()); | 		ConcreteElement<Int32>* concrete = dynamic_cast<ConcreteElement<Int32>*>(element.get()); | ||||||
| 		if ( concrete != NULL ) return concrete->value(); | 		if (concrete) return concrete->value(); | ||||||
| 	} | 	} | ||||||
| 	else if ( ElementTraits<Int64>::TypeId == element->type() ) | 	else if (ElementTraits<Int64>::TypeId == element->type()) | ||||||
| 	{ | 	{ | ||||||
| 		ConcreteElement<Int64>* concrete = dynamic_cast<ConcreteElement<Int64>* >(element.get()); | 		ConcreteElement<Int64>* concrete = dynamic_cast<ConcreteElement<Int64>*>(element.get()); | ||||||
| 		if ( concrete != NULL ) return concrete->value(); | 		if (concrete) return concrete->value(); | ||||||
| 	} | 	} | ||||||
| 	throw BadCastException("Invalid type mismatch!"); | 	throw Poco::BadCastException("Invalid type mismatch!"); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void Document::read(BinaryReader& reader) | void Document::read(BinaryReader& reader) | ||||||
| { | { | ||||||
| 	int size; | 	int size; | ||||||
| @@ -83,13 +83,13 @@ void Document::read(BinaryReader& reader) | |||||||
| 	unsigned char type; | 	unsigned char type; | ||||||
| 	reader >> type; | 	reader >> type; | ||||||
|  |  | ||||||
| 	while( type != '\0' ) | 	while (type != '\0') | ||||||
| 	{ | 	{ | ||||||
| 		Element::Ptr element; | 		Element::Ptr element; | ||||||
| 		 | 		 | ||||||
| 		std::string name = BSONReader(reader).readCString(); | 		std::string name = BSONReader(reader).readCString(); | ||||||
|  |  | ||||||
| 		switch(type) | 		switch (type) | ||||||
| 		{ | 		{ | ||||||
| 		case ElementTraits<double>::TypeId: | 		case ElementTraits<double>::TypeId: | ||||||
| 			element = new ConcreteElement<double>(name, 0); | 			element = new ConcreteElement<double>(name, 0); | ||||||
| @@ -101,16 +101,16 @@ void Document::read(BinaryReader& reader) | |||||||
| 			element = new ConcreteElement<std::string>(name, ""); | 			element = new ConcreteElement<std::string>(name, ""); | ||||||
| 			break; | 			break; | ||||||
| 		case ElementTraits<Document::Ptr>::TypeId: | 		case ElementTraits<Document::Ptr>::TypeId: | ||||||
| 			element = new ConcreteElement<Document::Ptr>(name, new Document()); | 			element = new ConcreteElement<Document::Ptr>(name, new Document); | ||||||
| 			break; | 			break; | ||||||
| 		case ElementTraits<Array::Ptr>::TypeId: | 		case ElementTraits<Array::Ptr>::TypeId: | ||||||
| 			element = new ConcreteElement<Array::Ptr>(name, new Array()); | 			element = new ConcreteElement<Array::Ptr>(name, new Array); | ||||||
| 			break; | 			break; | ||||||
| 		case ElementTraits<Binary::Ptr>::TypeId: | 		case ElementTraits<Binary::Ptr>::TypeId: | ||||||
| 			element = new ConcreteElement<Binary::Ptr>(name, new Binary()); | 			element = new ConcreteElement<Binary::Ptr>(name, new Binary); | ||||||
| 			break; | 			break; | ||||||
| 		case ElementTraits<ObjectId::Ptr>::TypeId: | 		case ElementTraits<ObjectId::Ptr>::TypeId: | ||||||
| 			element = new ConcreteElement<ObjectId::Ptr>(name, new ObjectId()); | 			element = new ConcreteElement<ObjectId::Ptr>(name, new ObjectId); | ||||||
| 			break; | 			break; | ||||||
| 		case ElementTraits<bool>::TypeId: | 		case ElementTraits<bool>::TypeId: | ||||||
| 			element = new ConcreteElement<bool>(name, false); | 			element = new ConcreteElement<bool>(name, false); | ||||||
| @@ -158,31 +158,31 @@ std::string Document::toString(int indent) const | |||||||
|  |  | ||||||
| 	oss << '{'; | 	oss << '{'; | ||||||
|  |  | ||||||
| 	if ( indent > 0 ) oss << std::endl; | 	if (indent > 0) oss << std::endl; | ||||||
|  |  | ||||||
|  |  | ||||||
| 	for(ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it) | 	for (ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it) | ||||||
| 	{ | 	{ | ||||||
| 		if ( it != _elements.begin() ) | 		if (it != _elements.begin()) | ||||||
| 		{ | 		{ | ||||||
| 			oss << ','; | 			oss << ','; | ||||||
| 			if ( indent > 0 ) oss << std::endl; | 			if (indent > 0) oss << std::endl; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		for(int i = 0; i < indent; ++i) oss << ' '; | 		for (int i = 0; i < indent; ++i) oss << ' '; | ||||||
|  |  | ||||||
| 		oss << '"' << (*it)->name() << '"'; | 		oss << '"' << (*it)->name() << '"'; | ||||||
| 		oss << (( indent > 0 ) ? " : " : ":"); | 		oss << (indent > 0  ? " : " : ":"); | ||||||
|  |  | ||||||
| 		oss << (*it)->toString(indent > 0 ? indent + 2 : 0); | 		oss << (*it)->toString(indent > 0 ? indent + 2 : 0); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if ( indent > 0 ) | 	if (indent > 0) | ||||||
| 	{ | 	{ | ||||||
| 		oss << std::endl; | 		oss << std::endl; | ||||||
| 		if ( indent >= 2 ) indent -= 2; | 		if (indent >= 2) indent -= 2; | ||||||
|  |  | ||||||
| 		for(int i = 0; i < indent; ++i) oss << ' '; | 		for (int i = 0; i < indent; ++i) oss << ' '; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	oss << '}'; | 	oss << '}'; | ||||||
| @@ -193,7 +193,7 @@ std::string Document::toString(int indent) const | |||||||
|  |  | ||||||
| void Document::write(BinaryWriter& writer) | void Document::write(BinaryWriter& writer) | ||||||
| { | { | ||||||
| 	if ( _elements.empty() ) | 	if (_elements.empty()) | ||||||
| 	{ | 	{ | ||||||
| 		writer << 5; | 		writer << 5; | ||||||
| 	} | 	} | ||||||
| @@ -201,7 +201,7 @@ void Document::write(BinaryWriter& writer) | |||||||
| 	{ | 	{ | ||||||
| 		std::stringstream sstream; | 		std::stringstream sstream; | ||||||
| 		Poco::BinaryWriter tempWriter(sstream); | 		Poco::BinaryWriter tempWriter(sstream); | ||||||
| 		for(ElementSet::iterator it = _elements.begin(); it != _elements.end(); ++it) | 		for (ElementSet::iterator it = _elements.begin(); it != _elements.end(); ++it) | ||||||
| 		{ | 		{ | ||||||
| 			tempWriter << static_cast<unsigned char>((*it)->type()); | 			tempWriter << static_cast<unsigned char>((*it)->type()); | ||||||
| 			BSONWriter(tempWriter).writeCString((*it)->name()); | 			BSONWriter(tempWriter).writeCString((*it)->name()); | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  Element | // Module:  Element | ||||||
| // | // | ||||||
| // Implementation of the Element class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  GetMoreRequest | // Module:  GetMoreRequest | ||||||
| // | // | ||||||
| // Implementation of the GetMoreRequest class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -24,8 +22,8 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| GetMoreRequest::GetMoreRequest(const std::string& collectionName, Int64 cursorID)  | GetMoreRequest::GetMoreRequest(const std::string& collectionName, Int64 cursorID): | ||||||
| 	: RequestMessage(MessageHeader::GetMore),  | 	RequestMessage(MessageHeader::OP_GET_MORE),  | ||||||
| 	_fullCollectionName(collectionName), | 	_fullCollectionName(collectionName), | ||||||
| 	_numberToReturn(100), | 	_numberToReturn(100), | ||||||
| 	_cursorID(cursorID) | 	_cursorID(cursorID) | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  InsertRequest | // Module:  InsertRequest | ||||||
| // | // | ||||||
| // Implementation of the InsertRequest class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -23,8 +21,8 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| InsertRequest::InsertRequest(const std::string& collectionName, Flags flags)  | InsertRequest::InsertRequest(const std::string& collectionName, Flags flags): | ||||||
| 	: RequestMessage(MessageHeader::Insert),  | 	RequestMessage(MessageHeader::OP_INSERT),  | ||||||
| 	_flags(flags), | 	_flags(flags), | ||||||
| 	_fullCollectionName(collectionName) | 	_fullCollectionName(collectionName) | ||||||
| { | { | ||||||
| @@ -38,12 +36,12 @@ InsertRequest::~InsertRequest() | |||||||
|  |  | ||||||
| void InsertRequest::buildRequest(BinaryWriter& writer) | void InsertRequest::buildRequest(BinaryWriter& writer) | ||||||
| { | { | ||||||
| 	//TODO: throw exception when no document is added | 	poco_assert (!_documents.empty()); | ||||||
|  |  | ||||||
| 	writer << _flags; | 	writer << _flags; | ||||||
| 	BSONWriter bsonWriter(writer); | 	BSONWriter bsonWriter(writer); | ||||||
| 	bsonWriter.writeCString(_fullCollectionName); | 	bsonWriter.writeCString(_fullCollectionName); | ||||||
| 	for(Document::Vector::iterator it = _documents.begin(); it != _documents.end(); ++it) | 	for (Document::Vector::iterator it = _documents.begin(); it != _documents.end(); ++it) | ||||||
| 	{ | 	{ | ||||||
| 		bsonWriter.write(*it); | 		bsonWriter.write(*it); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  JavaScriptCode | // Module:  JavaScriptCode | ||||||
| // | // | ||||||
| // Implementation of the JavaScriptCode class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  KillCursorsRequest | // Module:  KillCursorsRequest | ||||||
| // | // | ||||||
| // Implementation of the KillCursorsRequest class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -23,8 +21,8 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| KillCursorsRequest::KillCursorsRequest()  | KillCursorsRequest::KillCursorsRequest(): | ||||||
| 	: RequestMessage(MessageHeader::KillCursors) | 	RequestMessage(MessageHeader::OP_KILL_CURSORS) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -38,7 +36,7 @@ void KillCursorsRequest::buildRequest(BinaryWriter& writer) | |||||||
| { | { | ||||||
| 	writer << 0; // 0 - reserved for future use | 	writer << 0; // 0 - reserved for future use | ||||||
| 	writer << _cursors.size(); | 	writer << _cursors.size(); | ||||||
| 	for(std::vector<Int64>::iterator it = _cursors.begin(); it != _cursors.end(); ++it) | 	for (std::vector<Int64>::iterator it = _cursors.begin(); it != _cursors.end(); ++it) | ||||||
| 	{ | 	{ | ||||||
| 		writer << *it; | 		writer << *it; | ||||||
| 	}		 | 	}		 | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  Message | // Module:  Message | ||||||
| // | // | ||||||
| // Implementation of the Message class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -23,7 +21,8 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| Message::Message(MessageHeader::OpCode opcode) : _header(opcode) | Message::Message(MessageHeader::OpCode opcode):  | ||||||
|  | 	_header(opcode) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  MessageHeader | // Module:  MessageHeader | ||||||
| // | // | ||||||
| // Implementation of the MessageHeader class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -18,15 +16,17 @@ | |||||||
|  |  | ||||||
| #include "Poco/MongoDB/Message.h" | #include "Poco/MongoDB/Message.h" | ||||||
| #include "Poco/Exception.h" | #include "Poco/Exception.h" | ||||||
| #include "Poco/Net/SocketStream.h" |  | ||||||
| #include "Poco/StreamCopier.h" |  | ||||||
|  |  | ||||||
|  |  | ||||||
| namespace Poco { | namespace Poco { | ||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| MessageHeader::MessageHeader(OpCode opCode) : _messageLength(0), _requestID(0), _responseTo(0), _opCode(opCode) | MessageHeader::MessageHeader(OpCode opCode):  | ||||||
|  | 	_messageLength(0),  | ||||||
|  | 	_requestID(0),  | ||||||
|  | 	_responseTo(0),  | ||||||
|  | 	_opCode(opCode) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,42 +7,47 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  ObjectId | // Module:  ObjectId | ||||||
| // | // | ||||||
| // Implementation of the ObjectId class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| // SPDX-License-Identifier:	BSL-1.0 | // SPDX-License-Identifier:	BSL-1.0 | ||||||
| // | // | ||||||
|  |  | ||||||
|  |  | ||||||
| #include "Poco/MongoDB/ObjectId.h" | #include "Poco/MongoDB/ObjectId.h" | ||||||
| #include "Poco/Format.h" | #include "Poco/Format.h" | ||||||
|  | #include <cstring> | ||||||
|  |  | ||||||
|  |  | ||||||
| namespace Poco { | namespace Poco { | ||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| ObjectId::ObjectId() | ObjectId::ObjectId() | ||||||
| { | { | ||||||
| 	memset(_id, 0, sizeof(_id)); | 	std::memset(_id, 0, sizeof(_id)); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| ObjectId::ObjectId(const std::string& id) | ObjectId::ObjectId(const std::string& id) | ||||||
| { | { | ||||||
| 	poco_assert_dbg(id.size() == 24); | 	poco_assert_dbg(id.size() == 24); | ||||||
|  |  | ||||||
|     const char *p = id.c_str(); |     const char* p = id.c_str(); | ||||||
|     for (std::size_t i = 0; i < 12; ++i) { |     for (std::size_t i = 0; i < 12; ++i)  | ||||||
|  |     { | ||||||
| 		_id[i] = fromHex(p); | 		_id[i] = fromHex(p); | ||||||
| 		p += 2; | 		p += 2; | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| ObjectId::ObjectId(const ObjectId& copy) | ObjectId::ObjectId(const ObjectId& copy) | ||||||
| { | { | ||||||
| 	memcpy(_id, copy._id, sizeof(_id)); | 	std::memcpy(_id, copy._id, sizeof(_id)); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| ObjectId::~ObjectId() | ObjectId::~ObjectId() | ||||||
| { | { | ||||||
| } | } | ||||||
| @@ -52,7 +57,7 @@ std::string ObjectId::toString(const std::string& fmt) const | |||||||
| { | { | ||||||
| 	std::string s; | 	std::string s; | ||||||
|  |  | ||||||
| 	for(int i = 0; i < 12; ++i) | 	for (int i = 0; i < 12; ++i) | ||||||
| 	{ | 	{ | ||||||
| 		s += format(fmt, (unsigned int) _id[i]); | 		s += format(fmt, (unsigned int) _id[i]); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  QueryRequest | // Module:  QueryRequest | ||||||
| // | // | ||||||
| // Implementation of the QueryRequest class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -23,8 +21,8 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| QueryRequest::QueryRequest(const std::string& collectionName, QueryRequest::Flags flags)  | QueryRequest::QueryRequest(const std::string& collectionName, QueryRequest::Flags flags): | ||||||
| 	: RequestMessage(MessageHeader::Query),  | 	RequestMessage(MessageHeader::OP_QUERY),  | ||||||
| 	_flags(flags),  | 	_flags(flags),  | ||||||
| 	_fullCollectionName(collectionName), | 	_fullCollectionName(collectionName), | ||||||
| 	_numberToSkip(0),  | 	_numberToSkip(0),  | ||||||
| @@ -48,7 +46,7 @@ void QueryRequest::buildRequest(BinaryWriter& writer) | |||||||
| 	writer << _numberToReturn; | 	writer << _numberToReturn; | ||||||
| 	_selector.write(writer); | 	_selector.write(writer); | ||||||
|  |  | ||||||
| 	if ( ! _returnFieldSelector.empty() ) | 	if (!_returnFieldSelector.empty()) | ||||||
| 	{ | 	{ | ||||||
| 		_returnFieldSelector.write(writer); | 		_returnFieldSelector.write(writer); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  RegularExpression | // Module:  RegularExpression | ||||||
| // | // | ||||||
| // Implementation of the RegularExpression class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -29,7 +27,9 @@ RegularExpression::RegularExpression() | |||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| RegularExpression::RegularExpression(const std::string& pattern, const std::string& options) : _pattern(pattern), _options(options) | RegularExpression::RegularExpression(const std::string& pattern, const std::string& options):  | ||||||
|  | 	_pattern(pattern),  | ||||||
|  | 	_options(options) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -42,9 +42,9 @@ RegularExpression::~RegularExpression() | |||||||
| SharedPtr<Poco::RegularExpression> RegularExpression::createRE() const | SharedPtr<Poco::RegularExpression> RegularExpression::createRE() const | ||||||
| { | { | ||||||
| 	int options = 0; | 	int options = 0; | ||||||
| 	for(std::string::const_iterator optIt = _options.begin(); optIt != _options.end(); ++optIt) | 	for (std::string::const_iterator optIt = _options.begin(); optIt != _options.end(); ++optIt) | ||||||
| 	{ | 	{ | ||||||
| 		switch(*optIt) | 		switch (*optIt) | ||||||
| 		{ | 		{ | ||||||
| 		case 'i': // Case Insensitive | 		case 'i': // Case Insensitive | ||||||
| 			options |= Poco::RegularExpression::RE_CASELESS; | 			options |= Poco::RegularExpression::RE_CASELESS; | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  ReplicaSet | // Module:  ReplicaSet | ||||||
| // | // | ||||||
| // Implementation of the ReplicaSet class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -20,11 +18,13 @@ | |||||||
| #include "Poco/MongoDB/QueryRequest.h" | #include "Poco/MongoDB/QueryRequest.h" | ||||||
| #include "Poco/MongoDB/ResponseMessage.h" | #include "Poco/MongoDB/ResponseMessage.h" | ||||||
|  |  | ||||||
|  |  | ||||||
| namespace Poco { | namespace Poco { | ||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| ReplicaSet::ReplicaSet(const std::vector<Net::SocketAddress> &addresses) : _addresses(addresses) | ReplicaSet::ReplicaSet(const std::vector<Net::SocketAddress> &addresses):  | ||||||
|  | 	_addresses(addresses) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -38,10 +38,10 @@ Connection::Ptr ReplicaSet::findMaster() | |||||||
| { | { | ||||||
| 	Connection::Ptr master; | 	Connection::Ptr master; | ||||||
|  |  | ||||||
| 	for(std::vector<Net::SocketAddress>::iterator it = _addresses.begin(); it != _addresses.end(); ++it) | 	for (std::vector<Net::SocketAddress>::iterator it = _addresses.begin(); it != _addresses.end(); ++it) | ||||||
| 	{ | 	{ | ||||||
| 		master = isMaster(*it); | 		master = isMaster(*it); | ||||||
| 		if ( ! master.isNull() ) | 		if (!master.isNull()) | ||||||
| 		{ | 		{ | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| @@ -66,25 +66,25 @@ Connection::Ptr ReplicaSet::isMaster(const Net::SocketAddress& address) | |||||||
| 		ResponseMessage response; | 		ResponseMessage response; | ||||||
| 		conn->sendRequest(request, response); | 		conn->sendRequest(request, response); | ||||||
|  |  | ||||||
| 		if ( response.documents().size() > 0 ) | 		if (response.documents().size() > 0) | ||||||
| 		{ | 		{ | ||||||
| 			Document::Ptr doc = response.documents()[0]; | 			Document::Ptr doc = response.documents()[0]; | ||||||
| 			if ( doc->get<bool>("ismaster") ) | 			if (doc->get<bool>("ismaster")) | ||||||
| 			{ | 			{ | ||||||
| 				return conn; | 				return conn; | ||||||
| 			} | 			} | ||||||
| 			else if ( doc->exists("primary") ) | 			else if (doc->exists("primary")) | ||||||
| 			{ | 			{ | ||||||
| 				return isMaster(Net::SocketAddress(doc->get<std::string>("primary"))); | 				return isMaster(Net::SocketAddress(doc->get<std::string>("primary"))); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	catch(...) | 	catch (...) | ||||||
| 	{ | 	{ | ||||||
| 		conn = NULL; | 		conn = 0; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	return NULL;  | 	return 0;  | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  RequestMessage | // Module:  RequestMessage | ||||||
| // | // | ||||||
| // Implementation of the RequestMessage class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -25,7 +23,8 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| RequestMessage::RequestMessage(MessageHeader::OpCode opcode) : Message(opcode) | RequestMessage::RequestMessage(MessageHeader::OpCode opcode):  | ||||||
|  | 	Message(opcode) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  ResponseMessage | // Module:  ResponseMessage | ||||||
| // | // | ||||||
| // Implementation of the ResponseMessage class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -24,7 +22,12 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| ResponseMessage::ResponseMessage() : Message(MessageHeader::Reply), _responseFlags(0), _cursorID(0), _startingFrom(0), _numberReturned(0) | ResponseMessage::ResponseMessage(): | ||||||
|  | 	Message(MessageHeader::OP_REPLY),  | ||||||
|  | 	_responseFlags(0),  | ||||||
|  | 	_cursorID(0),  | ||||||
|  | 	_startingFrom(0),  | ||||||
|  | 	_numberReturned(0) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -57,7 +60,7 @@ void ResponseMessage::read(std::istream& istr) | |||||||
| 	reader >> _startingFrom; | 	reader >> _startingFrom; | ||||||
| 	reader >> _numberReturned; | 	reader >> _numberReturned; | ||||||
|  |  | ||||||
| 	for(int i = 0; i < _numberReturned; ++i) | 	for (int i = 0; i < _numberReturned; ++i) | ||||||
| 	{ | 	{ | ||||||
| 		Document::Ptr doc = new Document(); | 		Document::Ptr doc = new Document(); | ||||||
| 		doc->read(reader); | 		doc->read(reader); | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ | |||||||
| // Package: MongoDB | // Package: MongoDB | ||||||
| // Module:  UpdateRequest | // Module:  UpdateRequest | ||||||
| // | // | ||||||
| // Implementation of the UpdateRequest class. |  | ||||||
| // |  | ||||||
| // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. | ||||||
| // and Contributors. | // and Contributors. | ||||||
| // | // | ||||||
| @@ -23,8 +21,8 @@ namespace Poco { | |||||||
| namespace MongoDB { | namespace MongoDB { | ||||||
|  |  | ||||||
|  |  | ||||||
| UpdateRequest::UpdateRequest(const std::string& collectionName, UpdateRequest::Flags flags)  | UpdateRequest::UpdateRequest(const std::string& collectionName, UpdateRequest::Flags flags): | ||||||
| 	: RequestMessage(MessageHeader::Update),  | 	RequestMessage(MessageHeader::OP_UPDATE),  | ||||||
| 	_flags(flags), | 	_flags(flags), | ||||||
| 	_fullCollectionName(collectionName), | 	_fullCollectionName(collectionName), | ||||||
| 	_selector(), | 	_selector(), | ||||||
|   | |||||||
| @@ -8,11 +8,10 @@ | |||||||
| // | // | ||||||
| // SPDX-License-Identifier:	BSL-1.0 | // SPDX-License-Identifier:	BSL-1.0 | ||||||
| // | // | ||||||
| #include <iostream> |  | ||||||
|  |  | ||||||
| #include "Poco/DateTime.h" | #include "Poco/DateTime.h" | ||||||
| #include "Poco/ObjectPool.h" | #include "Poco/ObjectPool.h" | ||||||
|  |  | ||||||
| #include "Poco/MongoDB/InsertRequest.h" | #include "Poco/MongoDB/InsertRequest.h" | ||||||
| #include "Poco/MongoDB/QueryRequest.h" | #include "Poco/MongoDB/QueryRequest.h" | ||||||
| #include "Poco/MongoDB/DeleteRequest.h" | #include "Poco/MongoDB/DeleteRequest.h" | ||||||
| @@ -22,16 +21,17 @@ | |||||||
| #include "Poco/MongoDB/Cursor.h" | #include "Poco/MongoDB/Cursor.h" | ||||||
| #include "Poco/MongoDB/ObjectId.h" | #include "Poco/MongoDB/ObjectId.h" | ||||||
| #include "Poco/MongoDB/Binary.h" | #include "Poco/MongoDB/Binary.h" | ||||||
|  |  | ||||||
| #include "Poco/Net/NetException.h" | #include "Poco/Net/NetException.h" | ||||||
| #include "Poco/UUIDGenerator.h" | #include "Poco/UUIDGenerator.h" | ||||||
|  |  | ||||||
| #include "MongoDBTest.h" | #include "MongoDBTest.h" | ||||||
| #include "CppUnit/TestCaller.h" | #include "CppUnit/TestCaller.h" | ||||||
| #include "CppUnit/TestSuite.h" | #include "CppUnit/TestSuite.h" | ||||||
|  | #include <iostream> | ||||||
|  |  | ||||||
|  |  | ||||||
| using namespace Poco::MongoDB; | using namespace Poco::MongoDB; | ||||||
|  |  | ||||||
|  |  | ||||||
| Poco::MongoDB::Connection::Ptr MongoDBTest::_mongo; | Poco::MongoDB::Connection::Ptr MongoDBTest::_mongo; | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -79,6 +79,7 @@ void MongoDBTest::testInsertRequest() | |||||||
| 	_mongo->sendRequest(request); | 	_mongo->sendRequest(request); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void MongoDBTest::testQueryRequest() | void MongoDBTest::testQueryRequest() | ||||||
| { | { | ||||||
| 	Poco::MongoDB::QueryRequest request("team.players"); | 	Poco::MongoDB::QueryRequest request("team.players"); | ||||||
| @@ -120,6 +121,7 @@ void MongoDBTest::testQueryRequest() | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void MongoDBTest::testDBQueryRequest() | void MongoDBTest::testDBQueryRequest() | ||||||
| { | { | ||||||
| 	Database db("team"); | 	Database db("team"); | ||||||
| @@ -346,6 +348,7 @@ void MongoDBTest::testCommand() { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void MongoDBTest::testUUID() | void MongoDBTest::testUUID() | ||||||
| { | { | ||||||
| 	Poco::MongoDB::Document::Ptr club = new Poco::MongoDB::Document(); | 	Poco::MongoDB::Document::Ptr club = new Poco::MongoDB::Document(); | ||||||
|   | |||||||
| @@ -18,7 +18,6 @@ | |||||||
|  |  | ||||||
| #include "Poco/MongoDB/MongoDB.h" | #include "Poco/MongoDB/MongoDB.h" | ||||||
| #include "Poco/MongoDB/Connection.h" | #include "Poco/MongoDB/Connection.h" | ||||||
|  |  | ||||||
| #include "CppUnit/TestCase.h" | #include "CppUnit/TestCase.h" | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -27,7 +26,6 @@ class MongoDBTest: public CppUnit::TestCase | |||||||
| public: | public: | ||||||
| 	MongoDBTest(const std::string& name); | 	MongoDBTest(const std::string& name); | ||||||
|  |  | ||||||
|  |  | ||||||
| 	virtual ~MongoDBTest(); | 	virtual ~MongoDBTest(); | ||||||
|  |  | ||||||
| 	void testInsertRequest(); | 	void testInsertRequest(); | ||||||
| @@ -49,9 +47,7 @@ public: | |||||||
| 	static CppUnit::Test* suite(); | 	static CppUnit::Test* suite(); | ||||||
|  |  | ||||||
| private: | private: | ||||||
|  |  | ||||||
| 	static Poco::MongoDB::Connection::Ptr _mongo; | 	static Poco::MongoDB::Connection::Ptr _mongo; | ||||||
|  |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Guenter Obiltschnig
					Guenter Obiltschnig