下面列出了com.mongodb.WriteConcern#valueOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* @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;
}
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;
}
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;
}
/**
* 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);
}
}
/**
* 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;
}