Example usage for com.mongodb WriteConcern ACKNOWLEDGED

List of usage examples for com.mongodb WriteConcern ACKNOWLEDGED

Introduction

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

Prototype

WriteConcern ACKNOWLEDGED

To view the source code for com.mongodb WriteConcern ACKNOWLEDGED.

Click Source Link

Document

Write operations that use this write concern will wait for acknowledgement, using the default write concern configured on the server.

Usage

From source file:org.alfresco.contentstore.dao.mongo.MongoNodeUsageDAO.java

License:Open Source License

private void init() {
    if (db == null) {
        throw new RuntimeException("Mongo DB must not be null");
    }//from  ww w.  ja  v  a2s.  c  o m

    this.nodeUsageData = getCollection(db, nodeUsageCollectionName, WriteConcern.ACKNOWLEDGED);
    DBObject keys = BasicDBObjectBuilder.start("e", 1).add("n", 1).add("m", 1).get();
    this.nodeUsageData.ensureIndex(keys, "byMimeType", false);
}

From source file:org.alfresco.repo.domain.node.mongo.MongoNodeDAO.java

License:Open Source License

public void init() {
    if (db == null) {
        throw new RuntimeException("Mongo DB must not be null");
    }/*from   ww w .j a v a  2  s . com*/

    this.nodes = getCollection(db, nodesCollectionName, WriteConcern.ACKNOWLEDGED);

    {
        DBObject primary = BasicDBObjectBuilder.start("n", 1).add("v", 1).get();
        DBObject options = BasicDBObjectBuilder.start("unique", true).get();
        nodes.createIndex(primary, options);
    }

    {
        DBObject idx1 = BasicDBObjectBuilder.start("n", 1).add("vl", 1).add("c", 1).add("v", 1).get();
        nodes.createIndex(idx1);
    }

    {
        DBObject idx1 = BasicDBObjectBuilder.start("n", 1).add("c", 1).add("v", 1).get();
        nodes.createIndex(idx1);
    }
}

From source file:org.alfresco.semantics.MongoSemantics.java

License:Open Source License

public void init() {
    this.relations = getCollection(db, relationsCollectionName, WriteConcern.ACKNOWLEDGED);

    {/*from   w w  w. ja v a2s . c  o m*/
        DBObject idx = BasicDBObjectBuilder.start("f", 1).add("c", 1).get();
        DBObject options = BasicDBObjectBuilder.start("unique", false).add("sparse", true).add("name", "from")
                .get();
        this.relations.createIndex(idx, options);
    }

    {
        DBObject idx = BasicDBObjectBuilder.start("t", 1).add("c", 1).get();
        DBObject options = BasicDBObjectBuilder.start("unique", false).add("sparse", true).add("name", "to")
                .get();
        this.relations.createIndex(idx, options);
    }
}

From source file:org.apache.jackrabbit.oak.plugins.document.util.MongoConnection.java

License:Apache License

/**
 * Returns the default write concern depending on MongoDB deployment.
 * <ul>//from  w w w .ja  va  2 s  .  c o m
 *     <li>{@link WriteConcern#MAJORITY}: for a MongoDB replica set</li>
 *     <li>{@link WriteConcern#ACKNOWLEDGED}: for single MongoDB instance</li>
 * </ul>
 *
 * @param db the connection to MongoDB.
 * @return the default write concern to use for Oak.
 */
public static WriteConcern getDefaultWriteConcern(@Nonnull DB db) {
    WriteConcern w;
    if (checkNotNull(db).getMongo().getReplicaSetStatus() != null) {
        w = WriteConcern.MAJORITY;
    } else {
        w = WriteConcern.ACKNOWLEDGED;
    }
    return w;
}

From source file:org.apache.nifi.mongodb.AbstractMongoDBControllerService.java

License:Apache License

