res.forEachRemaining(x -> copy.add(x)); res.close();
@Override public OIndexKeyCursor keyCursor() { final OResultSet result = getDatabase().indexQuery(getName(), String.format(QUERY_KEYS, name)); final OInternalResultSet copy = new OInternalResultSet();//TODO a raw array instead...? result.forEachRemaining(x -> copy.add(x)); result.close(); return new OIndexKeyCursor() { @Override public Object next(int prefetchSize) { if (!copy.hasNext()) return null; final OResult value = copy.next(); return value.getProperty("key"); } }; }
@Override public OIndexCursor descCursor() { final OResultSet result = getDatabase().indexQuery(getName(), String.format(QUERY_ENTRIES_DESC, name)); final OInternalResultSet copy = new OInternalResultSet();//TODO a raw array instead...? result.forEachRemaining(x -> copy.add(x)); result.close(); return new OIndexAbstractCursor() { @Override public Map.Entry<Object, OIdentifiable> nextEntry() { if (!copy.hasNext()) return null; final OResult value = copy.next(); return new Map.Entry<Object, OIdentifiable>() { @Override public Object getKey() { return value.getProperty("key"); } @Override public OIdentifiable getValue() { return value.getProperty("rid"); } @Override public OIdentifiable setValue(OIdentifiable value) { throw new UnsupportedOperationException("setValue"); } }; } }; }
@Override public OIndexCursor cursor() { OResultSet result = getDatabase().indexQuery(getName(), String.format(QUERY_ENTRIES, name)); final OInternalResultSet copy = new OInternalResultSet();//TODO a raw array instead...? result.forEachRemaining(x -> copy.add(x)); result.close(); return new OIndexAbstractCursor() { @Override public Map.Entry<Object, OIdentifiable> nextEntry() { if (!copy.hasNext()) return null; final OResult value = copy.next(); return new Map.Entry<Object, OIdentifiable>() { @Override public Object getKey() { return value.getProperty("key"); } @Override public OIdentifiable getValue() { return value.getProperty("rid"); } @Override public OIdentifiable setValue(OIdentifiable value) { throw new UnsupportedOperationException("setValue"); } }; } }; }
@Override public OResultSet command(String query, Map args) { checkOpenness(); checkIfActive(); OStatement statement = OSQLEngine.parse(query, this); OResultSet original = statement.execute(this, args); OLocalResultSetLifecycleDecorator result; if (!statement.isIdempotent()) { //fetch all, close and detach OInternalResultSet prefetched = new OInternalResultSet(); original.forEachRemaining(x -> prefetched.add(x)); original.close(); result = new OLocalResultSetLifecycleDecorator(prefetched); } else { //stream, keep open and attach to the current DB result = new OLocalResultSetLifecycleDecorator(original); this.queryStarted(result.getQueryId(), result); result.addLifecycleListener(this); } return result; }
@Override public OResultSet command(String query, Object[] args) { checkOpenness(); checkIfActive(); OStatement statement = OSQLEngine.parse(query, this); OResultSet original = statement.execute(this, args); OLocalResultSetLifecycleDecorator result; if (!statement.isIdempotent()) { //fetch all, close and detach OInternalResultSet prefetched = new OInternalResultSet(); original.forEachRemaining(x -> prefetched.add(x)); original.close(); result = new OLocalResultSetLifecycleDecorator(prefetched); } else { //stream, keep open and attach to the current DB result = new OLocalResultSetLifecycleDecorator(original); this.queryStarted(result.getQueryId(), result); result.addLifecycleListener(this); } return result; }