@Test public void getDocuments() { MemoryQuery mdq = new MemoryQuery(); List<DatabaseDocument<MemoryType>> list = io.getDocuments(mdq, 2); if(list.size()!=2) { fail("Did not return all documents. Expected 2, found "+list.size()); } boolean test1 = false, test2=false; for(Document<MemoryType> d : list) { if("test".equals(d.getContentField("name"))) { if(((Integer)1).equals(d.getContentField("number"))) { test1 = true; } else if(((Integer)2).equals(d.getContentField("number"))) { test2 = true; } } } if (!test1 || !test2 ) { fail("Not all three documents were found"); } mdq.requireContentFieldEquals("name", "test"); list = io.getDocuments(mdq, 3); if(list.size()!=2) { fail("Wrong number of documents returned. Expected 2, found "+list.size()); } mdq.requireContentFieldEquals("number", 2); list = io.getDocuments(mdq, 1); if(list.size()!=1) { fail("Wrong number of documents returned. Expected 1, found "+list.size()); } }
@SuppressWarnings("unchecked") @Override public List<DatabaseDocument<MemoryType>> getDocuments( DatabaseQuery<MemoryType> q, int limit, int skip) { ArrayList<MemoryDocument> list = new ArrayList<MemoryDocument>(); int matching = 0; for (MemoryDocument doc : set.keySet()) { if (list.size() >= limit) break; if (doc.matches((MemoryQuery) q)) { if (matching >= skip) { list.add(doc); } matching++; } } return (List<DatabaseDocument<MemoryType>>) (Object) list; }
MemoryDocumentIO implements DocumentWriter<MemoryType>,
		DocumentReader<MemoryType> { @SuppressWarnings("unchecked") @Override public List<DatabaseDocument<MemoryType>> getDocuments( DatabaseQuery<MemoryType> q, int limit, int skip) { ArrayList<MemoryDocument> list = new ArrayList<MemoryDocument>(); int matching = 0; for (MemoryDocument doc : set.keySet()) { if (list.size() >= limit) break; if (doc.matches((MemoryQuery) q)) { if (matching >= skip) { list.add(doc); } matching++; } } return (List<DatabaseDocument<MemoryType>>) (Object) list; } }
MemoryDocumentIO implements DocumentWriter<MemoryType>,
		DocumentReader<MemoryType> { @SuppressWarnings("unchecked") @Override public List<DatabaseDocument<MemoryType>> getDocuments( DatabaseQuery<MemoryType> q, int limit, int skip) { ArrayList<MemoryDocument> list = new ArrayList<MemoryDocument>(); int matching = 0; for (MemoryDocument doc : set.keySet()) { if (list.size() >= limit) break; if (doc.matches((MemoryQuery) q)) { if (matching >= skip) { list.add(doc); } matching++; } } return (List<DatabaseDocument<MemoryType>>) (Object) list; } MemoryDocumentIO(); }
MemoryDocumentIO implements DocumentWriter<MemoryType>,
		DocumentReader<MemoryType> { @SuppressWarnings("unchecked") @Override public List<DatabaseDocument<MemoryType>> getDocuments( DatabaseQuery<MemoryType> q, int limit, int skip) { ArrayList<MemoryDocument> list = new ArrayList<MemoryDocument>(); int matching = 0; for (MemoryDocument doc : set.keySet()) { if (list.size() >= limit) break; if (doc.matches((MemoryQuery) q)) { if (matching >= skip) { list.add(doc); } matching++; } } return (List<DatabaseDocument<MemoryType>>) (Object) list; } MemoryDocumentIO(); @Override MemoryDocument getDocument(DatabaseQuery<MemoryType> q); @Override MemoryDocument getDocumentById(DocumentID<MemoryType> id); @Override DatabaseDocument<MemoryType> getDocumentById(DocumentID<MemoryType> id,
			boolean includeInactive); @Override TailableIterator<MemoryType> getInactiveIterator(); @SuppressWarnings("unchecked") @Override List<DatabaseDocument<MemoryType>> getDocuments(
			DatabaseQuery<MemoryType> q, int limit, int skip); @Override List<DatabaseDocument<MemoryType>> getDocuments(
			DatabaseQuery<MemoryType> q, int limit); @Override long getNumberOfDocuments(DatabaseQuery<MemoryType> q); @Override DocumentFile<MemoryType> getDocumentFile(
			DatabaseDocument<MemoryType> d, String fileName); @Override boolean deleteDocumentFile(DatabaseDocument<MemoryType> d,
			String fileName); @Override List<String> getDocumentFileNames(DatabaseDocument<MemoryType> d); @Override long getActiveDatabaseSize(); @Override long getInactiveDatabaseSize(); @Override MemoryDocument getAndTag(DatabaseQuery<MemoryType> query, String ... tag); @Override Collection<DatabaseDocument<MemoryType>> getAndTag(
			DatabaseQuery<MemoryType> query, int n, String ... tag); @Override boolean markTouched(DocumentID<MemoryType> id, String tag); @Override boolean markProcessed(DatabaseDocument<MemoryType> d, String stage); @Override boolean markDiscarded(DatabaseDocument<MemoryType> d, String stage); @Override boolean markFailed(DatabaseDocument<MemoryType> d, String stage); @Override boolean markPending(DatabaseDocument<MemoryType> d, String stage); @Override boolean insert(DatabaseDocument<MemoryType> d); @Override boolean insert(DatabaseDocument<MemoryType> d, List<DocumentFile<MemoryType>> attachments); @Override boolean update(DatabaseDocument<MemoryType> d); @Override void delete(DatabaseDocument<MemoryType> d); @Override void deleteAll(); @Override void write(DocumentFile<MemoryType> df); @Override void prepare(); @Override DocumentID<MemoryType> toDocumentId(Object jsonPrimitive); @Override DocumentID<MemoryType> toDocumentIdFromJson(String json); @Override TailableIterator<MemoryType> getInactiveIterator(
			DatabaseQuery<MemoryType> query); }
