Java Code Examples for com.tinkerpop.blueprints.Edge#getVertex()

The following examples show how to use com.tinkerpop.blueprints.Edge#getVertex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DotWriter.java    From bjoern with GNU General Public License v3.0 6 votes vote down vote up
private void writeEdge(Edge edge) throws IOException
{
	Vertex tail = edge.getVertex(Direction.OUT);
	Vertex head = edge.getVertex(Direction.IN);
	writer.write(id(tail));
	writer.write(DotTokens.EDGE_OP);
	writer.write(id(head));
	writer.write(" [ ");
	writer.write("label=\"" + edge.getLabel() + "\" ");
	for (String key : edge.getPropertyKeys())
	{
		String value = edge.getProperty(key).toString();
		value = escape(value);
		writer.write(key + "=\"" + value + "\" ");
	}
	writer.write("];");
	writer.write(DotTokens.NEWLINE);
}
 
Example 2
Source File: DElementStore.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
@Override
public void removeEdge(final Edge edge) {
	if (edge instanceof DEdge) {
		if (org.openntf.domino.ViewEntry.class.equals(((DEdge) edge).getDelegateType())) {
			throw new UnsupportedOperationException("ViewEntry edges cannot be removed.");
		}
	}
	startTransaction(edge);
	Vertex in = edge.getVertex(Direction.IN);
	if (in != null) {
		((DVertex) in).removeEdge(edge);
	}
	Vertex out = edge.getVertex(Direction.OUT);
	if (out != null) {
		((DVertex) out).removeEdge(edge);
	}
	removeCache(edge);
	((DEdge) edge)._remove();
}
 
Example 3
Source File: TeacherStudentTraversal.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
private void benchmarkTeacherThroughSectionBlueprint() {
    logger.log(Level.INFO, "Starting...");
    StopWatch bigWatch = new StopWatch();
    for (int i = 0; i < ITERATIONS; ++i) {
        StopWatch subWatch = new StopWatch();
        for (Vertex teacher : graph.getVertices("mongoid", "2012wl-f126bd7d-cfba-11e1-a172-024224a39f1b")) {
            for(Edge  e : teacher.getEdges(Direction.IN, "teacherSection")) {
                for (Edge ss : e.getVertex(Direction.OUT).getEdges(Direction.OUT, "studentSection")) {
                    ss.getVertex(Direction.IN);
                }
            }
        }
        subWatch.stop();
        times.add(subWatch.getEndTime());
    }
    bigWatch.stop();
    logger.log(Level.INFO, "Total {0} \t Avg {1} ms", new String[] { bigWatch.inSeconds(), "" + averageTime() });
    
}
 
Example 4
Source File: DElementStore.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
@Override
public void removeEdge(final Edge edge, final Vertex removingVertex) {
	if (edge instanceof DEdge) {
		if (org.openntf.domino.ViewEntry.class.equals(((DEdge) edge).getDelegateType())) {
			throw new UnsupportedOperationException("ViewEntry edges cannot be removed.");
		}
	}
	startTransaction(edge);
	Vertex in = edge.getVertex(Direction.IN);
	if (!in.equals(removingVertex)) {
		((DVertex) in).removeEdge(edge);
		removeCache(in);
	}
	Vertex out = edge.getVertex(Direction.OUT);
	if (!out.equals(removingVertex)) {
		((DVertex) out).removeEdge(edge);
		removeCache(out);
	}
	removeCache(edge);
	((DEdge) edge)._remove();
}
 
Example 5
Source File: DataDependencePlugin.java    From bjoern with GNU General Public License v3.0 6 votes vote down vote up
public static Set<ReachingDefinitionAnalyser.Definition> killedDefinitions(
		final Vertex vertex) {
	Set<ReachingDefinitionAnalyser.Definition> killSet = new HashSet<>();
	GremlinPipeline<Vertex, Edge> pipe = new GremlinPipeline<>();
	pipe.start(vertex)
	    .out("WRITE")
	    .out("BELONGS_TO")
	    .in("BELONGS_TO")
	    .inE("WRITE");
	for (Edge writeEdge : pipe) {
		Vertex genVertex = writeEdge.getVertex(Direction.OUT);
		Vertex aloc = writeEdge.getVertex(Direction.IN);
		GremlinPipeline<Vertex, Object> pipe2 = new
				GremlinPipeline<>();
		pipe2.start(aloc)
		     .out("BELONGS_TO")
		     .in("BELONGS_TO")
		     .property("name");
		for (Object identifier : pipe2) {
			killSet.add(new ReachingDefinitionAnalyser.Definition(
					genVertex, identifier));
		}
	}
	return killSet;
}
 
