Search in sources :

Example 6 with InternalVertex

use of com.thinkaurelius.titan.graphdb.internal.InternalVertex in project titan by thinkaurelius.

the class AbstractTypedRelation method it.

@Override
public InternalRelation it() {
    InternalVertex v = getVertex(0);
    if (v == v.it())
        return this;
    InternalRelation next = (InternalRelation) RelationIdentifier.get(v, type, super.getID()).findRelation(tx());
    if (next == null)
        throw new InvalidElementException("Relation has been removed", this);
    return next;
}
Also used : InternalVertex(com.thinkaurelius.titan.graphdb.internal.InternalVertex) InternalRelation(com.thinkaurelius.titan.graphdb.internal.InternalRelation)

Example 7 with InternalVertex

use of com.thinkaurelius.titan.graphdb.internal.InternalVertex in project titan by thinkaurelius.

the class CacheProperty method it.

@Override
public InternalRelation it() {
    InternalRelation it = null;
    InternalVertex startVertex = getVertex(0);
    if (startVertex.hasAddedRelations() && startVertex.hasRemovedRelations()) {
        // Test whether this relation has been replaced
        final long id = super.getID();
        it = Iterables.getOnlyElement(startVertex.getAddedRelations(new Predicate<InternalRelation>() {

            @Override
            public boolean apply(@Nullable InternalRelation internalRelation) {
                return (internalRelation instanceof StandardProperty) && ((StandardProperty) internalRelation).getPreviousID() == id;
            }
        }), null);
    }
    return (it != null) ? it : super.it();
}
Also used : InternalVertex(com.thinkaurelius.titan.graphdb.internal.InternalVertex) InternalRelation(com.thinkaurelius.titan.graphdb.internal.InternalRelation)

Example 8 with InternalVertex

use of com.thinkaurelius.titan.graphdb.internal.InternalVertex in project titan by thinkaurelius.

the class CacheEdge method it.

@Override
public InternalRelation it() {
    InternalRelation it = null;
    InternalVertex startVertex = getVertex(0);
    if (startVertex.hasAddedRelations() && startVertex.hasRemovedRelations()) {
        // Test whether this relation has been replaced
        final long id = super.getID();
        Iterable<InternalRelation> previous = startVertex.getAddedRelations(new Predicate<InternalRelation>() {

            @Override
            public boolean apply(@Nullable InternalRelation internalRelation) {
                return (internalRelation instanceof StandardEdge) && ((StandardEdge) internalRelation).getPreviousID() == id;
            }
        });
        assert Iterables.size(previous) <= 1 || (isLoop() && Iterables.size(previous) == 2);
        it = Iterables.getFirst(previous, null);
    }
    if (it != null)
        return it;
    return super.it();
}
Also used : InternalVertex(com.thinkaurelius.titan.graphdb.internal.InternalVertex) InternalRelation(com.thinkaurelius.titan.graphdb.internal.InternalRelation)

Example 9 with InternalVertex

use of com.thinkaurelius.titan.graphdb.internal.InternalVertex in project titan by thinkaurelius.

the class MultiVertexCentricQueryBuilder method execute.

/* ---------------------------------------------------------------
     * Query Execution
	 * ---------------------------------------------------------------
	 */
/**
     * Constructs the BaseVertexCentricQuery through {@link BasicVertexCentricQueryBuilder#constructQuery(com.thinkaurelius.titan.graphdb.internal.RelationCategory)}.
     * If the query asks for an implicit key, the resulting map is computed and returned directly.
     * If the query is empty, a map that maps each vertex to an empty list is returned.
     * Otherwise, the query is executed for all vertices through the transaction which will effectively
     * pre-load the return result sets into the associated {@link com.thinkaurelius.titan.graphdb.vertices.CacheVertex} or
     * don't do anything at all if the vertex is new (and hence no edges in the storage backend).
     * After that, a map is constructed that maps each vertex to the corresponding VertexCentricQuery and wrapped
     * into a QueryProcessor. Hence, upon iteration the query will be executed like any other VertexCentricQuery
     * with the performance difference that the SliceQueries will have already been preloaded and not further
     * calls to the storage backend are needed.
     *
     * @param returnType
     * @return
     */
