@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(); } }
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(); }); }
@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(); }
@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); } }
@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()}; }
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; } }
@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; }
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; }
@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); }
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()); }
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; } } }
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); }
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)); }
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()); }
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; } } }
@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)); } })); }
@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)); } })); }
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()); }
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; } } }
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); } }
@Override public MongoNamespace getNamespace() { return collection.getNamespace(); }
@Override public void renameCollection(MongoNamespace arg0) { collection.renameCollection(arg0); }
@Override public void renameCollection(MongoNamespace arg0, RenameCollectionOptions arg1) { collection.renameCollection(arg0, arg1); }
public DBDataImpl(MongoNamespace namespace, Document bson) { setup(namespace, bson); }
@Before @SuppressWarnings("unchecked") public void setUp() { collection = Mockito.mock(MongoCollection.class); Mockito.when(collection.getNamespace()).thenReturn(new MongoNamespace("db", "collection")); }
@Override public MongoNamespace getNamespace() { return wrapped.getNamespace(); }
@Override public Observable<Success> renameCollection(final MongoNamespace newCollectionNamespace) { return renameCollection(newCollectionNamespace, new RenameCollectionOptions()); }
public void renameCollection(String target, boolean dropTarget) { getCollection().renameCollection(new MongoNamespace(mongoDatabase.getName(), target), new RenameCollectionOptions().dropTarget(dropTarget)); }
@Override public Publisher<Success> renameCollection(final MongoNamespace newCollectionNamespace) { return renameCollection(newCollectionNamespace, new RenameCollectionOptions()); }
@Override public Publisher<Success> renameCollection(final ClientSession clientSession, final MongoNamespace newCollectionNamespace) { return renameCollection(clientSession, newCollectionNamespace, new RenameCollectionOptions()); }
public static void renameCollection(String oldName, String newName) throws UnknownHostException { reconnect(); MongoNamespace ns = new MongoNamespace(Database.getName() + "." + newName); Database.getCollection(oldName).renameCollection(ns); }
/** * Gets the namespace of this collection. * * @return the namespace */ MongoNamespace getNamespace();
/** * 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);
/** * 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);
/** * 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);
/** * 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);
/** * 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);