
com.mongodb.reactivestreams.client.MongoDatabaseImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mongodb-driver-reactivestreams Show documentation
Show all versions of mongodb-driver-reactivestreams Show documentation
A Reactive Streams implementation of the MongoDB Java driver
/*
* Copyright 2014 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mongodb.reactivestreams.client;
import com.mongodb.Block;
import com.mongodb.ReadConcern;
import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;
import com.mongodb.async.SingleResultCallback;
import com.mongodb.client.model.CreateCollectionOptions;
import org.bson.Document;
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.conversions.Bson;
import org.reactivestreams.Publisher;
import static com.mongodb.assertions.Assertions.notNull;
import static com.mongodb.async.client.Observables.observe;
import static com.mongodb.reactivestreams.client.PublisherHelper.voidToSuccessCallback;
class MongoDatabaseImpl implements MongoDatabase {
private final com.mongodb.async.client.MongoDatabase wrapped;
MongoDatabaseImpl(final com.mongodb.async.client.MongoDatabase wrapped) {
this.wrapped = notNull("wrapped", wrapped);
}
@Override
public String getName() {
return wrapped.getName();
}
@Override
public CodecRegistry getCodecRegistry() {
return wrapped.getCodecRegistry();
}
@Override
public ReadPreference getReadPreference() {
return wrapped.getReadPreference();
}
@Override
public WriteConcern getWriteConcern() {
return wrapped.getWriteConcern();
}
@Override
public ReadConcern getReadConcern() {
return wrapped.getReadConcern();
}
@Override
public MongoDatabase withCodecRegistry(final CodecRegistry codecRegistry) {
return new MongoDatabaseImpl(wrapped.withCodecRegistry(codecRegistry));
}
@Override
public MongoDatabase withReadPreference(final ReadPreference readPreference) {
return new MongoDatabaseImpl(wrapped.withReadPreference(readPreference));
}
@Override
public MongoDatabase withWriteConcern(final WriteConcern writeConcern) {
return new MongoDatabaseImpl(wrapped.withWriteConcern(writeConcern));
}
@Override
public MongoDatabase withReadConcern(final ReadConcern readConcern) {
return new MongoDatabaseImpl(wrapped.withReadConcern(readConcern));
}
@Override
public MongoCollection getCollection(final String collectionName) {
return getCollection(collectionName, Document.class);
}
@Override
public MongoCollection getCollection(final String collectionName, final Class clazz) {
return new MongoCollectionImpl(wrapped.getCollection(collectionName, clazz));
}
@Override
public Publisher runCommand(final Bson command) {
return runCommand(command, Document.class);
}
@Override
public Publisher runCommand(final Bson command, final ReadPreference readPreference) {
return runCommand(command, readPreference, Document.class);
}
@Override
public Publisher runCommand(final Bson command, final Class clazz) {
return new ObservableToPublisher(observe(new Block>() {
@Override
public void apply(final SingleResultCallback callback) {
wrapped.runCommand(command, clazz, callback);
}
}));
}
@Override
public Publisher runCommand(final Bson command, final ReadPreference readPreference,
final Class clazz) {
return new ObservableToPublisher(observe(new Block>() {
@Override
public void apply(final SingleResultCallback callback) {
wrapped.runCommand(command, readPreference, clazz, callback);
}
}));
}
@Override
public Publisher drop() {
return new ObservableToPublisher(observe(new Block>() {
@Override
public void apply(final SingleResultCallback callback) {
wrapped.drop(voidToSuccessCallback(callback));
}
}));
}
@Override
public Publisher listCollectionNames() {
return new ObservableToPublisher(observe(wrapped.listCollectionNames()));
}
@Override
public ListCollectionsPublisher listCollections() {
return listCollections(Document.class);
}
@Override
public ListCollectionsPublisher listCollections(final Class clazz) {
return new ListCollectionsPublisherImpl(wrapped.listCollections(clazz));
}
@Override
public Publisher createCollection(final String collectionName) {
return createCollection(collectionName, new CreateCollectionOptions());
}
@Override
public Publisher createCollection(final String collectionName, final CreateCollectionOptions options) {
return new ObservableToPublisher(observe(new Block>() {
@Override
public void apply(final SingleResultCallback callback) {
wrapped.createCollection(collectionName, options, voidToSuccessCallback(callback));
}
}));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy