@Test public void scanTest() { Map<String, Map<String, ByteIterator>> keyMap = new HashMap<>(); for (int i = 0; i < 5; i++) { String insertKey = KEY_PREFIX + i; keyMap.put(insertKey, insertRow(insertKey)); } Set<String> fieldSet = new HashSet<>(); fieldSet.add("FIELD0"); fieldSet.add("FIELD1"); int startIndex = 0; int resultRows = 3; Vector<HashMap<String, ByteIterator>> resultVector = new Vector<>(); orientDBClient.scan(CLASS, KEY_PREFIX + startIndex, resultRows, fieldSet, resultVector); assertEquals("Assert the correct number of results rows were returned", resultRows, resultVector.size()); int testIndex = startIndex; for (HashMap<String, ByteIterator> result : resultVector) { assertEquals("Assert that this row has the correct number of fields", fieldSet.size(), result.size()); for (String field : fieldSet) { assertEquals("Assert this field is correct in this row", keyMap.get(KEY_PREFIX + testIndex).get(field).toString(), result.get(field).toString()); } testIndex++; } }
@Override public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) { if (isRemote) { LOG.warn("OrientDB scan operation is not implemented for remote database connections."); return Status.NOT_IMPLEMENTED; } try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); final OIndexCursor entries = dictionary.getIndex().iterateEntriesMajor(startkey, true, true); int currentCount = 0; while (entries.hasNext()) { final ODocument document = entries.next().getRecord(); final HashMap<String, ByteIterator> map = new HashMap<>(); result.add(map); if (fields != null) { for (String field : fields) { map.put(field, new StringByteIterator((String) document.field(field))); } } else { for (String field : document.fieldNames()) { map.put(field, new StringByteIterator((String) document.field(field))); } } currentCount++; if (currentCount >= recordcount) { break; } } return Status.OK; } catch (Exception e) { e.printStackTrace(); } return Status.ERROR; }
OrientDBClient extends DB { @Override public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) { if (isRemote) { LOG.warn("OrientDB scan operation is not implemented for remote database connections."); return Status.NOT_IMPLEMENTED; } try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); final OIndexCursor entries = dictionary.getIndex().iterateEntriesMajor(startkey, true, true); int currentCount = 0; while (entries.hasNext()) { final ODocument document = entries.next().getRecord(); final HashMap<String, ByteIterator> map = new HashMap<>(); result.add(map); if (fields != null) { for (String field : fields) { map.put(field, new StringByteIterator((String) document.field(field))); } } else { for (String field : document.fieldNames()) { map.put(field, new StringByteIterator((String) document.field(field))); } } currentCount++; if (currentCount >= recordcount) { break; } } return Status.OK; } catch (Exception e) { e.printStackTrace(); } return Status.ERROR; } }
OrientDBClient extends DB { @Override public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) { if (isRemote) { LOG.warn("OrientDB scan operation is not implemented for remote database connections."); return Status.NOT_IMPLEMENTED; } try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); final OIndexCursor entries = dictionary.getIndex().iterateEntriesMajor(startkey, true, true); int currentCount = 0; while (entries.hasNext()) { final ODocument document = entries.next().getRecord(); final HashMap<String, ByteIterator> map = new HashMap<>(); result.add(map); if (fields != null) { for (String field : fields) { map.put(field, new StringByteIterator((String) document.field(field))); } } else { for (String field : document.fieldNames()) { map.put(field, new StringByteIterator((String) document.field(field))); } } currentCount++; if (currentCount >= recordcount) { break; } } return Status.OK; } catch (Exception e) { e.printStackTrace(); } return Status.ERROR; }  }
OrientDBClient extends DB { @Override public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) { if (isRemote) { LOG.warn("OrientDB scan operation is not implemented for remote database connections."); return Status.NOT_IMPLEMENTED; } try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); final OIndexCursor entries = dictionary.getIndex().iterateEntriesMajor(startkey, true, true); int currentCount = 0; while (entries.hasNext()) { final ODocument document = entries.next().getRecord(); final HashMap<String, ByteIterator> map = new HashMap<>(); result.add(map); if (fields != null) { for (String field : fields) { map.put(field, new StringByteIterator((String) document.field(field))); } } else { for (String field : document.fieldNames()) { map.put(field, new StringByteIterator((String) document.field(field))); } } currentCount++; if (currentCount >= recordcount) { break; } } return Status.OK; } catch (Exception e) { e.printStackTrace(); } return Status.ERROR; }  void init(); @Override void cleanup(); @Override Status insert(String table, String key, Map<String, ByteIterator> values); @Override Status delete(String table, String key); @Override Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result); @Override Status update(String table, String key, Map<String, ByteIterator> values); @Override Status scan(String table, String startkey, int recordcount, Set<String> fields,
      Vector<HashMap<String, ByteIterator>> result); }
OrientDBClient extends DB { @Override public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) { if (isRemote) { LOG.warn("OrientDB scan operation is not implemented for remote database connections."); return Status.NOT_IMPLEMENTED; } try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); final OIndexCursor entries = dictionary.getIndex().iterateEntriesMajor(startkey, true, true); int currentCount = 0; while (entries.hasNext()) { final ODocument document = entries.next().getRecord(); final HashMap<String, ByteIterator> map = new HashMap<>(); result.add(map); if (fields != null) { for (String field : fields) { map.put(field, new StringByteIterator((String) document.field(field))); } } else { for (String field : document.fieldNames()) { map.put(field, new StringByteIterator((String) document.field(field))); } } currentCount++; if (currentCount >= recordcount) { break; } } return Status.OK; } catch (Exception e) { e.printStackTrace(); } return Status.ERROR; }  void init(); @Override void cleanup(); @Override Status insert(String table, String key, Map<String, ByteIterator> values); @Override Status delete(String table, String key); @Override Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result); @Override Status update(String table, String key, Map<String, ByteIterator> values); @Override Status scan(String table, String startkey, int recordcount, Set<String> fields,
      Vector<HashMap<String, ByteIterator>> result);  }