protected WriteConcern getWriteConcern(final ConfigurationContext context) {
    final String writeConcernProperty = context.getProperty(WRITE_CONCERN).getValue();
    WriteConcern writeConcern = null;/*from ww w.  j a v  a  2s  .c  o m*/
    switch (writeConcernProperty) {
    case WRITE_CONCERN_ACKNOWLEDGED:
        writeConcern = WriteConcern.ACKNOWLEDGED;
        break;
    case WRITE_CONCERN_UNACKNOWLEDGED:
        writeConcern = WriteConcern.UNACKNOWLEDGED;
        break;
    case WRITE_CONCERN_FSYNCED:
        writeConcern = WriteConcern.FSYNCED;
        break;
    case WRITE_CONCERN_JOURNALED:
        writeConcern = WriteConcern.JOURNALED;
        break;
    case WRITE_CONCERN_REPLICA_ACKNOWLEDGED:
        writeConcern = WriteConcern.REPLICA_ACKNOWLEDGED;
        break;
    case WRITE_CONCERN_MAJORITY:
        writeConcern = WriteConcern.MAJORITY;
        break;
    default:
        writeConcern = WriteConcern.ACKNOWLEDGED;
    }
    return writeConcern;
}

From source file:org.apache.rya.mongodb.batch.collection.DbCollectionType.java

License:Apache License

@Override
public void insertOne(final DBObject item) {
    collection.insert(item, WriteConcern.ACKNOWLEDGED);
}

From source file:org.apache.tapestry5.mongodb.modules.MongodbModule.java

License:Apache License

/**
 * Contribute coercions for {@link WriteConcern} and {@link ReadPreference} to have them from
 * {@link org.apache.tapestry5.ioc.annotations.Symbol}
 *
 * @param configuration lets help the {@link org.apache.tapestry5.ioc.services.TypeCoercer} service
 *///from   w ww.  j a v  a  2s. c  o  m
public static void contributeTypeCoercer(Configuration<CoercionTuple> configuration) {
    configuration.add(new CoercionTuple(String.class, WriteConcern.class, new Coercion<String, WriteConcern>() {
        public WriteConcern coerce(String input) {
            if (input.equalsIgnoreCase("FSYNC_SAFE")) {
                return WriteConcern.FSYNC_SAFE;
            } else if (input.equalsIgnoreCase("JOURNAL_SAFE")) {
                return WriteConcern.JOURNAL_SAFE;
            } else if (input.equalsIgnoreCase("MAJORITY")) {
                return WriteConcern.MAJORITY;
            } else if (input.equalsIgnoreCase("NONE")) {
                return WriteConcern.NONE;
            } else if (input.equalsIgnoreCase("REPLICAS_SAFE")) {
                return WriteConcern.REPLICAS_SAFE;
            } else if (input.equalsIgnoreCase("SAFE")) {
                return WriteConcern.SAFE;
            } else if (input.equalsIgnoreCase("NORMAL")) {
                return WriteConcern.NORMAL;
            } else // WriteConcern.ACKNOWLEDGED IS OUR DEFAULT
            {
                return WriteConcern.ACKNOWLEDGED;
            }
        }
    }));

    configuration
            .add(new CoercionTuple(String.class, ReadPreference.class, new Coercion<String, ReadPreference>() {
                public ReadPreference coerce(String input) {
                    if (input.equalsIgnoreCase("SECONDARY")) {
                        return ReadPreference.secondary();
                    } else // PRIMARY IS OUR DEFAULT
                    {
                        return ReadPreference.primary();
                    }
                }
            }));
}

From source file:org.botdefender.collector.MongoMessageWriter.java

License:Open Source License

public void writeHit(String json) throws Exception {
    try {/*from  w  w  w .  j  a  v a  2s  .com*/
        if (collection == null) {
            logger.info("Connecting to the mongodb database");
            collection = connectHitsCollection();
            logger.info("successfully connected");
        }

        if (json != null) {
            jsonList.add((DBObject) JSON.parse(json));
        }

        if ((json == null && jsonList.size() > 0)
                || (jsonList.size() > config.getMessageWriterMaxBatchSize())) {
            collection.insert(jsonList, WriteConcern.ACKNOWLEDGED);
            jsonList.clear();
            logger.info("INSERTING INTO DATABASE");
        }
    } catch (Exception e) {
        // We can throw away old events if the queue is full
        logger.error("Error trying to write data, trying again [" + e.getMessage() + "]");
        collection = null;
        Thread.sleep(1000);
    }
}

From source file:org.Cherry.Modules.Security.Middleware.MorphiaRepositoryTemplate.java

License:LGPL

protected <T> Key<T> persist(final T entity) {
    return persist(entity, WriteConcern.ACKNOWLEDGED);
}

From source file:org.eclipse.persistence.nosql.adapters.mongo.MongoConnectionSpec.java

