Search in sources :

Example 1 with VertexCentricQueryBuilder

use of org.janusgraph.graphdb.query.vertex.VertexCentricQueryBuilder in project janusgraph by JanusGraph.

the class RelationIdentifierUtils method findEdgeRelations.

public static Iterable<? extends JanusGraphRelation> findEdgeRelations(JanusGraphVertex v, RelationType type, RelationIdentifier rId, JanusGraphTransaction tx) {
    Direction dir = Direction.OUT;
    JanusGraphVertex other = ((StandardJanusGraphTx) tx).getInternalVertex(rId.getInVertexId());
    if (other == null || other.isRemoved())
        return null;
    if (((StandardJanusGraphTx) tx).isPartitionedVertex(v) && !((StandardJanusGraphTx) tx).isPartitionedVertex(other)) {
        // Swap for likely better performance
        JanusGraphVertex tmp = other;
        other = v;
        v = tmp;
        dir = Direction.IN;
    }
    VertexCentricQueryBuilder query = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types(type).direction(dir).adjacent(other);
    RelationType internalVertex = ((StandardJanusGraphTx) tx).getExistingRelationType(type.longId());
    if (((InternalRelationType) internalVertex).getConsistencyModifier() != ConsistencyModifier.FORK) {
        query.has(ImplicitKey.JANUSGRAPHID.name(), rId.getRelationId());
    }
    return query.edges();
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) RelationType(org.janusgraph.core.RelationType) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) VertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.VertexCentricQueryBuilder) Direction(org.apache.tinkerpop.gremlin.structure.Direction)

Example 2 with VertexCentricQueryBuilder

use of org.janusgraph.graphdb.query.vertex.VertexCentricQueryBuilder in project janusgraph by JanusGraph.

the class IndexSerializer method indexMatches.

private static void indexMatches(JanusGraphVertex vertex, RecordEntry[] current, IndexRecords matches, IndexField[] fields, int pos, boolean onlyLoaded, PropertyKey replaceKey, RecordEntry replaceValue) {
    if (pos >= fields.length) {
        matches.add(current);
        return;
    }
    final PropertyKey key = fields[pos].getFieldKey();
    List<RecordEntry> values;
    if (key.equals(replaceKey)) {
        values = ImmutableList.of(replaceValue);
    } else {
        values = new ArrayList<>();
        Iterable<JanusGraphVertexProperty> props;
        if (onlyLoaded || (!vertex.isNew() && IDManager.VertexIDType.PartitionedVertex.is(vertex.longId()))) {
            // going through transaction so we can query deleted vertices
            final VertexCentricQueryBuilder qb = ((InternalVertex) vertex).tx().query(vertex);
            qb.noPartitionRestriction().type(key);
            if (onlyLoaded)
                qb.queryOnlyLoaded();
            props = qb.properties();
        } else {
            props = vertex.query().keys(key.name()).properties();
        }
        for (final JanusGraphVertexProperty p : props) {
            assert !onlyLoaded || p.isLoaded() || p.isRemoved();
            assert key.dataType().equals(p.value().getClass()) : key + " -> " + p;
            values.add(new RecordEntry(p));
        }
    }
    for (final RecordEntry value : values) {
        current[pos] = value;
        indexMatches(vertex, current, matches, fields, pos + 1, onlyLoaded, replaceKey, replaceValue);
    }
}
Also used : VertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.VertexCentricQueryBuilder) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) PropertyKey(org.janusgraph.core.PropertyKey)

Aggregations

VertexCentricQueryBuilder (org.janusgraph.graphdb.query.vertex.VertexCentricQueryBuilder)2 Direction (org.apache.tinkerpop.gremlin.structure.Direction)1 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)1 JanusGraphVertexProperty (org.janusgraph.core.JanusGraphVertexProperty)1 PropertyKey (org.janusgraph.core.PropertyKey)1 RelationType (org.janusgraph.core.RelationType)1 InternalRelationType (org.janusgraph.graphdb.internal.InternalRelationType)1 StandardJanusGraphTx (org.janusgraph.graphdb.transaction.StandardJanusGraphTx)1