public MongoDocument copy() { MongoDocument m = new MongoDocument(); m.putAll((Document<MongoType>)this); return m; } }
@Override @Deprecated public boolean containsKey(String s) { return containsField(s); }
@Override public boolean removeFetchedBy(String stage) { if(fetchedBy(stage)) { touchedMetadata.add(FETCHED_METADATA_TAG); return getMetadataSubMap(FETCHED_METADATA_TAG).remove(stage)!=null; } return false; }
if(!touchedBy(s)) { return false; if(touchedBy(s)) { return false; if(mq.getAction() != null && mq.getAction() != getAction()) { return false; if(!hasContentField(e.getKey()) || !getContentField(e.getKey()).equals(e.getValue())) { return false; if(hasContentField(e.getKey()) && getContentField(e.getKey()).equals(e.getValue())) { return false; if(!hasContentField(s)) { return false; if(hasContentField(s)) { return false; if(!fetchedBy(s)) { return false; if(fetchedBy(s)) { return false; if(!hasMetadataField(s)) { return false;
return false; mdq.requireID(md.getID()); if(md.isActionTouched()) { bob.add(MongoDocument.ACTION_KEY, md.getAction().toString()); for(String s : md.getTouchedContent()) { if(md.getContentField(s)!=null) { bob.add(MongoDocument.CONTENTS_KEY+"."+s, md.getContentField(s)); for(String s : md.getTouchedMetadata()){ bob.add(MongoDocument.METADATA_KEY+"."+s, md.getMetadataField(s));
@Override public boolean isEqual(Document<?> d) { if(d.getID()!=null) { if(!d.getID().getID().equals(getID().getID())) { return false; } } else { if(getID()!=null) { return false; } } if(d.getAction()!=getAction()) { return false; } if(equalMetadata(d) && equalContent(d)) { return true; } return false; }
public static MongoDocument staticConvert(LocalDocument document) { MongoDocument doc; try { doc = new MongoDocument(document.toJson()); return doc; } catch (JsonException e) { return null; } }
private boolean equalContent(Document<?> d) { Set<String> content = d.getContentFields(); if(content.size()!=getContentFields().size()) { return false; } for(String s : content) { if(!getContentFields().contains(s)) { return false; } if(!Comparator.equals(getContentField(s), d.getContentField(s))) { return false; } } return true; }
public MongoDocument(String json) throws JsonException { this(); fromJson(json); }
@Override public DatabaseDocument<MongoType> convert(Document<?> document) throws ConversionException { try { if (contains(document, "\u0000")) { throw new ConversionException( "A document cannot contain the NUL character. See https://jira.mongodb.org/browse/SERVER-7691"); } return new MongoDocument(document.toJson()); } catch (JsonException e) { throw new ConversionException( "JSON Exception caught while converting", e); } }
private MongoDocument findAndModify(DBObject query, DBObject modification) { DBObject c = documents.findAndModify(query, modification); if(c==null) { return null; } MongoDocument md = new MongoDocument(); md.putAll(c); return md; }
public static void main(String[] args) throws IOException, JsonException { MongoClient mongo = new MongoClient(new MongoClientURI(conf.getDatabaseUrl())); DB db = mongo.getDB(conf.getNamespace()); WriteConcern concern = mongo.getWriteConcern(); long documentsToKeep = conf.getOldMaxCount(); int oldDocsMaxSizeMB = conf.getOldMaxSize(); StatusUpdater updater = new StatusUpdater(new MongoConnector(conf)); GridFS documentFs = new GridFS(db); MongoDocumentIO io = new MongoDocumentIO(db, concern, documentsToKeep, oldDocsMaxSizeMB, updater, documentFs); io.prepare(); MongoDocument document = new MongoDocument(args[args.length-1]); io.insert(document); System.out.println("Added document"); }