@Override public <T> T execute(final WriteOperation<T> operation, final ReadConcern readConcern, @Nullable final ClientSession session) { ClientSession actualClientSession = getClientSession(session); WriteBinding binding = getWriteBinding(readConcern, actualClientSession, session == null && actualClientSession != null); try { return operation.execute(binding); } catch (MongoException e) { labelException(session, e); throw e; } finally { binding.release(); } }
static <T> T executeWrappedCommandProtocol(final WriteBinding binding, final String database, final BsonDocument command, final Decoder<BsonDocument> decoder, final Connection connection, final CommandTransformer<BsonDocument, T> transformer) { notNull("binding", binding); return executeWrappedCommandProtocol(database, command, decoder, connection, primary(), transformer, binding.getSessionContext()); }
static <T> T withConnection(final WriteBinding binding, final CallableWithConnection<T> callable) { ConnectionSource source = binding.getWriteConnectionSource(); try { return withConnectionSource(source, callable); } finally { source.release(); } }
static <T> T executeWrappedCommandProtocol(final WriteBinding binding, final String database, final BsonDocument command, final FieldNameValidator fieldNameValidator, final Decoder<BsonDocument> decoder, final Connection connection, final CommandTransformer<BsonDocument, T> transformer) { notNull("binding", binding); return executeWrappedCommandProtocol(database, command, fieldNameValidator, decoder, connection, primary(), transformer, binding.getSessionContext()); }
static <T> T withReleasableConnection(final WriteBinding binding, final CallableWithConnectionAndSource<T> callable) { ConnectionSource source = binding.getWriteConnectionSource(); try { return callable.call(source, source.getConnection()); } finally { source.release(); } }
@Override public <T> T execute(final WriteOperation<T> operation, final ReadConcern readConcern, @Nullable final ClientSession session) { ClientSession actualClientSession = getClientSession(session); WriteBinding binding = getWriteBinding(readConcern, actualClientSession, session == null && actualClientSession != null); try { return operation.execute(binding); } catch (MongoException e) { labelException(session, e); throw e; } finally { binding.release(); } }
static BsonDocument executeWrappedCommandProtocol(final WriteBinding binding, final String database, final BsonDocument command, final Connection connection) { notNull("binding", binding); return executeWrappedCommandProtocol(database, command, new BsonDocumentCodec(), connection, primary(), binding.getSessionContext()); }
static <T> T withReleasableConnection(final WriteBinding binding, final MongoException connectionException, final CallableWithConnectionAndSource<T> callable) { ConnectionSource source = null; Connection connection; try { source = binding.getWriteConnectionSource(); connection = source.getConnection(); } catch (Throwable t){ if (source != null) { source.release(); } throw connectionException; } try { return callable.call(source, connection); } finally { source.release(); } }
@Override public <T> T execute(final WriteOperation<T> operation, final ReadConcern readConcern, @Nullable final ClientSession session) { ClientSession actualClientSession = getClientSession(session); WriteBinding binding = getWriteBinding(readConcern, actualClientSession, session == null && actualClientSession != null); try { return operation.execute(binding); } catch (MongoException e) { labelException(session, e); throw e; } finally { binding.release(); } }
private BsonDocument executeCommand(final Connection connection, final BulkWriteBatch batch, final WriteBinding binding) { return connection.command(namespace.getDatabaseName(), batch.getCommand(), NO_OP_FIELD_NAME_VALIDATOR, null, batch.getDecoder(), binding.getSessionContext(), shouldAcknowledge(batch, writeConcern), batch.getPayload(), batch.getFieldNameValidator()); }
static <D, T> T executeWrappedCommandProtocol(final WriteBinding binding, final String database, final BsonDocument command, final FieldNameValidator fieldNameValidator, final Decoder<D> decoder, final CommandTransformer<D, T> transformer) { ConnectionSource source = binding.getWriteConnectionSource(); try { return transformer.apply(executeWrappedCommandProtocol(database, command, fieldNameValidator, decoder, source, primary()), source.getServerDescription().getAddress()); } finally { source.release(); } }
@Override public Void execute(final WriteBinding binding) { isTrue("in transaction", binding.getSessionContext().hasActiveTransaction()); return executeRetryableCommand(binding, "admin", null, new NoOpFieldNameValidator(), new BsonDocumentCodec(), getCommandCreator(), writeConcernErrorTransformer()); }
static <T> T withConnection(final WriteBinding binding, final CallableWithConnection<T> callable) { ConnectionSource source = binding.getWriteConnectionSource(); try { return withConnectionSource(source, callable); } finally { source.release(); } }
@Override public T execute(final WriteBinding binding) { return executeRetryableCommand(binding, getDatabaseName(), null, getFieldNameValidator(), CommandResultDocumentCodec.create(getDecoder(), "value"), getCommandCreator(binding.getSessionContext()), FindAndModifyHelper.<T>transformer()); }
static <T> T withReleasableConnection(final WriteBinding binding, final CallableWithConnectionAndSource<T> callable) { ConnectionSource source = binding.getWriteConnectionSource(); try { return callable.call(source, source.getConnection()); } finally { source.release(); } }
@Override public BulkWriteResult call(final ConnectionSource connectionSource, final Connection connection) { validateWriteRequestsAndReleaseConnectionIfError(connection); if (getWriteConcern().isAcknowledged() || serverIsAtLeastVersionThreeDotSix(connection.getDescription())) { BulkWriteBatch bulkWriteBatch = BulkWriteBatch.createBulkWriteBatch(namespace, connectionSource.getServerDescription(), connection.getDescription(), ordered, writeConcern, bypassDocumentValidation, retryWrites, writeRequests, binding.getSessionContext()); return executeBulkWriteBatch(binding, connection, bulkWriteBatch); } else { return executeLegacyBatches(connection); } } });
static <T> T withReleasableConnection(final WriteBinding binding, final MongoException connectionException, final CallableWithConnectionAndSource<T> callable) { ConnectionSource source = null; Connection connection; try { source = binding.getWriteConnectionSource(); connection = source.getConnection(); } catch (Throwable t){ if (source != null) { source.release(); } throw connectionException; } try { return callable.call(source, connection); } finally { source.release(); } }
@Override public BulkWriteResult call(final ConnectionSource source, final Connection connection) { if (!isRetryableWrite(retryWrites, writeConcern, source.getServerDescription(), connection.getDescription(), binding.getSessionContext())) { return checkMongoWriteConcernWithResponseException(connection); } else { try { retryBatch.addResult(executeCommand(connection, retryBatch, binding)); } catch (Throwable t) { return checkMongoWriteConcernWithResponseException(connection); } return executeBulkWriteBatch(binding, connection, retryBatch.getNextBatch()); } }
static <D, T> T executeWrappedCommandProtocol(final WriteBinding binding, final String database, final BsonDocument command, final FieldNameValidator fieldNameValidator, final Decoder<D> decoder, final CommandTransformer<D, T> transformer) { ConnectionSource source = binding.getWriteConnectionSource(); try { return transformer.apply(executeWrappedCommandProtocol(database, command, fieldNameValidator, decoder, source, primary()), source.getServerDescription().getAddress()); } finally { source.release(); } }
command = commandCreator.create(source.getServerDescription(), connection.getDescription()); return transformer.apply(connection.command(database, command, fieldNameValidator, readPreference, commandResultDecoder, binding.getSessionContext()), connection.getDescription().getServerAddress()); } catch (MongoException e) { exception = e;