Example usage for com.mongodb.client MongoCollection getNamespace

List of usage examples for com.mongodb.client MongoCollection getNamespace

Introduction

In this page you can find the example usage for com.mongodb.client MongoCollection getNamespace.

Prototype

MongoNamespace getNamespace();

Source Link

Document

Gets the namespace of this collection.

Usage

From source file:com.bluedragon.profiler.ProfileSession.java

License:Open Source License

@Override
public void execMongo(MongoCollection<Document> col, String action, Document qry, long execTime) {
    Map<String, Object> m = new HashMap<String, Object>();

    m.put("ms", execTime);
    m.put("action", action);
    m.put("col", col.getNamespace().getCollectionName());
    m.put("db", col.getNamespace().getDatabaseName());

    if (qry != null)
        m.put("qry", qry.toString());

    listMap.add(m);/*from w w  w  .j  av  a 2 s.  c  om*/
}

From source file:com.dilmus.dilshad.scabi.db.DTable.java

License:Open Source License

public DTable(DDB ddb, MongoCollection table) {
    m_ddb = ddb;/*from   w w  w  .  j a v a2s .co  m*/
    m_table = table;
    m_tableName = table.getNamespace().getCollectionName();
    m_firstTime = true;
    m_fieldNames = null;

    m_dcursor = new DResultSet();

}

From source file:com.epam.dlab.mongo.MongoDbConnection.java

License:Apache License

/**
 * Insert document to Mongo./* ww w  .  ja  v  a2 s  .c  om*/
 *
 * @param collection the name of collection.
 * @param document   the document.
 * @throws AdapterException
 */
public void insertOne(MongoCollection<Document> collection, Document document) throws AdapterException {
    try {
        collection.insertOne(document);
    } catch (Exception e) {
        throw new AdapterException("Cannot insert document into collection " + collection.getNamespace() + ": "
                + e.getLocalizedMessage(), e);
    }
}

From source file:com.epam.dlab.mongo.MongoDbConnection.java

License:Apache License

/**
 * Insert documents from list to Mongo collection and clear list.
 *
 * @param collection Mongo collection.//from   w w  w.j  a  v  a2s.  com
 * @param documents  the list of documents.
 * @throws AdapterException
 */
public void insertRows(MongoCollection<Document> collection, List<Document> documents) throws AdapterException {
    try {
        if (documents.size() > 0) {
            collection.insertMany(documents);
            LOGGER.debug("{} documents has been inserted into collection {}", documents.size(),
                    collection.getNamespace());
            documents.clear();
        }
    } catch (Exception e) {
        throw new AdapterException("Cannot insert new documents into collection " + collection.getNamespace()
                + ": " + e.getLocalizedMessage(), e);
    }
}

From source file:com.epam.dlab.mongo.MongoDbConnection.java

License:Apache License

/**
 * Delete the documents from Mongo collection.
 *
 * @param collection    Mongo collection.
 * @param usageDateList list of the data interval to deletion data from Mongo.
 * @throws AdapterException/*w  w w.  j  a v  a2  s .c o  m*/
 */
public void deleteRows(MongoCollection<Document> collection, UsageDataList usageDateList)
        throws AdapterException {
    try {
        long rowCount = 0;
        for (String date : usageDateList) {
            if (!usageDateList.get(date)) {
                DeleteResult result = collection.deleteMany(eq(ReportLine.FIELD_USAGE_DATE, date));
                rowCount += result.getDeletedCount();
                usageDateList.set(date, true);
            }
        }
        if (rowCount > 0) {
            LOGGER.debug("{} documents has been deleted from collection {}", rowCount,
                    collection.getNamespace());
        }
    } catch (Exception e) {
        throw new AdapterException("Cannot delete old rows from collection " + collection.getNamespace() + ": "
                + e.getLocalizedMessage(), e);
    }
}

From source file:com.imaginea.mongodb.services.impl.CollectionServiceImpl.java

License:Apache License

/**
 * Deletes a collection inside a database in mongo to which user is connected to.
 *
 * @param dbName Name of Database in which to insert a collection
 * @param collectionName Name of Collection to be inserted
 * @return Success if deletion is successful else throw exception
 * @throws DatabaseException throw super type of UndefinedDatabaseException
 * @throws ValidationException throw super type of
 *         EmptyDatabaseNameException,EmptyCollectionNameException
 * @throws CollectionException throw super type of
 *         UndefinedCollectionException,DeleteCollectionException
 */// w  w w.  j a va2  s  .c  o m

private void createCollection(CreateCollectionOptions options, MongoCollection<Document> selectedCollection,
        String selectedCollectionName, MongoDatabase db) {
    db.createCollection(selectedCollectionName + "_temp", options);
    MongoCollection<Document> tempCollection = db.getCollection(selectedCollectionName + "_temp");

    MongoCursor<Document> cur = selectedCollection.find().iterator();
    while (cur.hasNext()) {
        Document obj = cur.next();
        tempCollection.insertOne(obj);
    }
    MongoNamespace namespace = selectedCollection.getNamespace();
    selectedCollection.drop();
    tempCollection.renameCollection(namespace);
}

From source file:com.qbao.cat.plugin.db.nosql.NewMongoPluginTemplate.java

License:Apache License

@Override
protected Transaction beginLog(ProceedingJoinPoint pjp) {
    Transaction transaction = null;/*from   www . ja va 2 s  . c o m*/
    transaction = newTransaction("MongoDB", String.valueOf(pjp.getSignature().toShortString()));
    MongoCollection collector = (MongoCollection) pjp.getTarget();
    Cat.logEvent("DB.Collection", collector.getNamespace().getFullName());
    Cat.logEvent("Method", pjp.getSignature().toString());
    return transaction;
}

From source file:fr.lirmm.graphik.graal.keyval.KeyValueStoreMongoDB.java

License:Open Source License

public void showCollection(MongoCollection<Document> col) {
    System.out.println(col.getNamespace().getCollectionName() + " : ");
    MongoCursor<Document> cursor = col.find().iterator();
    try {/*from   w  w  w . ja  v a  2s.  c  o  m*/
        while (cursor.hasNext()) {
            System.out.println(cursor.next().toJson());
        }
    } finally {
        cursor.close();
    }
}

From source file:org.apache.eagle.alert.metadata.impl.MongoMetadataDaoImpl.java

License:Apache License

private <T> OpResult addOne(MongoCollection<Document> collection, T t) {
    OpResult result = new OpResult();
    String json = "";
    try {//from  w  ww  .  j  av  a2 s .com
        json = mapper.writeValueAsString(t);
        collection.insertOne(Document.parse(json));
        result.code = 200;
        result.message = String.format("add one document [%s] to collection [%s] succeed!", json,
                collection.getNamespace());
        LOG.info(result.message);
    } catch (Exception e) {
        result.code = 400;
        result.message = e.getMessage();
        LOG.error(String.format("Add one document [%s] to collection [%s] failed!", json,
                collection.getNamespace()), e);
    }
    return result;
}

From source file:org.apache.nifi.processors.mongodb.AbstractMongoQueryProcessor.java

License:Apache License

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();/*from   w w w  .j av a  2  s  .c om*/
        attributes.put(queryAttr, query.toJson());
    }

    attributes.put(DB_NAME, collection.getNamespace().getDatabaseName());
    attributes.put(COL_NAME, collection.getNamespace().getCollectionName());

    return attributes;
}