private static <T> T executeWrappedCommandProtocol(final String database, final BsonDocument command, final FieldNameValidator fieldNameValidator, final Decoder<T> decoder, final ConnectionSource source, final ReadPreference readPreference) { Connection connection = source.getConnection(); try { return executeWrappedCommandProtocol(database, command, fieldNameValidator, decoder, connection, readPreference, new IdentityTransformer<T>(), source.getSessionContext()); } finally { connection.release(); } }
private void killCursor(final Connection connection) { if (serverCursor != null) { notNull("connection", connection); if (serverIsAtLeastVersionThreeDotTwo(connection.getDescription())) { connection.command(namespace.getDatabaseName(), asKillCursorsCommandDocument(), NO_OP_FIELD_NAME_VALIDATOR, ReadPreference.primary(), new BsonDocumentCodec(), connectionSource.getSessionContext()); } else { connection.killCursor(namespace, singletonList(serverCursor.getId())); } serverCursor = null; } }
private void getMore() { Connection connection = connectionSource.getConnection(); try { if (serverIsAtLeastVersionThreeDotTwo(connection.getDescription())) { try { initFromCommandResult(connection.command(namespace.getDatabaseName(), asGetMoreCommandDocument(), NO_OP_FIELD_NAME_VALIDATOR, ReadPreference.primary(), CommandResultDocumentCodec.create(decoder, "nextBatch"), connectionSource.getSessionContext())); } catch (MongoCommandException e) { throw translateCommandException(e, serverCursor); } } else { QueryResult<T> getMore = connection.getMore(namespace, serverCursor.getId(), getNumberToReturn(limit, batchSize, count), decoder); initFromQueryResult(getMore); } if (limitReached()) { killCursor(connection); } if (serverCursor == null) { this.connectionSource.release(); this.connectionSource = null; } } finally { connection.release(); } }
private static <T> T executeWrappedCommandProtocol(final String database, final BsonDocument command, final FieldNameValidator fieldNameValidator, final Decoder<T> decoder, final ConnectionSource source, final ReadPreference readPreference) { Connection connection = source.getConnection(); try { return executeWrappedCommandProtocol(database, command, fieldNameValidator, decoder, connection, readPreference, new IdentityTransformer<T>(), source.getSessionContext()); } finally { connection.release(); } }
private void killCursor(final Connection connection) { if (serverCursor != null) { notNull("connection", connection); if (serverIsAtLeastVersionThreeDotTwo(connection.getDescription())) { connection.command(namespace.getDatabaseName(), asKillCursorsCommandDocument(), NO_OP_FIELD_NAME_VALIDATOR, ReadPreference.primary(), new BsonDocumentCodec(), connectionSource.getSessionContext()); } else { connection.killCursor(namespace, singletonList(serverCursor.getId())); } serverCursor = null; } }
private void getMore() { Connection connection = connectionSource.getConnection(); try { if (serverIsAtLeastVersionThreeDotTwo(connection.getDescription())) { try { initFromCommandResult(connection.command(namespace.getDatabaseName(), asGetMoreCommandDocument(), NO_OP_FIELD_NAME_VALIDATOR, ReadPreference.primary(), CommandResultDocumentCodec.create(decoder, "nextBatch"), connectionSource.getSessionContext())); } catch (MongoCommandException e) { throw translateCommandException(e, serverCursor); } } else { QueryResult<T> getMore = connection.getMore(namespace, serverCursor.getId(), getNumberToReturn(limit, batchSize, count), decoder); initFromQueryResult(getMore); } if (limitReached()) { killCursor(connection); } if (serverCursor == null) { this.connectionSource.release(); this.connectionSource = null; } } finally { connection.release(); } }