@Override protected Iterator<HugeEdge> queryEdgesFromBackend(Query query) { if (query.empty()) { // Query all edges, don't cache it return super.queryEdgesFromBackend(query); } Id id = new QueryId(query); @SuppressWarnings("unchecked") List<HugeEdge> edges = (List<HugeEdge>) this.edgesCache.get(id); if (edges == null) { // Iterator can't be cached, caching list instead edges = ImmutableList.copyOf(super.queryEdgesFromBackend(query)); if (edges.size() <= MAX_CACHE_EDGES_PER_QUERY) { this.edgesCache.update(id, edges); } } return edges.iterator(); }
@Watched(prefix = "tx") public Iterator<BackendEntry> query(Query query) { LOG.debug("Transaction query: {}", query); /* * NOTE: it's dangerous if an IdQuery/ConditionQuery is empty * check if the query is empty and its class is not the Query itself */ if (query.empty() && !query.getClass().equals(Query.class)) { throw new BackendException("Query without any id or condition"); } query = this.serializer.writeQuery(query); this.beforeRead(); try { return this.store.query(query); } finally { this.afterRead(); // TODO: not complete the iteration currently } }
@SuppressWarnings("unchecked") @Override public Iterator<BackendEntry> query(Query query) { if (query.empty()) { return this.store.query(query); } QueryId id = new QueryId(query); Object result = this.cache.get(id); if (result != null) { return (Iterator<BackendEntry>) result; } else { Iterator<BackendEntry> rs = this.store.query(query); if (rs.hasNext()) { this.cache.update(id, rs); } return rs; } }
} else if (!q.empty()) {
if (query.empty()) { return newEntryIterator(this.queryAll(session, query), query);
if (query.empty()) { return newEntryIterator(this.queryAll(session, query), query);
@Override protected Iterator<HugeEdge> queryEdgesFromBackend(Query query) { if (query.empty()) { // Query all edges, don't cache it return super.queryEdgesFromBackend(query); } Id id = new QueryId(query); @SuppressWarnings("unchecked") List<HugeEdge> edges = (List<HugeEdge>) this.edgesCache.get(id); if (edges == null) { // Iterator can't be cached, caching list instead edges = ImmutableList.copyOf(super.queryEdgesFromBackend(query)); if (edges.size() <= MAX_CACHE_EDGES_PER_QUERY) { this.edgesCache.update(id, edges); } } return edges.iterator(); }
@Watched(prefix = "tx") public Iterator<BackendEntry> query(Query query) { LOG.debug("Transaction query: {}", query); /* * NOTE: it's dangerous if an IdQuery/ConditionQuery is empty * check if the query is empty and its class is not the Query itself */ if (query.empty() && !query.getClass().equals(Query.class)) { throw new BackendException("Query without any id or condition"); } query = this.serializer.writeQuery(query); this.beforeRead(); try { return this.store.query(query); } finally { this.afterRead(); // TODO: not complete the iteration currently } }
@SuppressWarnings("unchecked") @Override public Iterator<BackendEntry> query(Query query) { if (query.empty()) { return this.store.query(query); } QueryId id = new QueryId(query); Object result = this.cache.get(id); if (result != null) { return (Iterator<BackendEntry>) result; } else { Iterator<BackendEntry> rs = this.store.query(query); if (rs.hasNext()) { this.cache.update(id, rs); } return rs; } }
@Override public Iterator<BackendEntry> query(Query query) { if (!(query instanceof ConditionQuery)) { return super.query(query); } List<Query> queries = new ArrayList<>(); for (ConditionQuery cq: ConditionQueryFlatten.flatten( (ConditionQuery) query)) { Query q = this.optimizeQuery(cq); /* * NOTE: There are two possibilities for this query: * 1.sysprop-query, which would not be empty. * 2.index-query result(ids after optimization), which may be empty. */ if (!q.empty()) { // Return empty if there is no result after index-query queries.add(q); } } ExtendableIterator<BackendEntry> rs = new ExtendableIterator<>(); for (Query q : queries) { rs.extend(super.query(q)); } return rs; }
@Override public Iterator<BackendEntry> query(Session session, Query query) { if (query.limit() == 0 && query.limit() != Query.NO_LIMIT) { LOG.debug("Return empty result(limit=0) for query {}", query); return ImmutableList.<BackendEntry>of().iterator(); } // Query all if (query.empty()) { return newEntryIterator(this.queryAll(session, query), query); } // Query by id if (query.conditions().isEmpty()) { assert !query.ids().isEmpty(); ExtendableIterator<BackendEntry> rs = new ExtendableIterator<>(); for (Id id : query.ids()) { rs.extend(newEntryIterator(this.queryById(session, id), query)); } return rs; } // Query by condition (or condition + id) ConditionQuery cq = (ConditionQuery) query; return newEntryIterator(this.queryByCond(session, cq), query); }