1 | // |
---|---|
2 | // Cursor.cpp |
3 | // |
4 | // Library: MongoDB |
5 | // Package: MongoDB |
6 | // Module: Cursor |
7 | // |
8 | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/MongoDB/Cursor.h" |
16 | #include "Poco/MongoDB/GetMoreRequest.h" |
17 | #include "Poco/MongoDB/KillCursorsRequest.h" |
18 | |
19 | |
20 | namespace Poco { |
21 | namespace MongoDB { |
22 | |
23 | |
24 | Cursor::Cursor(const std::string& db, const std::string& collection, QueryRequest::Flags flags): |
25 | _query(db + '.' + collection, flags) |
26 | { |
27 | } |
28 | |
29 | |
30 | Cursor::Cursor(const std::string& fullCollectionName, QueryRequest::Flags flags): |
31 | _query(fullCollectionName, flags) |
32 | { |
33 | } |
34 | |
35 | |
36 | Cursor::~Cursor() |
37 | { |
38 | try |
39 | { |
40 | poco_assert_dbg(!_response.cursorID()); |
41 | } |
42 | catch (...) |
43 | { |
44 | } |
45 | } |
46 | |
47 | |
48 | ResponseMessage& Cursor::next(Connection& connection) |
49 | { |
50 | if (_response.cursorID() == 0) |
51 | { |
52 | connection.sendRequest(_query, _response); |
53 | } |
54 | else |
55 | { |
56 | Poco::MongoDB::GetMoreRequest getMore(_query.fullCollectionName(), _response.cursorID()); |
57 | getMore.setNumberToReturn(_query.getNumberToReturn()); |
58 | _response.clear(); |
59 | connection.sendRequest(getMore, _response); |
60 | } |
61 | return _response; |
62 | } |
63 | |
64 | |
65 | void Cursor::kill(Connection& connection) |
66 | { |
67 | if (_response.cursorID() != 0) |
68 | { |
69 | KillCursorsRequest killRequest; |
70 | killRequest.cursors().push_back(_response.cursorID()); |
71 | connection.sendRequest(killRequest); |
72 | } |
73 | _response.clear(); |
74 | } |
75 | |
76 | |
77 | } } // Namespace Poco::MongoDB |
78 |