|
17 | 17 | package com.mongodb.operation;
|
18 | 18 |
|
19 | 19 | import com.mongodb.MongoNamespace;
|
| 20 | +import com.mongodb.binding.ReadBinding; |
20 | 21 | import com.mongodb.binding.WriteBinding;
|
21 | 22 | import com.mongodb.connection.Connection;
|
22 | 23 | import com.mongodb.operation.OperationHelper.CallableWithConnection;
|
|
35 | 36 | * @mongodb.driver.manual reference/command/fsyncUnlock/ fsyncUnlock command
|
36 | 37 | * @since 3.2
|
37 | 38 | */
|
38 |
| -public class FsyncUnlockOperation implements WriteOperation<BsonDocument> { |
| 39 | +public class FsyncUnlockOperation implements WriteOperation<BsonDocument>, ReadOperation<BsonDocument> { |
| 40 | + private static final BsonDocument FSYNC_UNLOCK_COMMAND = new BsonDocument("fsyncUnlock", new BsonInt32(1)); |
| 41 | + |
| 42 | + /** |
| 43 | + * Unlocks the MongoDB server, allowing write operations to go through. |
| 44 | + * |
| 45 | + * @param binding the binding to execute in the context of |
| 46 | + * @return the result of the operation |
| 47 | + * @deprecated use {@link #execute(ReadBinding)} instead. |
| 48 | + */ |
| 49 | + @Deprecated |
39 | 50 | @Override
|
40 | 51 | public BsonDocument execute(final WriteBinding binding) {
|
41 | 52 | return withConnection(binding, new CallableWithConnection<BsonDocument>() {
|
42 | 53 | @Override
|
43 | 54 | public BsonDocument call(final Connection connection) {
|
44 | 55 | if (serverIsAtLeastVersionThreeDotTwo(connection.getDescription())) {
|
45 |
| - return executeWrappedCommandProtocol(binding, "admin", new BsonDocument("fsyncUnlock", new BsonInt32(1)), connection); |
| 56 | + return executeWrappedCommandProtocol(binding, "admin", FSYNC_UNLOCK_COMMAND, connection); |
46 | 57 | } else {
|
47 |
| - return connection.query(new MongoNamespace("admin", "$cmd.sys.unlock"), new BsonDocument(), null, 0, 1, 0, |
48 |
| - false, false, false, false, false, false, |
49 |
| - new BsonDocumentCodec()).getResults().get(0); |
| 58 | + return queryUnlock(connection); |
50 | 59 | }
|
51 | 60 | }
|
52 | 61 | });
|
53 | 62 | }
|
| 63 | + |
| 64 | + @Override |
| 65 | + public BsonDocument execute(final ReadBinding binding) { |
| 66 | + return withConnection(binding, new CallableWithConnection<BsonDocument>() { |
| 67 | + @Override |
| 68 | + public BsonDocument call(final Connection connection) { |
| 69 | + if (serverIsAtLeastVersionThreeDotTwo(connection.getDescription())) { |
| 70 | + return executeWrappedCommandProtocol(binding, "admin", FSYNC_UNLOCK_COMMAND, connection); |
| 71 | + } else { |
| 72 | + return queryUnlock(connection); |
| 73 | + } |
| 74 | + } |
| 75 | + }); |
| 76 | + } |
| 77 | + |
| 78 | + private BsonDocument queryUnlock(final Connection connection) { |
| 79 | + return connection.query(new MongoNamespace("admin", "$cmd.sys.unlock"), new BsonDocument(), null, 0, 1, 0, |
| 80 | + false, false, false, false, false, false, |
| 81 | + new BsonDocumentCodec()).getResults().get(0); |
| 82 | + } |
| 83 | + |
54 | 84 | }
|
0 commit comments