Skip to content

Commit 30c654b

Browse files
committed
CXX-175 restore some things, add MONGO_CLIENT_API
1 parent 6bcfe51 commit 30c654b

File tree

6 files changed

+32
-27
lines changed

6 files changed

+32
-27
lines changed

src/mongo/client/bulk_operation_builder.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,29 @@ namespace mongo {
3737
, _ordered(ordered)
3838
{}
3939

40+
BulkOperationBuilder::~BulkOperationBuilder() {
41+
std::vector<WriteOperation*>::iterator it;
42+
for (it = _write_operations.begin(); it != _write_operations.end(); ++it)
43+
delete *it;
44+
}
45+
4046
BulkWriteOperation BulkOperationBuilder::find(const BSONObj& selector) {
4147
return BulkWriteOperation(this, selector);
4248
}
4349

4450
void BulkOperationBuilder::insert(const BSONObj& doc) {
4551
InsertWriteOperation* insert_op = new InsertWriteOperation(doc);
46-
_write_operations.enqueue(insert_op);
52+
enqueue(insert_op);
4753
}
4854

4955
void BulkOperationBuilder::execute(const WriteConcern* wc, std::vector<BSONObj>* results) {
5056
if (!_ordered)
51-
std::sort(_write_operations.ops.begin(), _write_operations.ops.end(), compare);
52-
_client->_write(_ns, _write_operations.ops, _ordered, wc, results);
57+
std::sort(_write_operations.begin(), _write_operations.end(), compare);
58+
_client->_write(_ns, _write_operations, _ordered, wc, results);
5359
}
5460

55-
void BulkOperationBuilder::enqueue(WriteOperation* const operation) {
56-
_write_operations.enqueue(operation);
61+
void BulkOperationBuilder::enqueue(WriteOperation* operation) {
62+
_write_operations.push_back(operation);
5763
}
5864

5965
} // namespace mongo

src/mongo/client/bulk_operation_builder.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
#include "mongo/bson/bsonobj.h"
2121
#include "mongo/client/bulk_write_operation.h"
22-
#include "mongo/client/write_operation.h"
2322

2423
namespace mongo {
2524

2625
class DBClientBase;
2726
class WriteConcern;
27+
class WriteOperation;
2828

2929
/**
3030
* Class for constructing and executing bulk operations against MongoDB via a
@@ -50,7 +50,7 @@ namespace mongo {
5050
* into batches instead of sending them individually to the server. This means
5151
* that unordered writes are non-deterministic. This is by design.
5252
*/
53-
class BulkOperationBuilder {
53+
class MONGO_CLIENT_API BulkOperationBuilder {
5454

5555
/* Enable operations of this type to append themselves to _write_operations */
5656
friend class BulkWriteOperation;
@@ -71,6 +71,9 @@ namespace mongo {
7171
*/
7272
BulkOperationBuilder(DBClientBase* const client, const std::string& ns, bool ordered);
7373

74+
/* Deletes all of the WriteOperations that were created during the Builder's lifetime */
75+
~BulkOperationBuilder();
76+
7477
/**
7578
* Supplies a filter to select a subset of documents on which to apply an operation.
7679
* The operation that is ultimately enqueued as part of this bulk operation depends on
@@ -100,7 +103,7 @@ namespace mongo {
100103
DBClientBase* const _client;
101104
const std::string _ns;
102105
const bool _ordered;
103-
ScopedWriteOperations _write_operations;
106+
std::vector<WriteOperation*> _write_operations;
104107

105108
void enqueue(WriteOperation* const operation);
106109
};

src/mongo/client/bulk_upsert_operation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace mongo {
2828
* Not to be instantiated directly. Comes into being via the upsert() method on
2929
* BulkWriteOperation.
3030
*/
31-
class BulkUpsertOperation {
31+
class MONGO_CLIENT_API BulkUpsertOperation {
3232

3333
friend class BulkWriteOperation;
3434

src/mongo/client/bulk_write_operation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace mongo {
2828
* Not to be instantiated directly. Comes into being via the find() method on
2929
* BulkOperationBuilder.
3030
*/
31-
class BulkWriteOperation {
31+
class MONGO_CLIENT_API BulkWriteOperation {
3232

3333
friend class BulkOperationBuilder;
3434

src/mongo/client/dbclient.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,19 @@ namespace mongo {
12201220

12211221
}
12221222

1223+
namespace {
1224+
struct ScopedWriteOperations {
1225+
ScopedWriteOperations() { }
1226+
~ScopedWriteOperations() {
1227+
vector<WriteOperation*>::const_iterator it;
1228+
for ( it = ops.begin(); it != ops.end(); ++it )
1229+
delete *it;
1230+
}
1231+
void enqueue(WriteOperation* op) { ops.push_back(op); }
1232+
std::vector<WriteOperation*> ops;
1233+
};
1234+
}
1235+
12231236
void DBClientBase::insert( const string & ns , BSONObj obj , int flags, const WriteConcern* wc ) {
12241237
vector<BSONObj> toInsert;
12251238
toInsert.push_back( obj );

src/mongo/client/write_operation.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,4 @@ namespace mongo {
9797
virtual void appendSelfToCommand(BSONArrayBuilder* batch) const = 0;
9898
};
9999

100-
/**
101-
* Helper struct to hold and clean up enqueued write operations.
102-
*/
103-
struct ScopedWriteOperations {
104-
ScopedWriteOperations() { }
105-
106-
~ScopedWriteOperations() {
107-
std::vector<WriteOperation*>::const_iterator it;
108-
for (it = ops.begin(); it != ops.end(); ++it)
109-
delete *it;
110-
}
111-
112-
void enqueue(WriteOperation* op) { ops.push_back(op); }
113-
114-
std::vector<WriteOperation*> ops;
115-
};
116-
117100
} // namespace mongo

0 commit comments

Comments
 (0)