Search in sources :

Example 11 with InternalVertex

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

the class CacheVertexProperty 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.longId();
        it = Iterables.getOnlyElement(startVertex.getAddedRelations(new Predicate<InternalRelation>() {

            @Override
            public boolean apply(@Nullable InternalRelation internalRelation) {
                return (internalRelation instanceof StandardVertexProperty) && ((StandardVertexProperty) 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 12 with InternalVertex

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

the class MultiVertexCentricQueryBuilder method relations.

protected Map<TitanVertex, Iterable<? extends TitanRelation>> relations(RelationType returnType) {
    Preconditions.checkArgument(!vertices.isEmpty(), "Need to add at least one vertex to query");
    BaseVertexCentricQuery vq = super.constructQuery(returnType);
    Map<TitanVertex, Iterable<? extends TitanRelation>> result = new HashMap<TitanVertex, Iterable<? extends TitanRelation>>(vertices.size());
    if (!vq.isEmpty()) {
        for (BackendQueryHolder<SliceQuery> sq : vq.getQueries()) {
            tx.executeMultiQuery(vertices, sq.getBackendQuery());
        }
        Condition<TitanRelation> condition = vq.getCondition();
        for (InternalVertex v : vertices) {
            // Add other-vertex and direction related conditions
            And<TitanRelation> newcond = new And<TitanRelation>();
            if (condition instanceof And)
                newcond.addAll((And) condition);
            else
                newcond.add(condition);
            newcond.add(new DirectionCondition<TitanRelation>(v, getDirection()));
            VertexCentricQuery vqsingle = new VertexCentricQuery(v, newcond, vq.getDirection(), vq.getQueries(), vq.getLimit());
            result.put(v, new QueryProcessor<VertexCentricQuery, TitanRelation, SliceQuery>(vqsingle, tx.edgeProcessor));
        }
    } else {
        Iterable<? extends TitanRelation> emptyIter = IterablesUtil.emptyIterable();
        for (TitanVertex v : vertices) result.put(v, emptyIter);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery) And(com.thinkaurelius.titan.graphdb.query.condition.And) InternalVertex(com.thinkaurelius.titan.graphdb.internal.InternalVertex)

Example 13 with InternalVertex

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

the class GuavaVertexCache method get.

@Override
public InternalVertex get(final long id, final Retriever<Long, InternalVertex> retriever) {
    final Long vertexId = id;
    InternalVertex vertex = cache.getIfPresent(vertexId);
    if (vertex == null) {
        InternalVertex newVertex = volatileVertices.get(vertexId);
        if (newVertex == null) {
            newVertex = retriever.get(vertexId);
        }
        assert newVertex != null;
        try {
            vertex = cache.get(vertexId, new NewVertexCallable(newVertex));
        } catch (Exception e) {
            throw new AssertionError("Should not happen: " + e.getMessage());
        }
        assert vertex != null;
    }
    return vertex;
}
Also used : NonBlockingHashMapLong(org.cliffc.high_scale_lib.NonBlockingHashMapLong) InternalVertex(com.thinkaurelius.titan.graphdb.internal.InternalVertex) ExecutionException(java.util.concurrent.ExecutionException)

Example 14 with InternalVertex

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

the class LRUVertexCache method get.

@Override
public InternalVertex get(long id, final Retriever<Long, InternalVertex> retriever) {
    final Long vertexId = id;
    InternalVertex vertex = cache.get(vertexId);
    if (vertex == null) {
        InternalVertex newVertex = volatileVertices.get(vertexId);
        if (newVertex == null) {
            newVertex = retriever.get(vertexId);
        }
        vertex = cache.putIfAbsent(vertexId, newVertex);
        if (vertex == null)
            vertex = newVertex;
    }
    return vertex;
}
Also used : NonBlockingHashMapLong(org.cliffc.high_scale_lib.NonBlockingHashMapLong) InternalVertex(com.thinkaurelius.titan.graphdb.internal.InternalVertex)

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