package com.mongodb.operation;
import com.mongodb.async.SingleResultCallback;
import com.mongodb.binding.AsyncReadBinding;
import com.mongodb.binding.ReadBinding;
import com.mongodb.connection.ConnectionDescription;
import com.mongodb.connection.ServerDescription;
import org.bson.BsonDocument;
import org.bson.codecs.Decoder;
import static com.mongodb.assertions.Assertions.notNull;
import static com.mongodb.operation.CommandOperationHelper.CommandCreator;
import static com.mongodb.operation.CommandOperationHelper.executeCommand;
import static com.mongodb.operation.CommandOperationHelper.executeCommandAsync;
@Deprecated
public class CommandReadOperation<T> implements AsyncReadOperation<T>, ReadOperation<T> {
private final String databaseName;
private final BsonDocument command;
private final Decoder<T> decoder;
public CommandReadOperation(final String databaseName, final BsonDocument command, final Decoder<T> decoder) {
this.databaseName = notNull("databaseName", databaseName);
this.command = notNull("command", command);
this.decoder = notNull("decoder", decoder);
}
@Override
public T execute(final ReadBinding binding) {
return executeCommand(binding, databaseName, getCommandCreator(), decoder, false);
}
@Override
public void executeAsync(final AsyncReadBinding binding, final SingleResultCallback<T> callback) {
executeCommandAsync(binding, databaseName, getCommandCreator(), decoder, false, callback);
}
private CommandCreator getCommandCreator() {
return new CommandCreator() {
@Override
public BsonDocument create(final ServerDescription serverDescription, final ConnectionDescription connectionDescription) {
return command;
}
};
}
}