Java 类com.mongodb.MongoNamespace 实例源码

项目:mongo-java-driver-rx    文件:GridFSTest.java   
@Before
@Override
public void setUp() throws Throwable {
    super.setUp();
    gridFSBucket = GridFSBuckets.create(database);
    filesCollection = initializeCollection(new MongoNamespace(getDefaultDatabaseName(), "fs.files"))
            .withDocumentClass(BsonDocument.class);
    chunksCollection = initializeCollection(new MongoNamespace(getDefaultDatabaseName(), "fs.chunks"))
            .withDocumentClass(BsonDocument.class);

    List<BsonDocument> filesDocuments = processFiles(data.getArray("files", new BsonArray()), new ArrayList<BsonDocument>());
    if (!filesDocuments.isEmpty()) {
        filesCollection.insertMany(filesDocuments).timeout(30, SECONDS).first().toBlocking().first();
    }

    List<BsonDocument> chunksDocuments = processChunks(data.getArray("chunks", new BsonArray()), new ArrayList<BsonDocument>());
    if (!chunksDocuments.isEmpty()) {
        chunksCollection.insertMany(chunksDocuments).timeout(30, SECONDS).first().toBlocking().first();
    }
}
项目:mongofx    文件:DBTreeController.java   
private void onReanameCollection(ActionEvent actionEvent) {
  TreeItem<DbTreeValue> selectedItem = treeView.getSelectionModel().getSelectedItem();
  if (selectedItem == null) {
    return;
  }

  DbTreeValue value = selectedItem.getValue();
  TextInputDialog dialog = new TextInputDialog(value.getDisplayValue());
  dialog.setContentText("New collection name:");
  dialog.setHeaderText("Rename collection");
  dialog.showAndWait().ifPresent(targetCollection -> {
    MongoCollection<Document> collection = value.getMongoDatabase().getMongoDb().getCollection(value.getDisplayValue());
    collection.renameCollection(new MongoNamespace(value.getMongoDatabase().getName(), targetCollection));
    ((DynamicTreeItem)selectedItem.getParent()).reload();
  });
}
项目:mongofx    文件:FindResultIterable.java   
@JsIgnore
@Override
public MongoCursor<Document> iterator(int skip, int limit) {
  MongoCollection<Document> collection = getCollection();

  findOptions.skip(skip);
  findOptions.limit(limit);
  if (projection != null) {
    findOptions.projection(projection);
  }
  if (sort != null) {
    findOptions.sort(dbObjectFromMap(sort));
  }
  return new FindIterable(new MongoNamespace(mongoDatabase.getName(), collectionName), collection.getCodecRegistry(), //
      collection.getReadPreference(), getExecutor(), findQuery, findOptions).iterator();
}
项目:mongo-java-driver-reactivestreams    文件:GridFSTest.java   
@Before
@Override
public void setUp() throws Throwable {
    super.setUp();
    gridFSBucket = GridFSBuckets.create(database);
    filesCollection = initializeCollection(new MongoNamespace(getDefaultDatabaseName(), "fs.files"))
            .withDocumentClass(BsonDocument.class);
    chunksCollection = initializeCollection(new MongoNamespace(getDefaultDatabaseName(), "fs.chunks"))
            .withDocumentClass(BsonDocument.class);

    List<BsonDocument> filesDocuments = processFiles(data.getArray("files", new BsonArray()), new ArrayList<BsonDocument>());
    if (!filesDocuments.isEmpty()) {
        ObservableSubscriber<Success> filesInsertSubscriber = new ObservableSubscriber<Success>();
        filesCollection.insertMany(filesDocuments).subscribe(filesInsertSubscriber);
        filesInsertSubscriber.await(30, SECONDS);
    }

    List<BsonDocument> chunksDocuments = processChunks(data.getArray("chunks", new BsonArray()), new ArrayList<BsonDocument>());
    if (!chunksDocuments.isEmpty()) {
        ObservableSubscriber<Success> chunksInsertSubscriber = new ObservableSubscriber<Success>();
        chunksCollection.insertMany(chunksDocuments).subscribe(chunksInsertSubscriber);
        chunksInsertSubscriber.await(30, SECONDS);
    }
}
项目:incubator-skywalking    文件:MongoDBMethodInterceptorTest.java   
@SuppressWarnings({"rawtypes", "unchecked"})
@Before
public void setUp() throws Exception {

    interceptor = new MongoDBMethodInterceptor();

    Config.Plugin.MongoDB.TRACE_PARAM = true;

    when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:27017");

    BsonDocument document = new BsonDocument();
    document.append("name", new BsonString("by"));
    MongoNamespace mongoNamespace = new MongoNamespace("test.user");
    Decoder decoder = PowerMockito.mock(Decoder.class);
    FindOperation findOperation = new FindOperation(mongoNamespace, decoder);
    findOperation.filter(document);

    arguments = new Object[] {findOperation};
    argumentTypes = new Class[] {findOperation.getClass()};
}
项目:openbd-core    文件:MongoCollectionRename.java   
public cfData execute(cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException {
    MongoDatabase   db  = getMongoDatabase( _session, argStruct );

    String collection   = getNamedStringParam(argStruct, "collection", null);
    if ( collection == null )
        throwException(_session, "please specify a collection");

    String name = getNamedStringParam(argStruct, "name", null);
    if ( name == null )
        throwException(_session, "please specify a name");

    try{

        db
            .getCollection( collection )
            .renameCollection( new MongoNamespace( db.getName(), name ), new RenameCollectionOptions().dropTarget( getNamedBooleanParam(argStruct, "droptarget", false ) ) );

        return cfBooleanData.TRUE;

    } catch (MongoException me){
        throwException(_session, me.getMessage());
        return null;
    }
}
项目:mogodb-dao    文件:MongoDaoImpl.java   
@Override
public Boolean renameCollection(String newCollection,String oldCollection) {
    // old collection name
    String collectionNameForT = null;

    if (oldCollection == null) {
        collectionNameForT = getCollectionName(this.collectionNames.get());
    }
    else {
        collectionNameForT = getCollectionName(oldCollection);
    }

    // collection
    MongoCollection<Document> collection = database.getCollection(collectionNameForT);

    // database name
    String databaseName = database.getName();
    // MongoDB namespace
    MongoNamespace mongoNamespace = new MongoNamespace(databaseName+"."+newCollection);

    if (collection == null) {
        collection.renameCollection(mongoNamespace);
    }
    else {
        gc(); // clear
        return false;
    }

    gc(); // clear

    return true;
}
项目:SimpleAPI    文件:DBDataImpl.java   
private void setup(MongoNamespace namespace, Document bson) {
    this.namespace = namespace;
    if (bson == null) {
        this.bson = new DBDataDocument(new Document("_id", id.toString()));
        SimpleAPIImpl.getDatabaseManager().withCollectionConsumer(namespace.getDatabaseName(), namespace.getCollectionName(), c -> c.insertOne(new Document(this.bson)));
    } else
        this.bson = new DBDataDocument(bson);
    id = this.bson.getString("_id");
    loaded = true;
}
项目:mongo-java-driver-rx    文件:MongoCollectionImpl.java   
@Override
public Observable<Success> renameCollection(final MongoNamespace newCollectionNamespace, final RenameCollectionOptions options) {
    return RxObservables.create(Observables.observe(new Block<SingleResultCallback<Success>>() {
        @Override
        public void apply(final SingleResultCallback<Success> callback) {
            wrapped.renameCollection(newCollectionNamespace, options, voidToSuccessCallback(callback));
        }
    }), observableAdapter);
}
项目:mongo-java-driver-rx    文件:Fixture.java   
public static MongoCollection<Document> initializeCollection(final MongoNamespace namespace) throws Throwable {
    MongoDatabase database = getMongoClient().getDatabase(namespace.getDatabaseName());
    try {
        database.runCommand(new Document("drop", namespace.getCollectionName())).timeout(10, SECONDS).toBlocking().first();
    } catch (MongoCommandException e) {
        if (!e.getErrorMessage().startsWith("ns not found")) {
            throw e;
        }
    }
    return database.getCollection(namespace.getCollectionName());
}
项目:mongo-java-driver-rx    文件:Fixture.java   
public static void drop(final MongoNamespace namespace) throws Throwable {
    try {
        getMongoClient().getDatabase(namespace.getDatabaseName())
                .runCommand(new Document("drop", namespace.getCollectionName())).timeout(10, SECONDS).toBlocking().first();
    } catch (MongoCommandException e) {
        if (!e.getErrorMessage().contains("ns not found")) {
            throw e;
        }
    }
}
项目:mongofx    文件:FindIterable.java   
public FindIterable(final MongoNamespace namespace,
    final CodecRegistry codecRegistry,
    final ReadPreference readPreference, final OperationExecutor executor,
    final Bson filter, final FindOptions findOptions) {
  this.namespace = notNull("namespace", namespace);
  this.codecRegistry = notNull("codecRegistry", codecRegistry);
  this.readPreference = notNull("readPreference", readPreference);
  this.executor = notNull("executor", executor);
  this.filter = notNull("filter", filter);
  this.findOptions = notNull("findOptions", findOptions);
}
项目:mongofx    文件:FindResultIterable.java   
public ObjectListPresentation explain() {
  MongoCollection<Document> collection = getCollection();

  FindIterable findIterable = new FindIterable(new MongoNamespace(mongoDatabase.getName(), collectionName), collection.getCodecRegistry(), //
      collection.getReadPreference(), getExecutor(), findQuery, findOptions);

  BsonDocument res = findIterable.explainIterator(ExplainVerbosity.QUERY_PLANNER);
  return JsApiUtils.singletonIter(JsApiUtils.convertBsonToDocument(res));
}
项目:mongo-java-driver-reactivestreams    文件:Fixture.java   
public static MongoCollection<Document> initializeCollection(final MongoNamespace namespace) throws Throwable {
    MongoDatabase database = getMongoClient().getDatabase(namespace.getDatabaseName());
    try {
        RxReactiveStreams.toObservable(database.runCommand(new Document("drop", namespace.getCollectionName())))
                .timeout(10, SECONDS).toBlocking().toIterable();
    } catch (MongoCommandException e) {
        if (!e.getErrorMessage().startsWith("ns not found")) {
            throw e;
        }
    }
    return database.getCollection(namespace.getCollectionName());
}
项目:mongo-java-driver-reactivestreams    文件:Fixture.java   
public static void drop(final MongoNamespace namespace) throws Throwable {
    try {
        RxReactiveStreams.toObservable(getMongoClient().getDatabase(namespace.getDatabaseName())
                .runCommand(new Document("drop", namespace.getCollectionName()))).timeout(10, SECONDS).toBlocking().toIterable();
    } catch (MongoCommandException e) {
        if (!e.getErrorMessage().contains("ns not found")) {
            throw e;
        }
    }
}
项目:mongo-java-driver-reactivestreams    文件:MongoCollectionImpl.java   
@Override
public Publisher<Success> renameCollection(final MongoNamespace newCollectionNamespace, final RenameCollectionOptions options) {
    return new ObservableToPublisher<Success>(observe(new Block<SingleResultCallback<Success>>() {
        @Override
        public void apply(final SingleResultCallback<Success> callback) {
            wrapped.renameCollection(newCollectionNamespace, options, voidToSuccessCallback(callback));
        }
    }));
}
项目:mongo-java-driver-reactivestreams    文件:MongoCollectionImpl.java   
@Override
public Publisher<Success> renameCollection(final ClientSession clientSession, final MongoNamespace newCollectionNamespace,
                                           final RenameCollectionOptions options) {
    return new ObservableToPublisher<Success>(observe(new Block<SingleResultCallback<Success>>() {
        @Override
        public void apply(final SingleResultCallback<Success> callback) {
            wrapped.renameCollection(clientSession, newCollectionNamespace, options, voidToSuccessCallback(callback));
        }
    }));
}
项目:mongo-java-driver-reactivestreams    文件:Fixture.java   
public static MongoCollection<Document> initializeCollection(final MongoNamespace namespace) throws Throwable {
    MongoDatabase database = getMongoClient().getDatabase(namespace.getDatabaseName());
    try {
        ObservableSubscriber<Document> subscriber = new ObservableSubscriber<Document>();
        database.runCommand(new Document("drop", namespace.getCollectionName())).subscribe(subscriber);
        subscriber.await(10, SECONDS);
    } catch (MongoCommandException e) {
        if (!e.getErrorMessage().startsWith("ns not found")) {
            throw e;
        }
    }
    return database.getCollection(namespace.getCollectionName());
}
项目:mongo-java-driver-reactivestreams    文件:Fixture.java   
public static void drop(final MongoNamespace namespace) throws Throwable {
    try {
        ObservableSubscriber<Document> subscriber = new ObservableSubscriber<Document>();
        getMongoClient().getDatabase(namespace.getDatabaseName())
                .runCommand(new Document("drop", namespace.getCollectionName()))
                .subscribe(subscriber);
        subscriber.await(20, SECONDS);
    } catch (MongoCommandException e) {
        if (!e.getErrorMessage().contains("ns not found")) {
            throw e;
        }
    }
}
项目:render    文件:RenderDao.java   
private void renameCollection(final String fromCollectionName,
                              final String toCollectionName) {

    if (MongoUtil.exists(renderDatabase, fromCollectionName)) {

        final MongoCollection<Document> fromCollection = renderDatabase.getCollection(fromCollectionName);
        final MongoNamespace toNamespace = new MongoNamespace(renderDatabase.getName(), toCollectionName);
        fromCollection.renameCollection(toNamespace);

        LOG.debug("renameCollection: exit, ran {}.renameCollection({})",
                  MongoUtil.fullName(fromCollection),
                  toCollectionName);
    }

}
项目:ibm-performance-monitor    文件:ProfiledMongoCollection.java   
@Override
public MongoNamespace getNamespace()
{
    return collection.getNamespace();
}
项目:ibm-performance-monitor    文件:ProfiledMongoCollection.java   
@Override
public void renameCollection(MongoNamespace arg0)
{
    collection.renameCollection(arg0);
}
项目:ibm-performance-monitor    文件:ProfiledMongoCollection.java   
@Override
public void renameCollection(MongoNamespace arg0, RenameCollectionOptions arg1)
{
    collection.renameCollection(arg0, arg1);
}
项目:SimpleAPI    文件:DBDataImpl.java   
public DBDataImpl(MongoNamespace namespace, Document bson) {
    setup(namespace, bson);
}
项目:incubator-rya    文件:AggregationPipelineQueryNodeTest.java   
@Before
@SuppressWarnings("unchecked")
public void setUp() {
    collection = Mockito.mock(MongoCollection.class);
    Mockito.when(collection.getNamespace()).thenReturn(new MongoNamespace("db", "collection"));
}
项目:incubator-rya    文件:SparqlToPipelineTransformVisitorTest.java   
@Before
@SuppressWarnings("unchecked")
public void setUp() {
    collection = Mockito.mock(MongoCollection.class);
    Mockito.when(collection.getNamespace()).thenReturn(new MongoNamespace("db", "collection"));
}
项目:mongo-java-driver-rx    文件:MongoCollectionImpl.java   
@Override
public MongoNamespace getNamespace() {
    return wrapped.getNamespace();
}
项目:mongo-java-driver-rx    文件:MongoCollectionImpl.java   
@Override
public Observable<Success> renameCollection(final MongoNamespace newCollectionNamespace) {
    return renameCollection(newCollectionNamespace, new RenameCollectionOptions());
}
项目:mongofx    文件:Collection.java   
public void renameCollection(String target, boolean dropTarget) {
  getCollection().renameCollection(new MongoNamespace(mongoDatabase.getName(), target), new RenameCollectionOptions().dropTarget(dropTarget));
}
项目:mongo-java-driver-reactivestreams    文件:MongoCollectionImpl.java   
@Override
public MongoNamespace getNamespace() {
    return wrapped.getNamespace();
}
项目:mongo-java-driver-reactivestreams    文件:MongoCollectionImpl.java   
@Override
public Publisher<Success> renameCollection(final MongoNamespace newCollectionNamespace) {
    return renameCollection(newCollectionNamespace, new RenameCollectionOptions());
}
项目:mongo-java-driver-reactivestreams    文件:MongoCollectionImpl.java   
@Override
public Publisher<Success> renameCollection(final ClientSession clientSession, final MongoNamespace newCollectionNamespace) {
    return renameCollection(clientSession, newCollectionNamespace, new RenameCollectionOptions());
}
项目:MongoExplorer    文件:MongoHelper.java   
public static void renameCollection(String oldName, String newName) throws UnknownHostException {
    reconnect();
    MongoNamespace ns = new MongoNamespace(Database.getName() + "." + newName);
    Database.getCollection(oldName).renameCollection(ns);
}
项目:mongo-java-driver-rx    文件:MongoCollection.java   
/**
 * Gets the namespace of this collection.
 *
 * @return the namespace
 */
MongoNamespace getNamespace();
项目:mongo-java-driver-rx    文件:MongoCollection.java   
/**
 * Rename the collection with oldCollectionName to the newCollectionName.
 *
 * @param newCollectionNamespace the namespace the collection will be renamed to
 * @return an Observable with a single element indicating when the operation has completed
 * @mongodb.driver.manual reference/commands/renameCollection Rename collection
 */
Observable<Success> renameCollection(MongoNamespace newCollectionNamespace);
项目:mongo-java-driver-rx    文件:MongoCollection.java   
/**
 * Rename the collection with oldCollectionName to the newCollectionName.
 *
 * @param newCollectionNamespace the name the collection will be renamed to
 * @param options                the options for renaming a collection
 * @return an Observable with a single element indicating when the operation has completed
 * @mongodb.driver.manual reference/commands/renameCollection Rename collection
 */
Observable<Success> renameCollection(MongoNamespace newCollectionNamespace, RenameCollectionOptions options);
项目:mongo-java-driver-reactivestreams    文件:MongoCollection.java   
/**
 * Gets the namespace of this collection.
 *
 * @return the namespace
 */
MongoNamespace getNamespace();
项目:mongo-java-driver-reactivestreams    文件:MongoCollection.java   
/**
 * Rename the collection with oldCollectionName to the newCollectionName.
 *
 * @param newCollectionNamespace the namespace the collection will be renamed to
 * @return a publisher with a single element indicating when the operation has completed
 * @mongodb.driver.manual reference/commands/renameCollection Rename collection
 */
Publisher<Success> renameCollection(MongoNamespace newCollectionNamespace);
项目:mongo-java-driver-reactivestreams    文件:MongoCollection.java   
/**
 * Rename the collection with oldCollectionName to the newCollectionName.
 *
 * @param newCollectionNamespace the name the collection will be renamed to
 * @param options                the options for renaming a collection
 * @return a publisher with a single element indicating when the operation has completed
 * @mongodb.driver.manual reference/commands/renameCollection Rename collection
 */
Publisher<Success> renameCollection(MongoNamespace newCollectionNamespace, RenameCollectionOptions options);
项目:mongo-java-driver-reactivestreams    文件:MongoCollection.java   
/**
 * Rename the collection with oldCollectionName to the newCollectionName.
 *
 * @param clientSession the client session with which to associate this operation
 * @param newCollectionNamespace the namespace the collection will be renamed to
 * @return a publisher with a single element indicating when the operation has completed
 * @mongodb.driver.manual reference/commands/renameCollection Rename collection
 * @mongodb.server.release 3.6
 * @since 1.7
 */
Publisher<Success> renameCollection(ClientSession clientSession, MongoNamespace newCollectionNamespace);