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;
}
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();
}
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();
}
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;
}
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;
}
Aggregations