Example usage for com.mongodb WriteConcern getWString

List of usage examples for com.mongodb WriteConcern getWString

Introduction

In this page you can find the example usage for com.mongodb WriteConcern getWString.

Prototype

public String getWString() 

Source Link

Document

Gets the w parameter as a String.

Usage

From source file:org.pentaho.mongo.MongoPropToOption.java

License:Open Source License

public WriteConcern writeConcernValue(final MongoProperties props) throws MongoDbException {
    // write concern
    String writeConcern = props.get(MongoProp.writeConcern);
    String wTimeout = props.get(MongoProp.wTimeout);
    boolean journaled = Boolean.valueOf(props.get(MongoProp.JOURNALED));

    WriteConcern concern;

    if (!Util.isEmpty(writeConcern) && Util.isEmpty(wTimeout) && !journaled) {
        // all defaults - timeout 0, journal = false, w = 1
        concern = new WriteConcern();
        concern.setWObject(1);/*from  w  w  w.  j a v  a2s.  co m*/

        if (log != null) {
            log.info(getString(PKG, "MongoPropToOption.Message.ConfiguringWithDefaultWriteConcern")); //$NON-NLS-1$
        }
    } else {
        int wt = 0;
        if (!Util.isEmpty(wTimeout)) {
            try {
                wt = Integer.parseInt(wTimeout);
            } catch (NumberFormatException n) {
                throw new MongoDbException(n);
            }
        }

        if (!Util.isEmpty(writeConcern)) {
            // try parsing as a number first
            try {
                int wc = Integer.parseInt(writeConcern);
                concern = new WriteConcern(wc, wt, false, journaled);
            } catch (NumberFormatException n) {
                // assume its a valid string - e.g. "majority" or a custom
                // getLastError label associated with a tag set
                concern = new WriteConcern(writeConcern, wt, false, journaled);
            }
        } else {
            concern = new WriteConcern(1, wt, false, journaled);
        }

        if (log != null) {
            String lwc = "w = " + concern.getWString() + ", wTimeout = " + concern.getWtimeout()
                    + ", journaled = " + concern.getJ();
            log.info(getString(PKG, "MongoPropToOption.Message.ConfiguringWithWriteConcern", lwc));
        }
    }
    return concern;
}