License:Open Source License

/**
 * Connect with the specified properties and return the Connection.
 *//*from w  ww . j a  va 2  s  . c o m*/
public Connection connectToDataSource(EISAccessor accessor, Properties properties)
        throws DatabaseException, ValidationException {
    if ((this.connectionFactory == null) && (this.name == null)) {
        this.connectionFactory = new MongoConnectionFactory();
    }
    if (!properties.isEmpty()) {
        if (this.connectionSpec == null) {
            this.connectionSpec = new MongoJCAConnectionSpec();
        }
        MongoJCAConnectionSpec spec = (MongoJCAConnectionSpec) this.connectionSpec;
        String host = (String) properties.get(HOST);
        String port = (String) properties.get(PORT);
        String db = (String) properties.get(DB);
        if (host != null) {
            if (host.indexOf(',') == -1) {
                spec.getHosts().add(host);
                if (port != null) {
                    spec.getPorts().add(new Integer(port));
                }
            } else {
                int startIndex = 0;
                while (startIndex < (host.length() - 1)) {
                    int endIndex = host.indexOf(',', startIndex);
                    if (endIndex == -1) {
                        endIndex = host.length();
                    }
                    String nextHost = host.substring(startIndex, endIndex);
                    spec.getHosts().add(nextHost);
                    startIndex = endIndex + 1;
                }
                while (startIndex < (port.length() - 1)) {
                    int endIndex = port.indexOf(',', startIndex);
                    if (endIndex == -1) {
                        endIndex = port.length();
                    }
                    String nextPort = port.substring(startIndex, endIndex);
                    spec.getPorts().add(new Integer(nextPort));
                    startIndex = endIndex + 1;
                }
            }
        }
        if (db != null) {
            spec.setDB(db);
        }

        String user = (String) properties.get("user");
        Object password = properties.get("password");
        if (password instanceof String) {
            password = ((String) password).toCharArray();
        }
        if ((user != null) && (user.length() != 0)) {
            spec.setUser(user);
            spec.setPassword((char[]) password);
        }

        // Allows setting of read preference as a property.
        Object preference = properties.get(READ_PREFERENCE);
        if (preference instanceof ReadPreference) {
            spec.setReadPreference((ReadPreference) preference);
        } else if (preference instanceof String) {
            String constant = (String) preference;
            if (constant.equals("PRIMARY")) {
                spec.setReadPreference(ReadPreference.PRIMARY);
            } else if (constant.equals("SECONDARY")) {
                spec.setReadPreference(ReadPreference.SECONDARY);
            } else {
                throw new EISException("Invalid read preference property value: " + constant);
            }
        }

        // Allows setting of write concern as a property.
        Object concern = properties.get(WRITE_CONCERN);
        if (concern instanceof WriteConcern) {
            spec.setWriteConcern((WriteConcern) concern);
        } else if (concern instanceof String) {
            String constant = (String) concern;
            if (constant.equals("FSYNC_SAFE")) {
                spec.setWriteConcern(WriteConcern.FSYNC_SAFE);
            } else if (constant.equals("ACKNOWLEDGED")) {
                spec.setWriteConcern(WriteConcern.ACKNOWLEDGED);
            } else if (constant.equals("JOURNAL_SAFE")) {
                spec.setWriteConcern(WriteConcern.JOURNAL_SAFE);
            } else if (constant.equals("MAJORITY")) {
                spec.setWriteConcern(WriteConcern.MAJORITY);
            } else if (constant.equals("NONE")) {
                spec.setWriteConcern(WriteConcern.NONE);
            } else if (constant.equals("NORMAL")) {
                spec.setWriteConcern(WriteConcern.NORMAL);
            } else if (constant.equals("REPLICAS_SAFE")) {
                spec.setWriteConcern(WriteConcern.REPLICAS_SAFE);
            } else if (constant.equals("SAFE")) {
                spec.setWriteConcern(WriteConcern.SAFE);
            } else {
                throw new EISException("Invalid read preference property value: " + constant);
            }
        }

        // Allows setting of options as a property.
        Object options = properties.get(OPTIONS);
        if (options instanceof Number) {
            spec.setOptions(((Number) options).intValue());
        } else if (options instanceof String) {
            spec.setOptions(Integer.valueOf(((String) options)));
        }
    }

    return super.connectToDataSource(accessor, properties);
}