Example 6
Source File: TagRelation.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<RelationSet> traverse(VertexWrapper vWrapper) {
    Vertex v = vWrapper.getVertex();
    Collection<VertexWrapper> vertices = new ArrayList<>();
    for (Edge e : v.getEdges(Direction.OUT)) {
        if (e.getLabel().startsWith(v.<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY))) {
            VertexWrapper trait = new TermVertexWrapper(e.getVertex(Direction.IN));
            if (trait.getPropertyKeys().contains("available_as_tag") && ! isDeleted(trait.getVertex())) {
                vertices.add(trait);
            }
        }
    }
    return Collections.singletonList(new RelationSet("tags", vertices));
}
 
Example 7
Source File: TagRelation.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public Pipe asPipe() {
    return new FilterFunctionPipe<>(new PipeFunction<Edge, Boolean>() {
        @Override
        public Boolean compute(Edge edge) {
            String name = edge.getVertex(Direction.OUT).getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY);
            if (edge.getLabel().startsWith(name)) {
                VertexWrapper v = new TermVertexWrapper(edge.getVertex(Direction.IN));
                return v.getPropertyKeys().contains("available_as_tag") && ! isDeleted(v.getVertex());
            } else {
                return false;
            }
        }
    });
}
 
Example 8
Source File: GenericRelation.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<RelationSet> traverse(VertexWrapper vWrapper) {
    Collection<RelationSet> relations = new ArrayList<>();
    Vertex v = vWrapper.getVertex();
    String vertexType = v.getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY);
    Map<String, Collection<VertexWrapper>> vertexMap = new HashMap<>();
    for (Edge e : v.getEdges(Direction.OUT)) {
        String edgeLabel = e.getLabel();
        String edgePrefix = String.format("%s%s.", Constants.INTERNAL_PROPERTY_KEY_PREFIX, vertexType);
        if (edgeLabel.startsWith(edgePrefix)) {
            Vertex adjacentVertex = e.getVertex(Direction.IN);
            if (! isDeleted(adjacentVertex)) {
                VertexWrapper relationVertex = new VertexWrapper(adjacentVertex, resourceDefinition);
                String relationName = edgeLabel.substring(edgePrefix.length());
                Collection<VertexWrapper> vertices = vertexMap.get(relationName);
                if (vertices == null) {
                    vertices = new ArrayList<>();
                    vertexMap.put(relationName, vertices);
                }
                vertices.add(relationVertex);
            }
        }
    }
    for (Map.Entry<String, Collection<VertexWrapper>> entry : vertexMap.entrySet()) {
        relations.add(new RelationSet(entry.getKey(), entry.getValue()));
    }
    return relations;
}
 
Example 9
Source File: DEdgeList.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public Edge findEdge(final Vertex toVertex) {
	Edge result = null;
	Object toId = toVertex.getId();
	Object fromId = sourceVertex_.getId();
	if (this.size() > 0) {
		for (Edge edge : this) {
			if (edge instanceof DEdge) {
				DEdge dedge = (DEdge) edge;
				if (toId.equals(dedge.getOtherVertexId(sourceVertex_))) {
					result = dedge;
					break;
				}
			} else {
				Vertex inVertex = edge.getVertex(Direction.IN);
				if (fromId.equals(inVertex.getId())) {
					if (toId.equals(edge.getVertex(Direction.OUT))) {
						result = edge;
						break;
					}
				} else if (toId.equals(inVertex.getId())) {
					result = edge;
					break;
				}
			}
		}
	} else {
		//			System.out.println("DEBUG: No edges defined in EdgeList");
	}
	return result;
}
 
Example 10
Source File: AccumuloBulkIngesterTest.java    From AccumuloGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testBulkIngester() throws Exception {
  AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("propertyBuilder").setClear(true);

  AccumuloBulkIngester ingester = new AccumuloBulkIngester(cfg);

  for (String t : cfg.getTableNames()) {
    assertTrue(cfg.getConnector().tableOperations().exists(t));
  }

  ingester.addVertex("A").finish();
  ingester.addVertex("B").add("P1", "V1").add("P2", "2").finish();
  ingester.addEdge("A", "B", "edge").add("P3", "V3").finish();
  ingester.shutdown(true);

  AccumuloGraph graph = new AccumuloGraph(cfg.clone().setClear(false));
  Vertex v1 = graph.getVertex("A");
  assertNotNull(v1);

  Iterator<Edge> it = v1.getEdges(Direction.OUT).iterator();
  assertTrue(it.hasNext());

  Edge e = it.next();
  assertEquals("edge", e.getLabel());

  Vertex v2 = e.getVertex(Direction.IN);
  assertEquals("B", v2.getId());
  assertEquals("V1", v2.getProperty("P1"));
  assertEquals("2", v2.getProperty("P2"));

  graph.shutdown();
}
 
