public DatabaseDocument<T> getCopy(DatabaseDocument<T> doc) { if (doc == null) { return null; } for (int i = 0; i < 10; i++) { try { return doc.copy(); } catch (ConcurrentModificationException e) { } } logger.error("Unable to copy a document with id " + doc); return null; } }
private String getDoneEvent(DatabaseDocument<?> doc) { StringBuffer sb = new StringBuffer(); sb.append(df.format(doc.getCompletedTime())); sb.append(" document="); sb.append(doc.getID()); sb.append(" type=done"); sb.append(" stage="); sb.append(doc.getCompletedBy()); sb.append(" time="); sb.append(doc.getCompletedTime().getTime()-doc.getFetchedTime(doc.getCompletedBy()).getTime()); sb.append(" totaltime="); sb.append(doc.getCompletedTime().getTime()-doc.getTouchedTime(getInserter(doc)).getTime()); return sb.toString(); }
private String getTouchEvent(DatabaseDocument<?> doc, String stage) { StringBuffer sb = new StringBuffer(); sb.append(df.format(doc.getTouchedTime(stage))); sb.append(" document="); sb.append(doc.getID()); sb.append(" type=touch"); sb.append(" stage="); sb.append(stage); sb.append(" time="); sb.append(doc.getTouchedTime(stage).getTime() - doc.getFetchedTime(stage).getTime()); return sb.toString(); }
private String getFetchEvent(DatabaseDocument<?> doc, String stage) { StringBuffer sb = new StringBuffer(); sb.append(df.format(doc.getFetchedTime(stage))); sb.append(" document="); sb.append(doc.getID()); sb.append(" type=fetch"); sb.append(" stage="); sb.append(stage); return sb.toString(); }
private String getSummary(DatabaseDocument<?> doc) { StringBuilder sb = new StringBuilder(); sb.append(doc.getID()); sb.append(" status="); sb.append(doc.getStatus().toString()); Date inserted = doc.getTouchedTime(getInserter(doc)); sb.append(" inserted_time=\""); sb.append(inserted); sb.append('"'); Date completed = doc.getCompletedTime(); sb.append(" completed_time=\""); sb.append(completed); sb.append(completed.getTime()-inserted.getTime()); Set<String> touched = doc.getTouchedBy(); Set<String> fetched = doc.getFetchedBy(); for(String e : fetched) { sb.append(' '); sb.append('='); if(touched.contains(e)) { sb.append(doc.getTouchedTime(e).getTime() - doc.getFetchedTime(e).getTime()); } else if(e.equals(doc.getCompletedBy())){ sb.append(doc.getCompletedTime().getTime() - doc.getFetchedTime(e).getTime()); } else { sb.append('?');
@Override public DatabaseDocument<T> getAndTag(DatabaseQuery<T> query, String ... tags) { for(String tag : tags) { query.requireNotFetchedByStage(tag); } DatabaseDocument<T> doc; synchronized (this) { doc = getDocument(query); if (doc != null) { freshen(doc.getID()); for(String tag : tags) { doc.setFetchedBy(tag, new Date()); } } } return doc; }
} catch (MongoInternalException e) { String largestContentField = getLargestContentField(document); document.putContentField(largestContentField, "<Removed>"); document.addError(stage, e); mongoDocument.putAll(((MongoDocument) document).toMap()); logger.error("An error occurred while writing document " + document.getID() + " to " + oldDocuments.getName() + ": " + e.getMessage(), e); + document.getID() + " to " + oldDocuments.getName() + ": " + e.getMessage(), e);
private String getInsertEvent(DatabaseDocument<?> doc) { StringBuffer sb = new StringBuffer(); String stage = getInserter(doc); sb.append(df.format(doc.getTouchedTime(stage))); sb.append(" document="); sb.append(doc.getID()); sb.append(" type=insert"); sb.append(" stage="); sb.append(stage); return sb.toString(); }
@Override public boolean insert(DatabaseDocument<MongoType> d) { if(d.getID()==null) { try { for(String key : getNullFields((MongoDocument)d)) { d.removeContentField(key); } documents.insert((MongoDocument) d, concern); return true; } catch (MongoException e) { logger.error("INSERT FAILED FOR id:"+d.getID(), e); } } return false; }
@Override public boolean markTouched(DocumentID<T> id, String tag) { DatabaseDocument<T> inCache; synchronized (this) { inCache = getDocumentById(id); if (inCache != null) { freshen(inCache.getID()); inCache.setTouchedBy(tag, new Date()); return true; } } return false; }
@Override public boolean update(DatabaseDocument<T> d) { if (!cache.update(d)) { DatabaseDocument<T> doc = reader.getDocumentById(d.getID()); if (doc != null) { cache.add(doc); cache.update(d); } if (cache.getDocumentById(d.getID()) == null) { d.removeFetchedBy(CACHE_TAG); } return writer.update(d); } return true; }
@Override public boolean insert(DatabaseDocument<MongoType> d, List<DocumentFile<MongoType>> attachments) { if(attachments == null || attachments.isEmpty()) { return insert(d); } d.putMetadataField(MongoDocument.COMMITTING_METADATA_FLAG, true); if (!insert(d)) { return false; }; if (!writeAttachments(d, attachments)) { delete(d); return false; } d.putMetadataField(MongoDocument.COMMITTING_METADATA_FLAG, false); return update(d); }
private Collection<? extends String> getTouchedEvents( DatabaseDocument<?> doc) { ArrayList<String> list = new ArrayList<String>(); for(String stage : doc.getTouchedBy()) { if(doc.fetchedBy(stage)) { list.add(getTouchEvent(doc, stage)); } } return list; }
@Override public Collection<DatabaseDocument<T>> getAndTag(DatabaseQuery<T> query, int n, String ... tags) { for(String tag : tags) { query.requireNotFetchedByStage(tag); } ArrayList<DatabaseDocument<T>> list; synchronized (this) { list = getDocument(query, n); for (DatabaseDocument<T> d : list) { freshen(d.getID()); for(String tag : tags) { d.setFetchedBy(tag, new Date()); } } } return list; }
@Override public boolean insert(DatabaseDocument<MemoryType> d, List<DocumentFile<MemoryType>> attachments) { if(attachments == null || attachments.isEmpty()) { return insert(d); } d.putMetadataField(Document.COMMITTING_METADATA_FLAG, true); if (!insert(d)) { return false; }; if (!writeAttachments(d, attachments)) { delete(d); return false; } d.putMetadataField(Document.COMMITTING_METADATA_FLAG, false); return update(d); }
@Override public DocumentFile<MongoType> getDocumentFile(DatabaseDocument<MongoType> d, String filename) { return getDocumentFile(d.getID(), filename); }
@Override public boolean deleteDocumentFile(DatabaseDocument<MemoryType> d, String fileName) { for (DocumentFile<MemoryType> f : files) { if (f.getDocumentId().equals(d.getID()) && f.getFileName().equals(fileName)) { files.remove(f); return true; } } return false; }