Example usage for com.mongodb DBCollection getWriteConcern

List of usage examples for com.mongodb DBCollection getWriteConcern

Introduction

In this page you can find the example usage for com.mongodb DBCollection getWriteConcern.

Prototype

public WriteConcern getWriteConcern() 

Source Link

Document

Get the WriteConcern for this collection.

Usage

From source file:com.ebay.cloud.cms.dal.persistence.MongoExecutor.java

License:Apache License

private static void logMongoAction(PersistenceContext context, String operName, long start,
        DBCollection dbCollection, DBObject queryObject, DBObject bodyObject, SearchOption option,
        Integer queryResultSize, String statusMsg) {
    long end = System.currentTimeMillis();
    long cost = end - start; //mili seconds

    //recording the time cost in mongo DB
    context.addDBTimeCost(cost);/*  www . j  a v a2 s .co  m*/

    if (logger.isDebugEnabled()) {

        String costStr = Long.toString(cost);
        String queryObjectStr = "{}";
        if (queryObject != null) {
            queryObjectStr = queryObject.toString();
        }
        String bodyObjectStr = "{}";
        if (bodyObject != null) {
            bodyObjectStr = bodyObject.toString();
        }
        String sortObjectStr = "{}";
        if (option != null && option.hasSort()) {
            sortObjectStr = option.getSort().toString();
        }
        StringBuilder optionBuilder = new StringBuilder("{");
        if (option != null && (option.hasSkip() || option.hasLimit())) {
            optionBuilder.append("\"skip\" : ");
            optionBuilder.append(option.getSkip());
            optionBuilder.append(", \"limit\" : ");
            optionBuilder.append(option.getLimit());
        }
        optionBuilder.append("}");

        StringBuilder readPref = new StringBuilder("{");
        StringBuilder writeCon = new StringBuilder("{");
        String dbName = "";
        String[] args;
        if (dbCollection != null) {
            readPref.append(dbCollection.getReadPreference().getName());
            writeCon.append(dbCollection.getWriteConcern().toString());
            dbName = dbCollection.getFullName();
        }
        readPref.append("}");
        writeCon.append("}");

        StringBuilder queryResult = new StringBuilder();
        if (queryResultSize != null) {
            queryResult.append("queryResultSize=").append(queryResultSize);
        }

        args = new String[] { operName, statusMsg, costStr, dbName, queryObjectStr, bodyObjectStr,
                sortObjectStr, optionBuilder.toString(), readPref.toString(), writeCon.toString(),
                queryResult.toString() };
        logger.debug(
                "operation={}|status={}|cost={}ms|collection={}|query={}|body={}|sort={}|option={}|readPrefernce={}|writeConcern={}|{}",
                args);
    }
}

From source file:com.edgytech.umongo.CollectionPanel.java

License:Apache License

@Override
protected void updateComponentCustom(JPanel old) {
    try {/*from   www . jav  a  2s.co  m*/
        DBCollection collection = getCollectionNode().getCollection();
        setStringFieldValue(Item.name, collection.getName());
        setStringFieldValue(Item.fullName, collection.getFullName());
        setStringFieldValue(Item.queryOptions, MongoUtils.queryOptionsToString(collection.getOptions()));
        ((DocField) getBoundUnit(Item.writeConcern)).setDoc(collection.getWriteConcern().getCommand());
        ((DocField) getBoundUnit(Item.readPreference)).setDoc(collection.getReadPreference().toDBObject());
        ((CmdField) getBoundUnit(Item.stats)).updateFromCmd(collection);
    } catch (Exception e) {
        UMongo.instance.showError(this.getClass().getSimpleName() + " update", e);
    }
}

From source file:com.edgytech.umongo.CollectionPanel.java

License:Apache License

public void readWriteOptions(ButtonBase button) {
    final DBCollection col = getCollectionNode().getCollection();
    OptionDialog od = UMongo.instance.getGlobalStore().getOptionDialog();
    od.update(col.getOptions(), col.getWriteConcern(), col.getReadPreference());
    if (!od.show()) {
        return;/*from  w ww  .java 2  s.c om*/
    }
    col.setOptions(od.getQueryOptions());
    col.setWriteConcern(od.getWriteConcern());
    col.setReadPreference(od.getReadPreference());
    refresh();
}

From source file:org.cryptorchat.json.JsonDBObject.java

License:Apache License

public void insertToCollection(final DBCollection collection) {
    final JsonDBObject[] array = { this };
    final Object oid = get("_id");
    if (oid != null && !ObjectId.isValid(oid.toString())) {
        objectId = new ObjectId();
        put("_id", objectId);
    }//from  w  ww.jav  a 2 s.  co  m
    collection.insert(array, collection.getWriteConcern(), new JsonDBEncoder());
}

From source file:org.exoplatform.mongo.service.impl.MongoRestServiceImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
private org.exoplatform.mongo.entity.response.Collection searchCollection(String collName, String dbName,
        DB db) {/*from w ww .  j  av  a 2s .  c o m*/
    DBCollection dbCollection = db.getCollection(collName);
    org.exoplatform.mongo.entity.response.Collection collection = new org.exoplatform.mongo.entity.response.Collection();
    collection.setDbName(dbName);
    collection.setName(collName);
    collection.setWriteConcern(org.exoplatform.mongo.entity.response.WriteConcern
            .fromMongoWriteConcern(dbCollection.getWriteConcern()));
    List<DBObject> indexInfos = dbCollection.getIndexInfo();
    List<org.exoplatform.mongo.entity.response.Index> indexes = new ArrayList<org.exoplatform.mongo.entity.response.Index>();
    for (DBObject indexInfo : indexInfos) {
        Map<String, Object> indexed = (Map<String, Object>) indexInfo.get("key");
        if (indexed != null) {
            org.exoplatform.mongo.entity.response.Index index = new org.exoplatform.mongo.entity.response.Index();
            index.setDbName(dbName);
            index.setCollectionName(collName);
            index.setKeys(indexed.keySet());
            indexes.add(index);
        }
    }
    collection.setIndexes(indexes);
    List<org.exoplatform.mongo.entity.response.Document> documents = new ArrayList<org.exoplatform.mongo.entity.response.Document>();
    DBCursor cursor = dbCollection.find();
    while (cursor.hasNext()) {
        org.exoplatform.mongo.entity.response.Document document = new org.exoplatform.mongo.entity.response.Document();
        DBObject dbDoc = cursor.next();
        document.setJson(dbDoc.toString());
        documents.add(document);
    }
    collection.setDocuments(documents);
    return collection;
}

From source file:org.jongo.MongoCollection.java

License:Apache License

public MongoCollection(DBCollection dbCollection, Mapper mapper) {
    this(dbCollection, mapper, dbCollection.getWriteConcern(), dbCollection.getReadPreference());

}