MemoryDocumentIO implements DocumentWriter<MemoryType>,
		DocumentReader<MemoryType> { @SuppressWarnings("unchecked") @Override public List<DatabaseDocument<MemoryType>> getDocuments( DatabaseQuery<MemoryType> q, int limit, int skip) { ArrayList<MemoryDocument> list = new ArrayList<MemoryDocument>(); int matching = 0; for (MemoryDocument doc : set.keySet()) { if (list.size() >= limit) break; if (doc.matches((MemoryQuery) q)) { if (matching >= skip) { list.add(doc); } matching++; } } return (List<DatabaseDocument<MemoryType>>) (Object) list; } MemoryDocumentIO(); @Override MemoryDocument getDocument(DatabaseQuery<MemoryType> q); @Override MemoryDocument getDocumentById(DocumentID<MemoryType> id); @Override DatabaseDocument<MemoryType> getDocumentById(DocumentID<MemoryType> id,
			boolean includeInactive); @Override TailableIterator<MemoryType> getInactiveIterator(); @SuppressWarnings("unchecked") @Override List<DatabaseDocument<MemoryType>> getDocuments(
			DatabaseQuery<MemoryType> q, int limit, int skip); @Override List<DatabaseDocument<MemoryType>> getDocuments(
			DatabaseQuery<MemoryType> q, int limit); @Override long getNumberOfDocuments(DatabaseQuery<MemoryType> q); @Override DocumentFile<MemoryType> getDocumentFile(
			DatabaseDocument<MemoryType> d, String fileName); @Override boolean deleteDocumentFile(DatabaseDocument<MemoryType> d,
			String fileName); @Override List<String> getDocumentFileNames(DatabaseDocument<MemoryType> d); @Override long getActiveDatabaseSize(); @Override long getInactiveDatabaseSize(); @Override MemoryDocument getAndTag(DatabaseQuery<MemoryType> query, String ... tag); @Override Collection<DatabaseDocument<MemoryType>> getAndTag(
			DatabaseQuery<MemoryType> query, int n, String ... tag); @Override boolean markTouched(DocumentID<MemoryType> id, String tag); @Override boolean markProcessed(DatabaseDocument<MemoryType> d, String stage); @Override boolean markDiscarded(DatabaseDocument<MemoryType> d, String stage); @Override boolean markFailed(DatabaseDocument<MemoryType> d, String stage); @Override boolean markPending(DatabaseDocument<MemoryType> d, String stage); @Override boolean insert(DatabaseDocument<MemoryType> d); @Override boolean insert(DatabaseDocument<MemoryType> d, List<DocumentFile<MemoryType>> attachments); @Override boolean update(DatabaseDocument<MemoryType> d); @Override void delete(DatabaseDocument<MemoryType> d); @Override void deleteAll(); @Override void write(DocumentFile<MemoryType> df); @Override void prepare(); @Override DocumentID<MemoryType> toDocumentId(Object jsonPrimitive); @Override DocumentID<MemoryType> toDocumentIdFromJson(String json); @Override TailableIterator<MemoryType> getInactiveIterator(
			DatabaseQuery<MemoryType> query); static final int inactiveSize; }