查询操作
之前已经遇到过很多查询操作
mgmt.containsVertexLabel(vType.toString())
transaction.containsVertexLabel(name);
return getSchemaVertex(JanusGraphSchemaCategory.VERTEXLABEL.getSchemaName(name))!=null;
1. JanusGraphSchemaCategory.VERTEXLABEL.getSchemaName(name) // 这一步就是在 name 前面加上标识,例如 vl rt
2. JanusGraphSchemaVertex getSchemaVertex(String schemaName)
graph.getSchemaCache().getSchemaId(schemaName)
1. getSchemaCache
2. StandardSchemaCache.getSchemaId
id = retriever.retrieveSchemaByName(schemaName); // 这个 retriever 是 StandardJanusGraph 中的变量 typeCacheRetrieval ,
typeCacheRetrieval.retrieveSchemaByName
StandardJanusGraph.this.newTransaction
QueryUtil.getVertices(consistentTx, BaseKey.SchemaName, typeName)
return v!=null?v.longId():null;
iterator
return new ResultSetIterator(getUnfoldedIterator(),(query.hasLimit()) ? query.getLimit() : Query.NO_LIMIT);
1. QueryProcessor (org.janusgraph.graphdb.query).getUnfoldedIterator:107,
Iterator<R> subiter = new LimitAdjustingIterator(subq);
2. this.next = nextInternal();
hasNext:68, LimitAdjustingIterator (org.janusgraph.graphdb.query)
getNewIterator:209, QueryProcessor$LimitAdjustingIterator (org.janusgraph.graphdb.query)
execute:1150, StandardJanusGraphTx$elementProcessorImpl (org.janusgraph.graphdb.transaction)
new SubqueryIterator
indexCache.getIfPresent(subQuery); // 这里的 schema 应该都是在启动的时候 cache 到了内存中,所以直接得到了,如果是 数据,应该要查询
其实查询操作并不复杂,这是有很多层的嵌套,导致我们看起来很麻烦而已,前面我们已经大概介绍了: 首先是 AbstractIterator 和 Iterators 类,然后是 ResultSetIterator LimitAdjustingIterator SubqueryIterator ,然后还有一个 Stream 类。
我们一层一层进行查看:
Query
继承体系:
Query (org.janusgraph.graphdb.query)
ElementQuery (org.janusgraph.graphdb.query)
GraphCentricQuery (org.janusgraph.graphdb.query.graph)
VertexCentricQuery (org.janusgraph.graphdb.query.vertex)
BaseQuery (org.janusgraph.graphdb.query)
MultiKeySliceQuery (org.janusgraph.graphdb.query.graph)
JointIndexQuery (org.janusgraph.graphdb.query.graph)
RawQuery (org.janusgraph.diskstorage.indexing)
BaseVertexCentricQuery (org.janusgraph.graphdb.query.vertex)
VertexCentricQuery (org.janusgraph.graphdb.query.vertex)
SliceQuery (org.janusgraph.diskstorage.keycolumnvalue)
KeyRangeQuery (org.janusgraph.diskstorage.keycolumnvalue)
KeySliceQuery (org.janusgraph.diskstorage.keycolumnvalue)
KVQuery (org.janusgraph.diskstorage.keycolumnvalue.keyvalue)
IndexQuery (org.janusgraph.diskstorage.indexing)
IndexQueryBuilder (org.janusgraph.graphdb.query