Example 11
Source File: HistoricVersionedGraph.java    From antiquity with GNU General Public License v3.0 5 votes vote down vote up
public HistoricVersionedVertex<V> getMatchedHistoricVersion(HistoricVersionedVertex later, V version) {
    Range<V> verRange = utils.getVersionRange(later);

    log.trace("Finding vertex[{}] in revision history for version [{}].", later, version);
    log.trace("Is vertex [{}] with range [{}] contains version [{}]?", later, verRange, version);

    if (!verRange.contains(version)) {
        Iterable<Edge> prevVerEdges = (later.getBaseElement()).getEdges(Direction.OUT, VEProps.PREV_VERSION_LABEL);

        if (!prevVerEdges.iterator().hasNext()) {
            // throw ExceptionFactory.notFoundException(String.format(
            // "Cannot find vertex %s in revision history for version [%s].",
            // later, version));
            log.info("Cannot find vertex %s in revision history for version [%s].", later, version);
            return null;
        }

        Edge rawEdge = prevVerEdges.iterator().next();
        Vertex rawVertex = rawEdge.getVertex(Direction.IN);
        HistoricVersionedVertex<V> nextLater =
                new HistoricVersionedVertex<V>(rawVertex, this, Range.range(version, version));
        return getMatchedHistoricVersion((HistoricVersionedVertex<V>) nextLater, version);
    }

    log.debug("Found vertex[{}] in revision history for version [{}].", later, version);
    return later;
}
 
Example 12
Source File: DominoGraph.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public void removeEdge(final Edge edge) {
	startTransaction(edge);
	Vertex in = edge.getVertex(Direction.IN);
	if (in != null) {
		((DominoVertex) in).removeEdge(edge);
	}
	Vertex out = edge.getVertex(Direction.OUT);
	if (out != null) {
		((DominoVertex) out).removeEdge(edge);
	}
	removeCache(edge);
	((DominoEdge) edge)._remove();
}
 
Example 13
Source File: TraitRelation.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<RelationSet> traverse(VertexWrapper vWrapper) {
    Vertex v = vWrapper.getVertex();
    Collection<VertexWrapper> vertices = new ArrayList<>();
    for (Edge e : v.getEdges(Direction.OUT)) {
        if (e.getLabel().startsWith(v.<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY))) {
            VertexWrapper trait = new TermVertexWrapper(e.getVertex(Direction.IN));
            if (! trait.getPropertyKeys().contains("available_as_tag") && ! isDeleted(trait.getVertex())) {
                vertices.add(trait);
            }
        }
    }
    return Collections.singletonList(new RelationSet("traits", vertices));
}
 
Example 14
Source File: DEdgeEntryList.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public Edge findEdge(final Vertex toVertex) {
	Edge result = null;
	Object toId = toVertex.getId();
	Object fromId = source_.getId();
	if (this.size() > 0) {
		for (Edge edge : this) {
			if (edge instanceof DEdge) {
				DEdge dedge = (DEdge) edge;
				if (toId.equals(dedge.getOtherVertexId(source_))) {
					result = dedge;
					break;
				}
			} else {
				Vertex inVertex = edge.getVertex(Direction.IN);
				if (fromId.equals(inVertex.getId())) {
					if (toId.equals(edge.getVertex(Direction.OUT))) {
						result = edge;
						break;
					}
				} else if (toId.equals(inVertex.getId())) {
					result = edge;
					break;
				}
			}
		}
	} else {
		//			System.out.println("DEBUG: No edges defined in EdgeList");
	}
	return result;
}
 
Example 15
Source File: VerticesFromEdgesIterable.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public Iterator<Vertex> iterator() {
    return new Iterator<Vertex>() {
        final Iterator<Edge> itty = iterable.iterator();

        public void remove() {
            this.itty.remove();
        }

        public boolean hasNext() {
            return this.itty.hasNext();
        }

        public Vertex next() {
            if (direction.equals(Direction.OUT)) {
                return this.itty.next().getVertex(Direction.IN);
            } else if (direction.equals(Direction.IN)) {
                return this.itty.next().getVertex(Direction.OUT);
            } else {
                final Edge edge = this.itty.next();
                if (edge.getVertex(Direction.IN).equals(vertex))
                    return edge.getVertex(Direction.OUT);
                else
                    return edge.getVertex(Direction.IN);
            }
        }
    };
}
 
Example 16
Source File: EdgeHelper.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public static Vertex getOther(final Edge edge, final Vertex vertex) {
    final Vertex temp = edge.getVertex(Direction.IN);
    if (temp.equals(vertex))
        return edge.getVertex(Direction.OUT);
    else
        return temp;
}
 
Example 17
Source File: AbstractEdgeHelper.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public Vertex getOtherVertex(final Edge edge, final Vertex vertex) {
	if (edge instanceof IDominoEdge) {
		return ((IDominoEdge) edge).getOtherVertex(vertex);
	} else {
		if (vertex.getId().equals(edge.getVertex(Direction.IN).getId())) {
			return edge.getVertex(Direction.OUT);
		} else {
			return edge.getVertex(Direction.IN);
		}
	}
}
 
