List of usage examples for com.mongodb.client MongoDatabase getName
String getName();
From source file:com.bluedragon.mongo.MongoCollectionRename.java
License:Open Source License
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 {/* ww w .j av a2 s .c o m*/ 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; } }
From source file:com.dilmus.dilshad.scabi.ms.MetaServer.java
License:Open Source License
private static int createDatabasesIfAbsent(String dbHost, String dbPort) throws DScabiException { MongoClient mongo = new MongoClient(dbHost, Integer.parseInt(dbPort)); MongoDatabase mongodb = mongo.getDatabase("MetaDB"); MongoDatabase mongodb2 = mongo.getDatabase("AppTableDB"); MongoDatabase mongodb3 = mongo.getDatabase("JavaFileDB"); MongoDatabase mongodb4 = mongo.getDatabase("FileDB"); log.debug("mongodb.getName() : {}", mongodb.getName()); log.debug("mongodb2.getName() : {}", mongodb2.getName()); log.debug("mongodb3.getName() : {}", mongodb3.getName()); log.debug("mongodb4.getName() : {}", mongodb4.getName()); mongo.close();// w w w . j a v a2 s . co m return 0; }
From source file:net.netzgut.integral.mongo.internal.services.MongoServiceImplementation.java
License:Apache License
@Override public void setupCollection(MongoDatabase db, Class<? extends Serializable> entityClass, String collectionName) {/*from w w w . j ava 2 s. co m*/ if (db == null) { log.error("Database can't be null"); throw new IllegalArgumentException("Database can't be null"); } if (entityClass == null) { log.error("Entity Class can't be null"); throw new IllegalArgumentException("Entity Class can't be null"); } if (collectionName == null || collectionName.length() == 0) { log.error("Collection name can't be blank"); throw new IllegalArgumentException("Collection name can't be blank"); } log.debug("setupCollection(DB: {}, Entity: {}, Collection: {}", db.getName(), entityClass.getName(), collectionName); setupIndexes(entityClass, getCollection(db, entityClass)); }
From source file:net.netzgut.integral.mongo.internal.services.MongoServiceImplementation.java
License:Apache License
@SuppressWarnings("unchecked") @Override/*from www . j a v a2s . c o m*/ public void autoSetup(MongoDatabase db, String... packageRestrictions) { log.debug("autoSetup(DB: {}, Package restrictions: {}", db.getName(), packageRestrictions); new FastClasspathScanner(packageRestrictions).matchClassesWithAnnotation(Collection.class, matchingClass -> { Collection annotation = matchingClass.getAnnotation(Collection.class); if (annotation.autoSetup()) { setupCollection(db, (Class<? extends Serializable>) matchingClass, annotation.value()); } }); }
From source file:org.codinjutsu.tools.nosql.mongo.logic.SingleMongoClient.java
License:Apache License
private SingleMongoDatabase createMongoDatabaseAndItsCollections(MongoDatabase database) { SingleMongoDatabase singleMongoDatabase = new SingleMongoDatabase(database.getName()); MongoIterable<String> collectionNames = database.listCollectionNames(); for (String collectionName : collectionNames) { singleMongoDatabase.addCollection(new SingleMongoCollection(collectionName, database.getName())); }/*from w ww . ja v a 2 s. c o m*/ return singleMongoDatabase; }
From source file:org.ff4j.mongo.store.FeatureStoreMongo.java
License:Apache License
/** * Parameterized constructor with collection. * /* ww w. j a v a 2s . c o m*/ * @param collection * the collection to set */ public FeatureStoreMongo(MongoDatabase db, String collectionName) { this.dbName = db.getName(); this.featuresCollection = db.getCollection(collectionName); }
From source file:org.ff4j.mongo.store.PropertyStoreMongo.java
License:Apache License
/** * Parameterized constructor with collection. * //from w w w .ja v a2 s .c om * @param collection * the collection to set */ public PropertyStoreMongo(MongoDatabase db, String collectionName) { this.propertiesCollection = db.getCollection(collectionName); this.dbName = db.getName(); }
From source file:org.flywaydb.core.internal.dbsupport.mongo.MongoDatabaseUtil.java
License:Apache License
/** * Checks whether a Mongo database is empty. * * @param mongoDb a MongoDatabase object * @return {@code true} if it is, {@code false} if isn't. Returns {@code false} if the database does not exist. * @throws FlywayException when the check fails. *//*w w w . java2s . c o m*/ public static boolean empty(MongoDatabase mongoDb) throws FlywayException { try { MongoIterable<String> collectionIterable = mongoDb.listCollectionNames(); return !collectionIterable.iterator().hasNext(); } catch (MongoException e) { throw new FlywayException("Unable to check whether Mongo database " + mongoDb.getName() + " is empty", e); } }