@Override public long getActiveDatabaseSize() { return reader.getActiveDatabaseSize(); }
@Override public DocumentFile<T> getDocumentFile(DatabaseDocument<T> d, String fileName) { return reader.getDocumentFile(d, fileName); }
@Override public List<String> getDocumentFileNames(DatabaseDocument<T> d) { return reader.getDocumentFileNames(d); }
@Override public DatabaseDocument<T> getDocumentById(DocumentID<T> id, boolean includeInactive) { DatabaseDocument<T> doc = getDocumentById(id); if (doc == null && includeInactive) { return reader.getDocumentById(id, includeInactive); } return cache.getDocumentById(id); }
@Override public TailableIterator<T> getInactiveIterator(DatabaseQuery<T> query) { return reader.getInactiveIterator(query); }
/** * Since skip becomes impossible to calculate in a cached scenario, this * will simply query the underlying reader. */ @Override public List<DatabaseDocument<T>> getDocuments(DatabaseQuery<T> q, int limit, int skip) { List<DatabaseDocument<T>> docs = reader.getDocuments(q, limit, skip); cache.add(docs); return docs; }
/** * Due to the nature of a cache, this method will return a result that is * possibly incorrect. In the current implementation, the number reported by * the underlying database is returned and the cache is ignored, since hits * in the cache are potentially just replicas of the hits in the database. * * We have no way of knowing what hits are missing from the reader, but are * in the cache and vice versa, without some very expensive computation. */ @Override public long getNumberOfDocuments(DatabaseQuery<T> q) { return reader.getNumberOfDocuments(q); }
@Override public long getInactiveDatabaseSize() { return reader.getInactiveDatabaseSize(); }
@Override public DocumentID<T> toDocumentId(Object jsonPrimitive) { return reader.toDocumentId(jsonPrimitive); }
@Override public DatabaseDocument<T> getDocument(DatabaseQuery<T> q) { DatabaseDocument<T> doc = cache.getDocument(q); if (doc == null) { doc = reader.getDocument(q); cache.add(doc); } return getCopy(doc); }
@Override public boolean markTouched(DocumentID<T> id, String tag) { if (!cache.markTouched(id, tag)) { DatabaseDocument<T> d = reader.getDocumentById(id); if (d != null) { d.removeFetchedBy(CACHE_TAG); d.setTouchedBy(tag, new Date()); return writer.update(d); } return false; } return true; }
@Override public TailableIterator<T> getInactiveIterator() { return reader.getInactiveIterator(); }
/** * If there is any documents in the cache matching the query, those are * returned, otherwise a direct call is made to the underlying reader. * * As such, this may return 1 document (if one is found in the cache) even * though there are thousands of documents in the underlying database that * match. */ @Override public List<DatabaseDocument<T>> getDocuments(DatabaseQuery<T> q, int limit) { List<DatabaseDocument<T>> docs = new ArrayList<DatabaseDocument<T>>(); docs.addAll(cache.getDocument(q, limit)); if (docs.size() == 0) { docs = reader.getDocuments(q, limit); cache.add(docs); } return docs; }
@Override public DatabaseDocument<T> getDocumentById(DocumentID<T> id) { DatabaseDocument<T> doc = cache.getDocumentById(id); if (doc == null) { doc = reader.getDocumentById(id, false); if(doc != null) { cache.add(doc); } else { return null; } } return getCopy(doc); }
@Override public void run() { iterator = dbc.getDocumentReader().getInactiveIterator(); while(iterator.hasNext()) { if(format==Format.SUMMARY) { logger.info(getSummary(iterator.next())); } else { for(String event : getAllEvents(iterator.next())) { System.out.println(event); } } } }
@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; }