Search in sources :

Example 51 with WriteConcern

use of com.mongodb.WriteConcern in project spring-data-mongodb by spring-projects.

the class PerformanceTests method executeWithWriteConcerns.

private void executeWithWriteConcerns(WriteConcernCallback callback) {
    Constants constants = new Constants(WriteConcern.class);
    for (String constantName : constants.getNames(null)) {
        if (IGNORED_WRITE_CONCERNS.contains(constantName)) {
            continue;
        }
        WriteConcern writeConcern = (WriteConcern) constants.asObject(constantName);
        setupCollections();
        callback.doWithWriteConcern(constantName, writeConcern);
    }
}
Also used : WriteConcern(com.mongodb.WriteConcern) Constants(org.springframework.core.Constants)

Example 52 with WriteConcern

use of com.mongodb.WriteConcern in project pinpoint by naver.

the class MongoWriteConcernMapper method buildWriteConcern.

private Map<WriteConcern, String> buildWriteConcern() {
    Map<WriteConcern, String> writeConcernMap = new HashMap<>();
    for (final Field f : WriteConcern.class.getFields()) {
        if (Modifier.isStatic(f.getModifiers()) && f.getType().equals(WriteConcern.class) && f.getAnnotation(Deprecated.class) == null) {
            String value = f.getName();
            try {
                WriteConcern key = (WriteConcern) f.get(null);
                writeConcernMap.put(key, value);
            } catch (IllegalAccessException e) {
                PLogger logger = PLoggerFactory.getLogger(this.getClass());
                logger.warn("WriteConcern access error Caused by:" + e.getMessage(), e);
            }
        }
    }
    return writeConcernMap;
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) WriteConcern(com.mongodb.WriteConcern) PLogger(com.navercorp.pinpoint.bootstrap.logging.PLogger)

Example 53 with WriteConcern

use of com.mongodb.WriteConcern in project morphia by mongodb.

the class Mapper method getWriteConcern.

/**
 * 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
 */
@Nullable
public WriteConcern getWriteConcern(Class clazz) {
    WriteConcern wc = null;
    EntityModel entityModel = getEntityModel(clazz);
    if (entityModel != null) {
        final Entity entityAnn = entityModel.getEntityAnnotation();
        if (entityAnn != null && !entityAnn.concern().isEmpty()) {
            wc = WriteConcern.valueOf(entityAnn.concern());
        }
    }
    return wc;
}
Also used : ExternalEntity(dev.morphia.annotations.experimental.ExternalEntity) Entity(dev.morphia.annotations.Entity) WriteConcern(com.mongodb.WriteConcern) EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Nullable(com.mongodb.lang.Nullable)

Aggregations

WriteConcern (com.mongodb.WriteConcern)53 Document (org.bson.Document)14 MongoException (com.mongodb.MongoException)11 List (java.util.List)11 ArrayList (java.util.ArrayList)9 ReadPreference (com.mongodb.ReadPreference)8 Map (java.util.Map)8 Collectors (java.util.stream.Collectors)8 TimeUnit (java.util.concurrent.TimeUnit)7 BsonDocument (org.bson.BsonDocument)7 DeleteResult (com.mongodb.client.result.DeleteResult)6 HashMap (java.util.HashMap)6 ClientSessionOptions (com.mongodb.ClientSessionOptions)5 ReadConcern (com.mongodb.ReadConcern)5 Arrays (java.util.Arrays)5 BsonValue (org.bson.BsonValue)5 FullDocument (com.mongodb.client.model.changestream.FullDocument)4 InsertOneResult (com.mongodb.client.result.InsertOneResult)4 MongoClient (com.mongodb.reactivestreams.client.MongoClient)4 MongoCollection (com.mongodb.reactivestreams.client.MongoCollection)4