/** * Get the database name the event was originated at. * * @return can be {@literal null}. */ @Nullable public String getDatabaseName() { return raw != null ? raw.getNamespace().getDatabaseName() : null; }
@Override public BsonDocument call(final Connection connection) { validateCollation(connection, collation); return executeWrappedCommandProtocol(binding, namespace.getDatabaseName(), getCommand(), connection); } });
@Override public BatchCursor<T> call(final ConnectionSource connectionSource, final Connection connection) { validateCollation(connection, collation); return executeWrappedCommandProtocol(binding, namespace.getDatabaseName(), getCommand(), CommandResultDocumentCodec.create(decoder, "retval"), connection, transformer(connectionSource, connection)); } });
protected Map<String, String> getAttributes(ProcessContext context, FlowFile input, Document query, MongoCollection collection) { final Map<String, String> attributes = new HashMap<>(); attributes.put(CoreAttributes.MIME_TYPE.key(), "application/json"); if (context.getProperty(QUERY_ATTRIBUTE).isSet()) { final String queryAttr = context.getProperty(QUERY_ATTRIBUTE).evaluateAttributeExpressions(input).getValue(); attributes.put(queryAttr, query.toJson()); } attributes.put(DB_NAME, collection.getNamespace().getDatabaseName()); attributes.put(COL_NAME, collection.getNamespace().getCollectionName()); return attributes; } }
@Override public Void call(final Connection connection) { try { executeWrappedCommandProtocol(binding, namespace.getDatabaseName(), getCommand(connection.getDescription()), connection, writeConcernErrorTransformer()); } catch (MongoCommandException e) { rethrowIfNotNamespaceError(e); } return null; } });
@Override public Void call(final Connection connection) { try { executeWrappedCommandProtocol(binding, namespace.getDatabaseName(), getCommand(connection.getDescription()), connection, writeConcernErrorTransformer()); } catch (MongoCommandException e) { CommandOperationHelper.rethrowIfNotNamespaceError(e); } return null; } });
@Override public Long call(final Connection connection) { validateReadConcernAndCollation(connection, binding.getSessionContext().getReadConcern(), collation); return executeWrappedCommandProtocol(binding, namespace.getDatabaseName(), getCommand(binding.getSessionContext()), DECODER, connection, transformer()); } });
private CommandReadOperation<BsonDocument> createExplainableOperation(final ExplainVerbosity explainVerbosity) { return new CommandReadOperation<BsonDocument>(namespace.getDatabaseName(), asExplainCommand(getCommand(NoOpSessionContext.INSTANCE), explainVerbosity), new BsonDocumentCodec()); }
private CommandReadOperation<BsonDocument> createExplainableOperation(final ExplainVerbosity explainVerbosity) { return new CommandReadOperation<BsonDocument>(namespace.getDatabaseName(), asExplainCommand(getCommand(NoOpSessionContext.INSTANCE), explainVerbosity), new BsonDocumentCodec()); }
@Override public BatchCursor<T> call(final ConnectionSource source, final Connection connection) { validateReadConcernAndCollation(connection, binding.getSessionContext().getReadConcern(), collation); return executeWrappedCommandProtocol(binding, namespace.getDatabaseName(), getCommand(binding.getSessionContext()), createCommandDecoder(), connection, transformer(source, connection)); } });
private CommandReadOperation<BsonDocument> createExplainableOperation(final ExplainVerbosity explainVerbosity) { return new CommandReadOperation<BsonDocument>(namespace.getDatabaseName(), ExplainHelper.asExplainCommand(getCommand(null), explainVerbosity), new BsonDocumentCodec()); }
@Override public MapReduceBatchCursor<T> call(final ConnectionSource source, final Connection connection) { validateReadConcernAndCollation(connection, binding.getSessionContext().getReadConcern(), collation); return executeWrappedCommandProtocol(binding, namespace.getDatabaseName(), getCommand(binding.getSessionContext()), CommandResultDocumentCodec.create(decoder, "results"), connection, transformer(source, connection)); } });
@Override public List<BatchCursor<T>> call(final ConnectionSource source, final Connection connection) { validateReadConcern(connection, binding.getSessionContext().getReadConcern()); return executeWrappedCommandProtocol(binding, namespace.getDatabaseName(), getCommand(binding.getSessionContext()), CommandResultDocumentCodec.create(decoder, "firstBatch"), connection, transformer(source)); } });
private static BsonDocument namespaceToDocument(final MongoNamespace namespace) { Assertions.notNull("namespace", namespace); return new BsonDocument("db", new BsonString(namespace.getDatabaseName())) .append("coll", new BsonString(namespace.getCollectionName())); }
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()); }
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; } }
@Override public BatchCursor<T> call(final ConnectionSource source, final Connection connection) { validateReadConcernAndCollation(connection, binding.getSessionContext().getReadConcern(), collation); return executeWrappedCommandProtocol(binding, namespace.getDatabaseName(), getCommand(connection.getDescription(), binding.getSessionContext()), CommandResultDocumentCodec.create(decoder, FIELD_NAMES_WITH_RESULT), connection, transformer(source, connection)); } });
private void executeCommandAsync(final AsyncWriteBinding binding, final AsyncConnection connection, final BulkWriteBatch batch, final ConnectionReleasingWrappedCallback<BulkWriteResult> callback, final SingleResultCallback<BsonDocument> commandCallback) { try { connection.commandAsync(namespace.getDatabaseName(), batch.getCommand(), NO_OP_FIELD_NAME_VALIDATOR, null, batch.getDecoder(), binding.getSessionContext(), shouldAcknowledge(batch, writeConcern), batch.getPayload(), batch.getFieldNameValidator(), commandCallback); } catch (Throwable t) { callback.onResult(null, t); } }
private void getMore(final AsyncConnection connection, final ServerCursor cursor, final SingleResultCallback<List<T>> callback, final boolean tryNext) { if (serverIsAtLeastVersionThreeDotTwo(connection.getDescription())) { connection.commandAsync(namespace.getDatabaseName(), asGetMoreCommandDocument(cursor.getId()), NO_OP_FIELD_NAME_VALIDATOR, ReadPreference.primary(), CommandResultDocumentCodec.create(decoder, "nextBatch"), connectionSource.getSessionContext(), new CommandResultSingleResultCallback(connection, cursor, callback, tryNext)); } else { connection.getMoreAsync(namespace, cursor.getId(), getNumberToReturn(limit, batchSize, count.get()), decoder, new QueryResultSingleResultCallback(connection, callback, tryNext)); } }
@Override protected Message<ChangeStreamDocument<Document>, Object> createMessage(ChangeStreamDocument<Document> source, Class<Object> targetType, RequestOptions options) { MongoNamespace namespace = source.getNamespace() != null ? source.getNamespace() : createNamespaceFromOptions(options); return new ChangeStreamEventMessage<>(new ChangeStreamEvent<>(source, targetType, mongoConverter), MessageProperties .builder().databaseName(namespace.getDatabaseName()).collectionName(namespace.getCollectionName()).build()); }