Example 18
Source File: OEdgeTransformerTest.java    From orientdb-etl with Apache License 2.0 4 votes vote down vote up
@Test
public void testEdgeWithProperties() {
  process("{source: { content: { value: 'id,name,surname,friendSince,friendId,friendName,friendSurname\n0,Jay,Miner,1996,1,Luca,Garulli' } }, extractor : { row: {} },"
      + " transformers: [{csv: {}}, {vertex: {class:'V1'}}, "
      + "{edge:{unresolvedLinkAction:'CREATE',class:'Friend',joinFieldName:'friendId',lookup:'V2.fid',targetVertexFields:{name:'${input.friendName}',surname:'${input.friendSurname}'},edgeFields:{since:'${input.friendSince}'}}},"
      + "{field:{fieldNames:['friendSince','friendId','friendName','friendSurname'],operation:'remove'}}"
      + "], loader: { orientdb: { dbURL: 'memory:ETLBaseTest', dbType:'graph', useLightweightEdges:false } } }");

  assertEquals(1, graph.countVertices("V1"));
  assertEquals(2, graph.countVertices("V2"));
  assertEquals(1, graph.countEdges("Friend"));

  final Iterator<Vertex> v = graph.getVerticesOfClass("V2").iterator();
  assertTrue(v.hasNext());
  assertNotNull(v.next());
  assertTrue(v.hasNext());
  final Vertex v1 = v.next();
  assertNotNull(v1);

  final Set<String> v1Props = v1.getPropertyKeys();

  assertEquals(3, v1Props.size());
  assertEquals(v1.getProperty("name"), "Luca");
  assertEquals(v1.getProperty("surname"), "Garulli");
  assertEquals(v1.getProperty("fid"), 1);

  final Iterator<Edge> edge = v1.getEdges(Direction.IN).iterator();
  assertTrue(edge.hasNext());

  final Edge e = edge.next();
  assertNotNull(e);
  final Set<String> eProps = e.getPropertyKeys();
  assertEquals(1, eProps.size());
  assertEquals(e.getProperty("since"), 1996);

  final Vertex v0 = e.getVertex(Direction.OUT);
  assertNotNull(v0);

  final Set<String> v0Props = v0.getPropertyKeys();

  assertEquals(3, v0Props.size());
  assertEquals(v0.getProperty("name"), "Jay");
  assertEquals(v0.getProperty("surname"), "Miner");
  assertEquals(v0.getProperty("id"), 0);
}
 
Example 19
Source File: DFastEdgeList.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
@Override
public Edge findEdge(final Vertex toVertex) {
	Edge result = null;
	Object toId = toVertex.getId();
	Object fromId = sourceVertex_.getId();
	if (isUnique() && !isEmpty()) {
		if (toId instanceof NoteCoordinate && fromId instanceof NoteCoordinate) {
			String toString = ((NoteCoordinate) toId).toString();
			String fromString = ((NoteCoordinate) fromId).toString();
			String testString1 = DominoUtils.toUnid(toString + getLabel() + fromString);
			String testString2 = DominoUtils.toUnid(toString + getLabel() + fromString);
			NoteCoordinate nc1 = NoteCoordinate.Utils.getNoteCoordinate(storeid_, testString1);
			NoteCoordinate nc2 = NoteCoordinate.Utils.getNoteCoordinate(storeid_, testString2);
			if (contains(nc1)) {
				result = parentGraph_.getEdge(nc1);
			} else if (contains(nc2)) {
				result = parentGraph_.getEdge(nc2);
			}
		} else {
			//NTF then we go back to the old way...
		}
	}
	if (result == null && this.size() > 0 && !isUnique()) {
		for (Edge edge : this) {
			if (edge instanceof DEdge) {
				DEdge dedge = (DEdge) edge;
				if (toId.equals(dedge.getOtherVertexId(sourceVertex_))) {
					result = dedge;
					break;
				}
			} else {
				if (edge != null) {
					Vertex inVertex = edge.getVertex(Direction.IN);
					if (fromId.equals(inVertex.getId())) {
						if (toId.equals(edge.getVertex(Direction.OUT))) {
							result = edge;
							break;
						}
					} else if (toId.equals(inVertex.getId())) {
						result = edge;
						break;
					}
				}
			}
		}
	} else {
		//			System.out.println("DEBUG: No edges defined in EdgeList");
	}
	return result;
}
 
Example 20
Source File: TitanGraphDatabase.java    From graphdb-benchmarks with Apache License 2.0 4 votes vote down vote up
@Override
public Vertex getSrcVertexFromEdge(Edge edge)
{
    return edge.getVertex(Direction.IN);
}