Skip to content

Commit 55b1e25

Browse files
committed
Updated CommandOperationHelper so bindings must be provided
Ensures that readpreferences cannot accidentily default to primary() Refs: JAVA-1954
1 parent 5557a3f commit 55b1e25

29 files changed

+244
-255
lines changed

driver-core/src/main/com/mongodb/operation/AggregateExplainOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ public AggregateExplainOperation maxTime(final long maxTime, final TimeUnit time
8080

8181
@Override
8282
public BsonDocument execute(final ReadBinding binding) {
83-
return executeWrappedCommandProtocol(namespace.getDatabaseName(), getCommand(), binding);
83+
return executeWrappedCommandProtocol(binding, namespace.getDatabaseName(), getCommand());
8484
}
8585

8686
@Override
8787
public void executeAsync(final AsyncReadBinding binding, final SingleResultCallback<BsonDocument> callback) {
88-
executeWrappedCommandProtocolAsync(namespace.getDatabaseName(), getCommand(), binding, callback);
88+
executeWrappedCommandProtocolAsync(binding, namespace.getDatabaseName(), getCommand(), callback);
8989
}
9090

9191
private BsonDocument getCommand() {

driver-core/src/main/com/mongodb/operation/AggregateOperation.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,9 @@ public BatchCursor<T> execute(final ReadBinding binding) {
196196
return withConnection(binding, new CallableWithConnectionAndSource<BatchCursor<T>>() {
197197
@Override
198198
public BatchCursor<T> call(final ConnectionSource source, final Connection connection) {
199-
return executeWrappedCommandProtocol(namespace.getDatabaseName(), asCommandDocument(connection.getDescription()),
200-
CommandResultDocumentCodec.create(decoder,
201-
getFieldNameWithResults(connection
202-
.getDescription())),
203-
connection, binding.getReadPreference(), transformer(source, connection));
199+
return executeWrappedCommandProtocol(binding, namespace.getDatabaseName(), asCommandDocument(connection.getDescription()),
200+
CommandResultDocumentCodec.create(decoder, getFieldNameWithResults(connection.getDescription())),
201+
connection, transformer(source, connection));
204202
}
205203
});
206204
}
@@ -213,12 +211,11 @@ public void call(final AsyncConnectionSource source, final AsyncConnection conne
213211
if (t != null) {
214212
errorHandlingCallback(callback).onResult(null, t);
215213
} else {
216-
executeWrappedCommandProtocolAsync(namespace.getDatabaseName(), asCommandDocument(connection.getDescription()),
217-
CommandResultDocumentCodec.create(decoder,
218-
getFieldNameWithResults(connection
219-
.getDescription())),
220-
connection, binding.getReadPreference(), asyncTransformer(source, connection),
221-
releasingCallback(errorHandlingCallback(callback), source, connection));
214+
executeWrappedCommandProtocolAsync(binding, namespace.getDatabaseName(),
215+
asCommandDocument(connection.getDescription()),
216+
CommandResultDocumentCodec.create(decoder, getFieldNameWithResults(connection.getDescription())),
217+
connection, asyncTransformer(source, connection),
218+
releasingCallback(errorHandlingCallback(callback), source, connection));
222219
}
223220
}
224221
});

driver-core/src/main/com/mongodb/operation/AggregateToCollectionOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ public AggregateToCollectionOperation maxTime(final long maxTime, final TimeUnit
127127
@SuppressWarnings("unchecked")
128128
@Override
129129
public Void execute(final WriteBinding binding) {
130-
executeWrappedCommandProtocol(namespace.getDatabaseName(), getCommand(), new BsonDocumentCodec(), binding,
130+
executeWrappedCommandProtocol(binding, namespace.getDatabaseName(), getCommand(), new BsonDocumentCodec(),
131131
new VoidTransformer<BsonDocument>());
132132

133133
return null;
134134
}
135135

136136
@Override
137137
public void executeAsync(final AsyncWriteBinding binding, final SingleResultCallback<Void> callback) {
138-
executeWrappedCommandProtocolAsync(namespace.getDatabaseName(), getCommand(), new BsonDocumentCodec(), binding,
138+
executeWrappedCommandProtocolAsync(binding, namespace.getDatabaseName(), getCommand(), new BsonDocumentCodec(),
139139
new VoidTransformer<BsonDocument>(), callback);
140140
}
141141

0 commit comments

Comments
 (0)