Java Code Examples for com.mongodb.WriteConcern#valueOf()

The following examples show how to use com.mongodb.WriteConcern#valueOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Mapper.java    From morphia with Apache License 2.0 6 votes vote down vote up
/**
 * @param type the type look up
 * @param <T>  the class type
 * @return the collection mapped for this class
 */
public <T> MongoCollection<T> getCollection(final Class<T> type) {
    MappedClass mappedClass = getMappedClass(type);
    if (mappedClass == null) {
        throw new MappingException(Sofia.notMappable(type.getName()));
    }
    if (mappedClass.getCollectionName() == null) {
        throw new MappingException(Sofia.noMappedCollection(type.getName()));
    }

    MongoCollection<T> collection = datastore.getDatabase().getCollection(mappedClass.getCollectionName(), type);

    Entity annotation = mappedClass.getEntityAnnotation();
    if (annotation != null && WriteConcern.valueOf(annotation.concern()) != null) {
        collection = collection.withWriteConcern(WriteConcern.valueOf(annotation.concern()));
    }
    return collection;
}
 
Example 2
Source File: DatabasesForMongoDBCreator.java    From bluemix-cloud-connectors with Apache License 2.0 5 votes vote down vote up
public SimpleMongoDbFactory configure(SimpleMongoDbFactory mongoDbFactory, MongoDbFactoryConfig config) {
    if (config != null && config.getWriteConcern() != null) {
        WriteConcern writeConcern = WriteConcern.valueOf(config.getWriteConcern());
        if (writeConcern != null) {
            mongoDbFactory.setWriteConcern(writeConcern);
        }
    }
    return mongoDbFactory;
}
 
Example 3
Source File: MongoDbFactoryCreator.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
public SimpleMongoDbFactory configure(SimpleMongoDbFactory mongoDbFactory, MongoDbFactoryConfig config) {
	if (config != null && config.getWriteConcern() != null) {
		WriteConcern writeConcern = WriteConcern.valueOf(config.getWriteConcern());
		if (writeConcern != null) {
			mongoDbFactory.setWriteConcern(writeConcern);
		}
	}
	return mongoDbFactory;
}
 
Example 4
Source File: MongoRepository.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the write concern of the template. Support options defined in Mongo's WriteConcern
 * class.
 *
 * @see com.mongodb.WriteConcern
 */
@Override
public void setWriteConcern(String writeConcern) {
    try {
        WriteConcern concern = WriteConcern.valueOf(writeConcern);
        template.setWriteConcern(concern);
    } catch (RuntimeException ex) {
        LOG.warn("Unknown write concern", writeConcern);
        // When in doubt, play it (Replicas) safe.
        template.setWriteConcern(WriteConcern.REPLICAS_SAFE);
    }
}
 
Example 5
Source File: Mapper.java    From morphia with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the write concern for entity or returns the default write concern for this datastore
 *
 * @param clazz the class to use when looking up the WriteConcern
 * @return the write concern for the type
 * @morphia.internal
 */
public WriteConcern getWriteConcern(final Class clazz) {
    WriteConcern wc = null;
    if (clazz != null) {
        final Entity entityAnn = getMappedClass(clazz).getEntityAnnotation();
        if (entityAnn != null && !entityAnn.concern().isEmpty()) {
            wc = WriteConcern.valueOf(entityAnn.concern());
        }
    }

    return wc;
}