Example usage for com.mongodb DBCollection setOptions

List of usage examples for com.mongodb DBCollection setOptions

Introduction

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

Prototype

@Deprecated
public void setOptions(final int options) 

Source Link

Document

Sets the default query options, overwriting previous value.

Usage

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;//ww  w . j a v a  2  s .com
    }
    col.setOptions(od.getQueryOptions());
    col.setWriteConcern(od.getWriteConcern());
    col.setReadPreference(od.getReadPreference());
    refresh();
}

From source file:com.github.nlloyd.hornofmongo.adaptor.Mongo.java

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
@JSFunction//w w  w  . j  a  v a  2s  .co  m
public void insert(final String ns, Object obj, int options) {
    Object rawObj = BSONizer.convertJStoBSON(obj, true);
    DBObject bsonObj = null;
    if (rawObj instanceof DBObject)
        bsonObj = (DBObject) rawObj;

    try {
        int dbSeparatorIdx = ns.indexOf('.');
        com.mongodb.DB db = innerMongo.getDB(ns.substring(0, dbSeparatorIdx));
        String collectionName = ns.substring(dbSeparatorIdx + 1);
        DBCollection collection = db.getCollection(collectionName);
        collection.setDBEncoderFactory(HornOfMongoBSONEncoder.FACTORY);
        collection.setDBDecoderFactory(HornOfMongoBSONDecoder.FACTORY);
        // unfortunately the Java driver does not expose the _allow_dot
        // argument in insert calls so we need to translate system.indexes
        // inserts into index creation calls through the java driver
        if (collectionName.endsWith("system.indexes")) {
            db.getCollection("system.indexes").insert(Arrays.asList(bsonObj));
        } else {
            int oldOptions = collection.getOptions();
            collection.setOptions(options);

            List insertObj = null;
            if (rawObj instanceof List)
                insertObj = (List) rawObj;
            else
                insertObj = Arrays.asList(rawObj);
            collection.insert(insertObj);
            collection.setOptions(oldOptions);
        }
        saveLastCalledDB(db);
    } catch (MongoException me) {
        handleMongoException(me);
    }
}