protected <Q> Map<TitanVertex, Q> execute(RelationCategory returnType, ResultConstructor<Q> resultConstructor) {
    Preconditions.checkArgument(!vertices.isEmpty(), "Need to add at least one vertex to query");
    Map<TitanVertex, Q> result = new HashMap<TitanVertex, Q>(vertices.size());
    BaseVertexCentricQuery bq = super.constructQuery(returnType);
    profiler.setAnnotation(QueryProfiler.MULTIQUERY_ANNOTATION, true);
    profiler.setAnnotation(QueryProfiler.NUMVERTICES_ANNOTATION, vertices.size());
    if (!bq.isEmpty()) {
        for (BackendQueryHolder<SliceQuery> sq : bq.getQueries()) {
            Set<InternalVertex> adjVertices = Sets.newHashSet(vertices);
            for (InternalVertex v : vertices) {
                if (isPartitionedVertex(v)) {
                    profiler.setAnnotation(QueryProfiler.PARTITIONED_VERTEX_ANNOTATION, true);
                    adjVertices.remove(v);
                    adjVertices.addAll(allRequiredRepresentatives(v));
                }
            }
            //Overwrite with more accurate size accounting for partitioned vertices
            profiler.setAnnotation(QueryProfiler.NUMVERTICES_ANNOTATION, adjVertices.size());
            tx.executeMultiQuery(adjVertices, sq.getBackendQuery(), sq.getProfiler());
        }
        for (InternalVertex v : vertices) {
            result.put(v, resultConstructor.getResult(v, bq));
        }
    } else {
        for (TitanVertex v : vertices) result.put(v, resultConstructor.emptyResult());
    }
    return result;
}
Also used : InternalVertex(com.thinkaurelius.titan.graphdb.internal.InternalVertex) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)

Example 10 with InternalVertex

use of com.thinkaurelius.titan.graphdb.internal.InternalVertex in project titan by thinkaurelius.

the class ModificationDeserializer method parseRelation.

public static InternalRelation parseRelation(TransactionLogHeader.Modification modification, StandardTitanTx 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 : EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) Change(com.thinkaurelius.titan.core.log.Change) InternalRelation(com.thinkaurelius.titan.graphdb.internal.InternalRelation) Entry(com.thinkaurelius.titan.diskstorage.Entry) InternalVertex(com.thinkaurelius.titan.graphdb.internal.InternalVertex) InternalRelationType(com.thinkaurelius.titan.graphdb.internal.InternalRelationType) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Aggregations

InternalVertex (com.thinkaurelius.titan.graphdb.internal.InternalVertex)14 InternalRelation (com.thinkaurelius.titan.graphdb.internal.InternalRelation)9 InternalRelationType (com.thinkaurelius.titan.graphdb.internal.InternalRelationType)3 LongArrayList (com.carrotsearch.hppc.LongArrayList)2 TitanType (com.thinkaurelius.titan.core.TitanType)2 SliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)2 HashMap (java.util.HashMap)2 NonBlockingHashMapLong (org.cliffc.high_scale_lib.NonBlockingHashMapLong)2 AbstractIntObjectMap (cern.colt.map.AbstractIntObjectMap)1 OpenIntObjectHashMap (cern.colt.map.OpenIntObjectHashMap)1 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)1 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)1 Change (com.thinkaurelius.titan.core.log.Change)1 BackendTransaction (com.thinkaurelius.titan.diskstorage.BackendTransaction)1 Entry (com.thinkaurelius.titan.diskstorage.Entry)1 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)1 IndexEntry (com.thinkaurelius.titan.diskstorage.indexing.IndexEntry)1 IndexTransaction (com.thinkaurelius.titan.diskstorage.indexing.IndexTransaction)1 RecordIterator (com.thinkaurelius.titan.diskstorage.util.RecordIterator)1 StaticArrayEntry (com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry)1