Search in sources :

Example 16 with WriteResult

use of com.mongodb.WriteResult in project GeoGig by boundlessgeo.

the class MongoObjectDatabase method deleteChunk.

private long deleteChunk(List<ObjectId> ids) {
    List<String> idStrings = Lists.transform(ids, Functions.toStringFunction());
    DBObject query = BasicDBObjectBuilder.start().push("oid").add("$in", idStrings).pop().get();
    WriteResult result = collection.remove(query);
    return result.getN();
}
Also used : WriteResult(com.mongodb.WriteResult) BulkWriteResult(com.mongodb.BulkWriteResult) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 17 with WriteResult

use of com.mongodb.WriteResult in project cas by apereo.

the class MongoDbMultifactorAuthenticationTrustStorage method expire.

@Override
public void expire(final String key) {
    try {
        final Query query = new Query();
        query.addCriteria(Criteria.where("key").is(key));
        final WriteResult res = this.mongoTemplate.remove(query, MultifactorAuthenticationTrustRecord.class, this.collectionName);
        LOGGER.info("Found and removed [{}]", res.getN());
    } catch (final Exception e) {
        LOGGER.info("No trusted authentication records could be found");
    }
}
Also used : WriteResult(com.mongodb.WriteResult) Query(org.springframework.data.mongodb.core.query.Query)

Example 18 with WriteResult

use of com.mongodb.WriteResult in project cas by apereo.

the class MongoDbMultifactorAuthenticationTrustStorage method expire.

@Override
public void expire(final LocalDate onOrBefore) {
    try {
        final Query query = new Query();
        query.addCriteria(Criteria.where("date").lte(onOrBefore));
        final WriteResult res = this.mongoTemplate.remove(query, MultifactorAuthenticationTrustRecord.class, this.collectionName);
        LOGGER.info("Found and removed [{}]", res.getN());
    } catch (final Exception e) {
        LOGGER.info("No trusted authentication records could be found");
    }
}
Also used : WriteResult(com.mongodb.WriteResult) Query(org.springframework.data.mongodb.core.query.Query)

Example 19 with WriteResult

use of com.mongodb.WriteResult in project jetty.project by eclipse.

the class MongoSessionDataStore method doStore.

/** 
     * @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(String, SessionData, long) 
     */
@Override
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception {
    NoSqlSessionData nsqd = (NoSqlSessionData) data;
    // Form query for upsert
    BasicDBObject key = new BasicDBObject(__ID, id);
    // Form updates
    BasicDBObject update = new BasicDBObject();
    boolean upsert = false;
    BasicDBObject sets = new BasicDBObject();
    BasicDBObject unsets = new BasicDBObject();
    Object version = ((NoSqlSessionData) data).getVersion();
    // New session
    if (lastSaveTime <= 0) {
        upsert = true;
        version = new Long(1);
        sets.put(__CREATED, nsqd.getCreated());
        sets.put(__VALID, true);
        sets.put(getContextSubfield(__VERSION), version);
        sets.put(getContextSubfield(__LASTSAVED), data.getLastSaved());
        sets.put(getContextSubfield(__LASTNODE), data.getLastNode());
        sets.put(__MAX_IDLE, nsqd.getMaxInactiveMs());
        sets.put(__EXPIRY, nsqd.getExpiry());
        nsqd.setVersion(version);
    } else {
        sets.put(getContextSubfield(__LASTSAVED), data.getLastSaved());
        sets.put(getContextSubfield(__LASTNODE), data.getLastNode());
        version = new Long(((Number) version).longValue() + 1);
        nsqd.setVersion(version);
        update.put("$inc", _version_1);
        //if max idle time and/or expiry is smaller for this context, then choose that for the whole session doc
        BasicDBObject fields = new BasicDBObject();
        fields.append(__MAX_IDLE, true);
        fields.append(__EXPIRY, true);
        DBObject o = _dbSessions.findOne(new BasicDBObject("id", id), fields);
        if (o != null) {
            Long tmpLong = (Long) o.get(__MAX_IDLE);
            long currentMaxIdle = (tmpLong == null ? 0 : tmpLong.longValue());
            tmpLong = (Long) o.get(__EXPIRY);
            long currentExpiry = (tmpLong == null ? 0 : tmpLong.longValue());
            if (currentMaxIdle != nsqd.getMaxInactiveMs())
                sets.put(__MAX_IDLE, nsqd.getMaxInactiveMs());
            if (currentExpiry != nsqd.getExpiry())
                sets.put(__EXPIRY, nsqd.getExpiry());
        } else
            LOG.warn("Session {} not found, can't update", id);
    }
    sets.put(__ACCESSED, nsqd.getAccessed());
    Set<String> names = nsqd.takeDirtyAttributes();
    if (lastSaveTime <= 0) {
        // note dirty may include removed names
        names.addAll(nsqd.getAllAttributeNames());
    }
    for (String name : names) {
        Object value = data.getAttribute(name);
        if (value == null)
            unsets.put(getContextField() + "." + encodeName(name), 1);
        else
            sets.put(getContextField() + "." + encodeName(name), encodeName(value));
    }
    // Do the upsert
    if (!sets.isEmpty())
        update.put("$set", sets);
    if (!unsets.isEmpty())
        update.put("$unset", unsets);
    WriteResult res = _dbSessions.update(key, update, upsert, false, WriteConcern.SAFE);
    if (LOG.isDebugEnabled())
        LOG.debug("Save:db.sessions.update( {}, {},{} )", key, update, res);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) WriteResult(com.mongodb.WriteResult) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 20 with WriteResult

use of com.mongodb.WriteResult in project android-uploader by nightscout.

the class MongoUploaderTest method setUpUpsertCapture.

public void setUpUpsertCapture() {
    captor = ArgumentCaptor.forClass(BasicDBObject.class);
    WriteResult result = mock(WriteResult.class);
    when(result.getError()).thenReturn(null);
    when(mockCollection.update(any(DBObject.class), captor.capture(), eq(true), eq(false), eq(WriteConcern.UNACKNOWLEDGED))).thenReturn(result);
    validateMockitoUsage();
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) WriteResult(com.mongodb.WriteResult) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Aggregations

WriteResult (com.mongodb.WriteResult)27 BasicDBObject (com.mongodb.BasicDBObject)17 DBObject (com.mongodb.DBObject)14 DBCollection (com.mongodb.DBCollection)9 Test (org.junit.Test)5 BulkWriteResult (com.mongodb.BulkWriteResult)3 DB (com.mongodb.DB)3 Date (java.util.Date)3 List (java.util.List)3 ImmutableList (com.google.common.collect.ImmutableList)2 MongoException (com.mongodb.MongoException)2 QueryBuilder (com.mongodb.QueryBuilder)2 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)2 ObjectId (org.bson.types.ObjectId)2 AlarmCallbackConfiguration (org.graylog2.alarmcallbacks.AlarmCallbackConfiguration)2 EmailAlarmCallback (org.graylog2.alarmcallbacks.EmailAlarmCallback)2 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)2 Stream (org.graylog2.plugin.streams.Stream)2