aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/MongoDB/src/Cursor.cpp
blob: 69031e0ab653bef0b2be1be2d8400aea4d90c2fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Cursor.cpp
//
// Library: MongoDB
// Package: MongoDB
// Module:  Cursor
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier:	BSL-1.0
//


#include "Poco/MongoDB/Cursor.h"
#include "Poco/MongoDB/GetMoreRequest.h"
#include "Poco/MongoDB/KillCursorsRequest.h"


namespace Poco {
namespace MongoDB {


Cursor::Cursor(const std::string& db, const std::string& collection, QueryRequest::Flags flags):
	_query(db + '.' + collection, flags)
{
}


Cursor::Cursor(const std::string& fullCollectionName, QueryRequest::Flags flags):
	_query(fullCollectionName, flags)
{
}


Cursor::~Cursor()
{
	try
	{
		poco_assert_dbg(!_response.cursorID());
	}
	catch (...)
	{
	}
}


ResponseMessage& Cursor::next(Connection& connection)
{
	if (_response.cursorID() == 0)
	{
		connection.sendRequest(_query, _response);
	}
	else
	{
		Poco::MongoDB::GetMoreRequest getMore(_query.fullCollectionName(), _response.cursorID());
		getMore.setNumberToReturn(_query.getNumberToReturn());
		_response.clear();
		connection.sendRequest(getMore, _response);
	}
	return _response;
}


void Cursor::kill(Connection& connection)
{
	if (_response.cursorID() != 0)
	{
		KillCursorsRequest killRequest;
		killRequest.cursors().push_back(_response.cursorID());
		connection.sendRequest(killRequest);
	}
	_response.clear();
}


} } // Namespace Poco::MongoDB