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();
}
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");
}
}
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");
}
}
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);
}
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();
}
Aggregations