poco/MongoDB/include/Poco/MongoDB/QueryRequest.h

190 lines
4.4 KiB
C
Raw Normal View History

2013-02-02 21:52:49 +01:00
//
// QueryRequest.h
//
// Library: MongoDB
// Package: MongoDB
// Module: QueryRequest
//
// Definition of the QueryRequest class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
2013-02-02 21:52:49 +01:00
//
2013-03-12 04:49:54 +01:00
#ifndef MongoDB_QueryRequest_INCLUDED
#define MongoDB_QueryRequest_INCLUDED
2013-02-02 21:52:49 +01:00
#include "Poco/MongoDB/MongoDB.h"
#include "Poco/MongoDB/RequestMessage.h"
2013-02-13 19:10:57 +01:00
#include "Poco/MongoDB/Document.h"
2013-02-02 21:52:49 +01:00
2013-03-12 04:49:54 +01:00
namespace Poco {
namespace MongoDB {
2013-02-02 21:52:49 +01:00
enh(Poco): Mark deprecated functionality with C++ attributes and resolve internal usage of deprecated functions (#4551) * enh(poco): Replace deprecated comments with C++ deprecated attribute. * enh(Poco): Replace some deprecated functionality in Poco sources. (#4426) * enh(Poco): Replace more deprecated functionality in Poco sources. (#4426) * fix(CMake): Variable BUILD_SHARED_LIBS must be defined properly to create valid binaries. * enh: Code improvements done while resolving deprecated functionality (#4426) * Un-deprecate LocalDateTme (#4426) * enh(Poco): Replace usage of deprecated functionality with other functions/classes (#4426) * chore(SSL): temporarily un-deprecate SSL-related functionality (#4426) * chore(SSL): temporarily un-deprecate old MongoDB protocol functionality (#4426) * enh(Poco): Minor Hash improvements (#4426) * enh(Foundation): Compile deprecated hash tests only when POCO_TEST_DEPRECATED is enabled (#4426) * enh(Net): Compile deprecated Socket::select functionality only when POCO_TEST_DEPRECATED is enabled (#4426) * enh(Bonjour): Replace deprecated Socket::select with PollSet (#4426) * enh(Poco): Introduce POCO_DEPRECATED macro to have the ability to disable deprecation warnings in applications (#4426) * test(ODBC): add few asserts to testStoredProcedureDynamicVar * fix(ODBC): rename DynamicAny -> DynamicVar in tests * fix(ODBC): make Dignostics static members inline to prevent explicit instantiation warnings on windows --------- Co-authored-by: Alex Fabijanic <alex@pocoproject.org>
2024-07-29 08:16:50 +02:00
//class [[deprecated]] QueryRequest;
class QueryRequest;
2013-02-02 21:52:49 +01:00
class MongoDB_API QueryRequest: public RequestMessage
/// A request to query documents in a MongoDB database
/// using an OP_QUERY request.
2013-02-02 21:52:49 +01:00
{
public:
enum Flags
2013-02-02 21:52:49 +01:00
{
2022-07-07 11:18:20 +02:00
QUERY_DEFAULT = 0,
/// Do not set any flags.
2022-07-07 11:18:20 +02:00
QUERY_TAILABLE_CURSOR = 2,
/// Tailable means cursor is not closed when the last data is retrieved.
/// Rather, the cursor marks the final objects 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.
2022-07-07 11:18:20 +02:00
QUERY_SLAVE_OK = 4,
/// Allow query of replica slave. Normally these return an error except
/// for namespace "local".
2022-07-07 11:18:20 +02:00
// QUERY_OPLOG_REPLAY = 8 (internal replication use only - drivers should not implement)
2022-07-07 11:18:20 +02:00
QUERY_NO_CURSOR_TIMEOUT = 16,
2022-07-07 11:18:20 +02:00
/// The server normally times out idle cursors after an inactivity period
/// (10 minutes) to prevent excess memory use. Set this option to prevent that.
2022-07-07 11:18:20 +02:00
2013-02-02 21:52:49 +01:00
QUERY_AWAIT_DATA = 32,
2022-07-07 11:18:20 +02:00
/// 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.
2013-02-02 21:52:49 +01:00
QUERY_EXHAUST = 64,
2022-07-07 11:18:20 +02:00
/// 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.
2013-02-02 21:52:49 +01:00
QUERY_PARTIAL = 128
2022-07-07 11:18:20 +02:00
/// Get partial results from a mongos if some shards are down
/// (instead of throwing an error).
};
2013-02-02 21:52:49 +01:00
QueryRequest(const std::string& collectionName, Flags flags = QUERY_DEFAULT);
/// Creates a QueryRequest.
///
2022-07-07 11:18:20 +02:00
/// The full collection name is the concatenation of the database
/// 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
2013-02-02 21:52:49 +01:00
/// "foo.bar".
virtual ~QueryRequest();
/// Destroys the QueryRequest.
Flags getFlags() const;
/// Returns the flags.
2013-02-02 21:52:49 +01:00
void setFlags(Flags flag);
/// Set the flags.
2013-02-02 21:52:49 +01:00
std::string fullCollectionName() const;
/// Returns the <db>.<collection> used for this query.
2013-02-02 21:52:49 +01:00
Int32 getNumberToSkip() const;
/// Returns the number of documents to skip.
2013-02-02 21:52:49 +01:00
void setNumberToSkip(Int32 n);
/// Sets the number of documents to skip.
2013-02-02 21:52:49 +01:00
Int32 getNumberToReturn() const;
/// Returns the number of documents to return.
2013-02-02 21:52:49 +01:00
void setNumberToReturn(Int32 n);
/// Sets the number of documents to return (limit).
2013-02-02 21:52:49 +01:00
2013-02-20 22:20:55 +01:00
Document& selector();
/// Returns the selector document.
Document& returnFieldSelector();
/// Returns the field selector document.
2013-02-02 21:52:49 +01:00
protected:
void buildRequest(BinaryWriter& writer);
private:
2013-03-12 04:49:54 +01:00
Flags _flags;
2013-02-02 21:52:49 +01:00
std::string _fullCollectionName;
2013-03-12 04:49:54 +01:00
Int32 _numberToSkip;
Int32 _numberToReturn;
Document _selector;
Document _returnFieldSelector;
2013-02-02 21:52:49 +01:00
};
//
// inlines
//
inline QueryRequest::Flags QueryRequest::getFlags() const
2013-02-02 21:52:49 +01:00
{
return _flags;
}
inline void QueryRequest::setFlags(QueryRequest::Flags flags)
2013-02-02 21:52:49 +01:00
{
_flags = flags;
}
inline std::string QueryRequest::fullCollectionName() const
{
return _fullCollectionName;
}
2013-02-20 22:20:55 +01:00
inline Document& QueryRequest::selector()
2013-02-02 21:52:49 +01:00
{
2013-02-20 22:20:55 +01:00
return _selector;
2013-02-02 21:52:49 +01:00
}
2013-02-13 19:10:57 +01:00
inline Document& QueryRequest::returnFieldSelector()
2013-02-02 21:52:49 +01:00
{
return _returnFieldSelector;
}
inline Int32 QueryRequest::getNumberToSkip() const
2013-02-02 21:52:49 +01:00
{
return _numberToSkip;
}
inline void QueryRequest::setNumberToSkip(Int32 n)
2013-02-02 21:52:49 +01:00
{
_numberToSkip = n;
}
inline Int32 QueryRequest::getNumberToReturn() const
2013-02-02 21:52:49 +01:00
{
return _numberToReturn;
}
inline void QueryRequest::setNumberToReturn(Int32 n)
2013-02-02 21:52:49 +01:00
{
_numberToReturn = n;
}
2013-03-12 04:49:54 +01:00
} } // namespace Poco::MongoDB
2013-02-02 21:52:49 +01:00
#endif // MongoDB_QueryRequest_INCLUDED