Skip to content

Commit

Permalink
enh(MongoDB): handle deprecated functionality (#4426)
Browse files Browse the repository at this point in the history
  • Loading branch information
matejk committed Nov 30, 2024
1 parent d8a423c commit f97bf7f
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 71 deletions.
4 changes: 1 addition & 3 deletions MongoDB/include/Poco/MongoDB/BSONReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ class MongoDB_API BSONReader
{
}

virtual ~BSONReader()
virtual ~BSONReader() = default;
/// Destroys the BSONReader.
{
}

template<typename T>
void read(T& t)
Expand Down
4 changes: 1 addition & 3 deletions MongoDB/include/Poco/MongoDB/BSONWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ class MongoDB_API BSONWriter
{
}

virtual ~BSONWriter()
virtual ~BSONWriter() = default;
/// Destroys the BSONWriter.
{
}

template<typename T>
void write(T& t)
Expand Down
2 changes: 1 addition & 1 deletion MongoDB/include/Poco/MongoDB/Cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MongoDB_API Cursor: public Document
Cursor(const Document& aggregationResponse);
/// Creates a Cursor for the given agregation query response.

virtual ~Cursor();
~Cursor() override;
/// Destroys the Cursor.

ResponseMessage& next(Connection& connection);
Expand Down
13 changes: 7 additions & 6 deletions MongoDB/include/Poco/MongoDB/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ class MongoDB_API Database
///
/// If the command fails, -1 is returned.

//[[deprecated]]
POCO_DEPRECATED("Use new wire protocol")
Poco::SharedPtr<Poco::MongoDB::QueryRequest> createCommand() const;
/// Creates a QueryRequest for a command. (old wire protocol)

//[[deprecated]]
POCO_DEPRECATED("Use new wire protocol")
Poco::SharedPtr<Poco::MongoDB::QueryRequest> createCountRequest(const std::string& collectionName) const;
/// Creates a QueryRequest to count the given collection.
/// The collectionname must not contain the database name. (old wire protocol)
Expand All @@ -86,12 +86,12 @@ class MongoDB_API Database
/// Creates a DeleteRequest to delete documents in the given collection.
/// The collectionname must not contain the database name. (old wire protocol)

//[[deprecated]]
POCO_DEPRECATED("Use new wire protocol")
Poco::SharedPtr<Poco::MongoDB::InsertRequest> createInsertRequest(const std::string& collectionName) const;
/// Creates an InsertRequest to insert new documents in the given collection.
/// The collectionname must not contain the database name. (old wire protocol)

//[[deprecated]]
POCO_DEPRECATED("Use new wire protocol")
Poco::SharedPtr<Poco::MongoDB::QueryRequest> createQueryRequest(const std::string& collectionName) const;
/// Creates a QueryRequest. (old wire protocol)
/// The collectionname must not contain the database name.
Expand All @@ -110,6 +110,7 @@ class MongoDB_API Database
Poco::SharedPtr<Poco::MongoDB::OpMsgCursor> createOpMsgCursor(const std::string& collectionName) const;
/// Creates OpMsgCursor. (new wire protocol)

POCO_DEPRECATED("Use new wire protocol")
Poco::MongoDB::Document::Ptr ensureIndex(Connection& connection,
const std::string& collection,
const std::string& indexName,
Expand All @@ -121,12 +122,12 @@ class MongoDB_API Database
/// Creates an index. The document returned is the result of a getLastError call.
/// For more info look at the ensureIndex information on the MongoDB website. (old wire protocol)

//[[deprecated]]
POCO_DEPRECATED("Use new wire protocol")
Document::Ptr getLastErrorDoc(Connection& connection) const;
/// Sends the getLastError command to the database and returns the error document.
/// (old wire protocol)

//[[deprecated]]
POCO_DEPRECATED("Use new wire protocol")
std::string getLastError(Connection& connection) const;
/// Sends the getLastError command to the database and returns the err element
/// from the error document. When err is null, an empty string is returned.
Expand Down
6 changes: 3 additions & 3 deletions MongoDB/include/Poco/MongoDB/DeleteRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
namespace Poco {
namespace MongoDB {

//class POCO_DEPRECATED("Use new wire protocol") DeleteRequest;
class POCO_DEPRECATED("Use new wire protocol") DeleteRequest;

class MongoDB_API DeleteRequest: public RequestMessage
/// A DeleteRequest is used to delete one ore more documents from a database.
Expand Down Expand Up @@ -64,7 +64,7 @@ class MongoDB_API DeleteRequest: public RequestMessage
/// If justOne is true, only the first matching document will
/// be removed (the same as using flag DELETE_SINGLE_REMOVE).

virtual ~DeleteRequest();
~DeleteRequest() override;
/// Destructor

Flags flags() const;
Expand All @@ -77,7 +77,7 @@ class MongoDB_API DeleteRequest: public RequestMessage
/// Returns the selector document.

protected:
void buildRequest(BinaryWriter& writer);
void buildRequest(BinaryWriter& writer) override;
/// Writes the OP_DELETE request to the writer.

private:
Expand Down
7 changes: 3 additions & 4 deletions MongoDB/include/Poco/MongoDB/GetMoreRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
namespace Poco {
namespace MongoDB {

//class [[deprecated]] GetMoreRequest;
class GetMoreRequest;
class POCO_DEPRECATED("Use new wire protocol") GetMoreRequest;

class MongoDB_API GetMoreRequest: public RequestMessage
/// A GetMoreRequest is used to query the database for more documents in a collection
Expand All @@ -42,7 +41,7 @@ class MongoDB_API GetMoreRequest: public RequestMessage
/// "foo.bar". The cursorID has been returned by the response on the query request.
/// By default the numberToReturn is set to 100.

virtual ~GetMoreRequest();
~GetMoreRequest() override;
/// Destroys the GetMoreRequest.

Int32 getNumberToReturn() const;
Expand All @@ -55,7 +54,7 @@ class MongoDB_API GetMoreRequest: public RequestMessage
/// Returns the cursor ID.

protected:
void buildRequest(BinaryWriter& writer);
void buildRequest(BinaryWriter& writer) override;

private:
std::string _fullCollectionName;
Expand Down
7 changes: 3 additions & 4 deletions MongoDB/include/Poco/MongoDB/InsertRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
namespace Poco {
namespace MongoDB {

//class [[deprecated]] InsertRequest;
class InsertRequest;
class POCO_DEPRECATED("Use new wire protocol") InsertRequest;

class MongoDB_API InsertRequest: public RequestMessage
/// A request for inserting one or more documents to the database
Expand Down Expand Up @@ -55,7 +54,7 @@ class MongoDB_API InsertRequest: public RequestMessage
/// for the database "foo" and the collection "bar", the full collection name is
/// "foo.bar".

virtual ~InsertRequest();
~InsertRequest() override;
/// Destroys the InsertRequest.

Document& addNewDocument();
Expand All @@ -67,7 +66,7 @@ class MongoDB_API InsertRequest: public RequestMessage
/// Returns the documents to insert into the database.

protected:
void buildRequest(BinaryWriter& writer);
void buildRequest(BinaryWriter& writer) override;

private:
Int32 _flags;
Expand Down
2 changes: 1 addition & 1 deletion MongoDB/include/Poco/MongoDB/JavaScriptCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MongoDB_API JavaScriptCode
JavaScriptCode();
/// Creates an empty JavaScriptCode object.

virtual ~JavaScriptCode();
~JavaScriptCode();
/// Destroys the JavaScriptCode.

void setCode(const std::string& code);
Expand Down
4 changes: 2 additions & 2 deletions MongoDB/include/Poco/MongoDB/KillCursorsRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class MongoDB_API KillCursorsRequest: public RequestMessage
KillCursorsRequest();
/// Creates a KillCursorsRequest.

virtual ~KillCursorsRequest();
~KillCursorsRequest() override;
/// Destroys the KillCursorsRequest.

std::vector<Int64>& cursors();
/// The internal list of cursors.

protected:
void buildRequest(BinaryWriter& writer);
void buildRequest(BinaryWriter& writer) override;
std::vector<Int64> _cursors;
};

Expand Down
4 changes: 0 additions & 4 deletions MongoDB/include/Poco/MongoDB/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@
#define MongoDB_Message_INCLUDED


#include "Poco/Net/Socket.h"
#include "Poco/BinaryReader.h"
#include "Poco/BinaryWriter.h"
#include "Poco/MongoDB/MongoDB.h"
#include "Poco/MongoDB/MessageHeader.h"
#include <sstream>


namespace Poco {
Expand Down
33 changes: 11 additions & 22 deletions MongoDB/include/Poco/MongoDB/MessageHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
#ifndef MongoDB_MessageHeader_INCLUDED
#define MongoDB_MessageHeader_INCLUDED


#include "Poco/MongoDB/MongoDB.h"
#include "Poco/MongoDB/MessageHeader.h"


namespace Poco {
namespace MongoDB {

class BinaryReader;
class BinaryWriter;

class Message; // Required to disambiguate friend declaration in MessageHeader.
namespace MongoDB {

class Message; // Required to disambiguate friend declaration in MessageHeader.

class MongoDB_API MessageHeader
/// Represents the message header which is always prepended to a
Expand All @@ -38,24 +37,14 @@ class MongoDB_API MessageHeader

enum OpCode
{
#if false
// Opcodes deprecated in MongoDB 5.0
OP_REPLY [[deprecated]] = 1,
OP_UPDATE [[deprecated]] = 2001,
OP_INSERT [[deprecated]] = 2002,
OP_QUERY [[deprecated]] = 2004,
OP_GET_MORE [[deprecated]] = 2005,
OP_DELETE [[deprecated]] = 2006,
OP_KILL_CURSORS [[deprecated]] = 2007,
#else
OP_REPLY = 1,
OP_UPDATE = 2001,
OP_INSERT = 2002,
OP_QUERY = 2004,
OP_GET_MORE = 2005,
OP_DELETE = 2006,
OP_KILL_CURSORS = 2007,
#endif
OP_REPLY POCO_DEPRECATED("Use new wire protocol") = 1,
OP_UPDATE POCO_DEPRECATED("Use new wire protocol") = 2001,
OP_INSERT POCO_DEPRECATED("Use new wire protocol") = 2002,
OP_QUERY POCO_DEPRECATED("Use new wire protocol") = 2004,
OP_GET_MORE POCO_DEPRECATED("Use new wire protocol") = 2005,
OP_DELETE POCO_DEPRECATED("Use new wire protocol") = 2006,
OP_KILL_CURSORS POCO_DEPRECATED("Use new wire protocol") = 2007,

/// Opcodes supported in MongoDB 5.1 and later
OP_COMPRESSED = 2012,
Expand Down
4 changes: 2 additions & 2 deletions MongoDB/include/Poco/MongoDB/ObjectId.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ class MongoDB_API ObjectId
inline Timestamp ObjectId::timestamp() const
{
int time;
char* T = (char *) &time;
auto* T = reinterpret_cast<unsigned char *>(&time);
T[0] = _id[3];
T[1] = _id[2];
T[2] = _id[1];
T[3] = _id[0];
return Timestamp::fromEpochTime((time_t) time);
return Timestamp::fromEpochTime(static_cast<time_t>(time));
}


Expand Down
2 changes: 1 addition & 1 deletion MongoDB/include/Poco/MongoDB/OpMsgCursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MongoDB_API OpMsgCursor: public Document
OpMsgCursor(const std::string& dbname, const std::string& collectionName);
/// Creates a OpMsgCursor for the given database and collection.

virtual ~OpMsgCursor();
~OpMsgCursor() override;
/// Destroys the OpMsgCursor.

void setEmptyFirstBatch(bool empty);
Expand Down
2 changes: 1 addition & 1 deletion MongoDB/include/Poco/MongoDB/OpMsgMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class MongoDB_API OpMsgMessage: public Message
OpMsgMessage(const std::string& databaseName, const std::string& collectionName, UInt32 flags = MSG_FLAGS_DEFAULT);
/// Creates an OpMsgMessage for requests.

virtual ~OpMsgMessage();
~OpMsgMessage() override;

const std::string& databaseName() const;

Expand Down
4 changes: 2 additions & 2 deletions MongoDB/include/Poco/MongoDB/PoolableConnectionFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class PoolableObjectFactory<MongoDB::Connection, MongoDB::Connection::Ptr>
public:
PoolableObjectFactory(Net::SocketAddress& address):
_address(address),
_pSocketFactory(0)
_pSocketFactory(nullptr)
{
}

PoolableObjectFactory(const std::string& address):
_address(address),
_pSocketFactory(0)
_pSocketFactory(nullptr)
{
}

Expand Down
7 changes: 4 additions & 3 deletions MongoDB/include/Poco/MongoDB/QueryRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
namespace Poco {
namespace MongoDB {

//class [[deprecated]] QueryRequest;
class QueryRequest;

class MongoDB_API QueryRequest: public RequestMessage
/// A request to query documents in a MongoDB database
/// using an OP_QUERY request.
///
/// Generally deprecated but still supported for server hello (queryServerHello).
{
public:
enum Flags
Expand Down Expand Up @@ -83,7 +84,7 @@ class MongoDB_API QueryRequest: public RequestMessage
/// for the database "foo" and the collection "bar", the full collection name is
/// "foo.bar".

virtual ~QueryRequest();
~QueryRequest() override;
/// Destroys the QueryRequest.

Flags getFlags() const;
Expand Down Expand Up @@ -114,7 +115,7 @@ class MongoDB_API QueryRequest: public RequestMessage
/// Returns the field selector document.

protected:
void buildRequest(BinaryWriter& writer);
void buildRequest(BinaryWriter& writer) override;

private:
Flags _flags;
Expand Down
6 changes: 4 additions & 2 deletions MongoDB/include/Poco/MongoDB/RequestMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define MongoDB_RequestMessage_INCLUDED


#include "Poco/BinaryWriter.h"
#include "Poco/MongoDB/MongoDB.h"
#include "Poco/MongoDB/Message.h"
#include <ostream>
Expand All @@ -26,17 +27,18 @@
namespace Poco {
namespace MongoDB {

//class [[deprecated]] RequestMessage;
class RequestMessage;

class MongoDB_API RequestMessage: public Message
/// Base class for a request sent to the MongoDB server.
///
/// Generally deprecated but still supported for server hello (queryServerHello).
{
public:
explicit RequestMessage(MessageHeader::OpCode opcode);
/// Creates a RequestMessage using the given opcode.

virtual ~RequestMessage();
~RequestMessage() override;
/// Destroys the RequestMessage.

void send(std::ostream& ostr);
Expand Down
5 changes: 3 additions & 2 deletions MongoDB/include/Poco/MongoDB/ResponseMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
namespace Poco {
namespace MongoDB {

//class [[deprecated]] ResponseMessage;
class ResponseMessage;

class MongoDB_API ResponseMessage: public Message
/// This class represents a response (OP_REPLY) from MongoDB.
///
/// Generally deprecated but still supported for server hello (queryServerHello).
{
public:
ResponseMessage();
Expand All @@ -41,7 +42,7 @@ class MongoDB_API ResponseMessage: public Message
ResponseMessage(const Int64& cursorID);
/// Creates an ResponseMessage for existing cursor ID.

virtual ~ResponseMessage();
~ResponseMessage() override;
/// Destroys the ResponseMessage.

Int64 cursorID() const;
Expand Down
Loading

0 comments on commit f97bf7f

Please sign in to comment.