@Override public MongoDocument getDocumentById(DocumentID<MongoType> id, boolean includeInactive) { MongoQuery mq = new MongoQuery(); mq.requireID(id); MongoDocument doc = (MongoDocument) documents.findOne(mq.toDBObject()); if(doc==null && includeInactive) { doc = (MongoDocument) oldDocuments.findOne(mq.toDBObject()); } return doc; }
public MongoQuery(String json) throws JsonException { this(); fromJson(json); }
@Override public final void requireMetadataFieldEquals(String s, Object o) { qb = putMetadataField(s).is(o); getMetadataEquals().put(s, o); }
for(String s : mq.getTouchedBy()) { if(!touchedBy(s)) { return false; for(String s : mq.getNotTouchedBy()) { if(touchedBy(s)) { return false; if(mq.getAction() != null && mq.getAction() != getAction()) { return false; for(Map.Entry<String, Object> e : mq.getContentsEquals().entrySet()) { if(!hasContentField(e.getKey()) || !getContentField(e.getKey()).equals(e.getValue())) { return false; for(Map.Entry<String, Object> e : mq.getContentsNotEquals().entrySet()) { if(hasContentField(e.getKey()) && getContentField(e.getKey()).equals(e.getValue())) { return false; for(String s : mq.getContentsExists()) { if(!hasContentField(s)) { return false; for(String s : mq.getContentsNotExists()) { if(hasContentField(s)) { return false; for(String s : mq.getFetchedBy()) { if(!fetchedBy(s)) {
@Override public MongoQuery convert(Query query) { try { return new MongoQuery(query.toJson()); } catch (JsonException e) { return null; } }
public static MongoQuery staticConvert(LocalQuery query) { MongoQuery mdq; try { mdq = new MongoQuery(query.toJson()); return mdq; } catch (JsonException e) { return null; } }
@Override public boolean markTouched(DocumentID<MongoType> id, String tag) { MongoQuery mq = new MongoQuery(); mq.requireID(id); DBObject update = new BasicDBObject(MongoDocument.METADATA_KEY+"."+DatabaseDocument.TOUCHED_METADATA_TAG+"."+tag, new Date()); DBObject dbo = getUpdateObject(update); if(documents.findAndModify(mq.toDBObject(), dbo)==null) { return false; } return true; }
@Override public boolean markPending(DatabaseDocument<MongoType> d, String stage) { MongoQuery mq = new MongoQuery(); mq.requireID(d.getID()); DBObject update = new BasicDBObject(); update.put(MongoDocument.METADATA_KEY+"."+MongoDocument.PENDING_METADATA_FLAG+"."+MongoDocument.DATE_METADATA_SUBKEY, new Date()); update.put(MongoDocument.METADATA_KEY+"."+MongoDocument.PENDING_METADATA_FLAG+"."+MongoDocument.STAGE_METADATA_SUBKEY, stage); DBObject dbo = getUpdateObject(update); if(documents.findAndModify(mq.toDBObject(), dbo)==null) { return false; } return true; }
private boolean markDone(final DatabaseDocument<MongoType> d, String stage, String stamp) { MongoQuery mq = new MongoQuery(); mq.requireID(d.getID()); DBObject doc = documents.findAndRemove(mq.toDBObject()); if(doc==null) { return false; } doc.putAll(((MongoDocument)d).toMap()); stampMetadataField(doc, stamp, stage); deleteAllFiles(d); return writeToOldDocuments(d, stage, doc); }
MongoDocument md = (MongoDocument) d; MongoQuery mdq = new MongoQuery(); if(d.getID() == null) { logger.error("Unable to update document without an ID: "+d); return false; mdq.requireID(md.getID()); WriteResult wr = documents.update(mdq.toDBObject(), updateObject, true, false, concern); return wr.getN()==1;