Search in sources :

Example 1 with CacheVertexProperty

use of org.janusgraph.graphdb.relations.CacheVertexProperty in project janusgraph by JanusGraph.

the class ModificationDeserializer method parseRelation.

public static InternalRelation parseRelation(TransactionLogHeader.Modification modification, StandardJanusGraphTx tx) {
    Change state = modification.state;
    assert state.isProper();
    long outVertexId = modification.outVertexId;
    Entry relEntry = modification.relationEntry;
    InternalVertex outVertex = tx.getInternalVertex(outVertexId);
    // Special relation parsing, compare to {@link RelationConstructor}
    RelationCache relCache = tx.getEdgeSerializer().readRelation(relEntry, false, tx);
    assert relCache.direction == Direction.OUT;
    InternalRelationType type = (InternalRelationType) tx.getExistingRelationType(relCache.typeId);
    assert type.getBaseType() == null;
    InternalRelation rel;
    if (type.isPropertyKey()) {
        if (state == Change.REMOVED) {
            rel = new StandardVertexProperty(relCache.relationId, (PropertyKey) type, outVertex, relCache.getValue(), ElementLifeCycle.Removed);
        } else {
            rel = new CacheVertexProperty(relCache.relationId, (PropertyKey) type, outVertex, relCache.getValue(), relEntry);
        }
    } else {
        assert type.isEdgeLabel();
        InternalVertex otherVertex = tx.getInternalVertex(relCache.getOtherVertexId());
        if (state == Change.REMOVED) {
            rel = new StandardEdge(relCache.relationId, (EdgeLabel) type, outVertex, otherVertex, ElementLifeCycle.Removed);
        } else {
            rel = new CacheEdge(relCache.relationId, (EdgeLabel) type, outVertex, otherVertex, relEntry);
        }
    }
    if (state == Change.REMOVED && relCache.hasProperties()) {
        // copy over properties
        for (LongObjectCursor<Object> entry : relCache) {
            rel.setPropertyDirect(tx.getExistingPropertyKey(entry.key), entry.value);
        }
    }
    return rel;
}
Also used : RelationCache(org.janusgraph.graphdb.relations.RelationCache) EdgeLabel(org.janusgraph.core.EdgeLabel) StandardVertexProperty(org.janusgraph.graphdb.relations.StandardVertexProperty) Change(org.janusgraph.core.log.Change) InternalRelation(org.janusgraph.graphdb.internal.InternalRelation) StandardEdge(org.janusgraph.graphdb.relations.StandardEdge) Entry(org.janusgraph.diskstorage.Entry) CacheVertexProperty(org.janusgraph.graphdb.relations.CacheVertexProperty) CacheEdge(org.janusgraph.graphdb.relations.CacheEdge) InternalVertex(org.janusgraph.graphdb.internal.InternalVertex) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) PropertyKey(org.janusgraph.core.PropertyKey)

Aggregations

EdgeLabel (org.janusgraph.core.EdgeLabel)1 PropertyKey (org.janusgraph.core.PropertyKey)1 Change (org.janusgraph.core.log.Change)1 Entry (org.janusgraph.diskstorage.Entry)1 InternalRelation (org.janusgraph.graphdb.internal.InternalRelation)1 InternalRelationType (org.janusgraph.graphdb.internal.InternalRelationType)1 InternalVertex (org.janusgraph.graphdb.internal.InternalVertex)1 CacheEdge (org.janusgraph.graphdb.relations.CacheEdge)1 CacheVertexProperty (org.janusgraph.graphdb.relations.CacheVertexProperty)1 RelationCache (org.janusgraph.graphdb.relations.RelationCache)1 StandardEdge (org.janusgraph.graphdb.relations.StandardEdge)1 StandardVertexProperty (org.janusgraph.graphdb.relations.StandardVertexProperty)1