use of com.tinkerpop.blueprints.Edge in project titan by thinkaurelius.
the class AllEdgesIterator method findNext.
private Edge findNext() {
Edge rel = null;
while (rel == null) {
if (currentEdges.hasNext()) {
rel = currentEdges.next();
if (vertices != null && !vertices.contains(rel.getVertex(Direction.IN)))
rel = null;
} else {
if (vertexIter.hasNext()) {
Vertex nextVertex = vertexIter.next();
currentEdges = nextVertex.getEdges(Direction.OUT).iterator();
} else
break;
}
}
return rel;
}
use of com.tinkerpop.blueprints.Edge in project titan by thinkaurelius.
the class AllEdgesIterator method next.
@Override
public Edge next() {
if (next == null)
throw new NoSuchElementException();
Edge current = next;
next = findNext();
return current;
}
use of com.tinkerpop.blueprints.Edge in project titan by thinkaurelius.
the class TitanKeyVertex method getIndexList.
private List<IndexDefinition> getIndexList(Class<? extends Element> type) {
Preconditions.checkArgument(type == Vertex.class || type == Edge.class, "Expected Vertex or Edge class as argument");
List<IndexDefinition> result = type == Vertex.class ? vertexIndexes : edgeIndexes;
if (result == null) {
// Build it
ImmutableList.Builder b = new ImmutableList.Builder();
for (IndexDefinition it : getIndexes()) if (type.isAssignableFrom(it.getElementType()))
b.add(it);
result = b.build();
if (type == Vertex.class)
vertexIndexes = result;
else if (type == Edge.class)
edgeIndexes = result;
}
return result;
}
use of com.tinkerpop.blueprints.Edge in project titan by thinkaurelius.
the class TitanEventualGraphTest method testTimestampSetting.
@Test
public void testTimestampSetting() {
// Transaction 1: Init graph with two vertices, having set "name" and "age" properties
TitanTransaction tx1 = graph.buildTransaction().setTimestamp(100).start();
String name = "name";
String age = "age";
String address = "address";
Vertex v1 = tx1.addVertex();
Vertex v2 = tx1.addVertex();
v1.setProperty(name, "a");
v2.setProperty(age, "14");
v2.setProperty(name, "b");
v2.setProperty(age, "42");
tx1.commit();
// Fetch vertex ids
Object id1 = v1.getId();
Object id2 = v2.getId();
// Transaction 2: Remove "name" property from v1, set "address" property; create
// an edge v2 -> v1
TitanTransaction tx2 = graph.buildTransaction().setTimestamp(1000).start();
v1 = tx2.getVertex(id1);
v2 = tx2.getVertex(id2);
v1.removeProperty(name);
v1.setProperty(address, "xyz");
Edge edge = tx2.addEdge(1, v2, v1, "parent");
tx2.commit();
Object edgeId = edge.getId();
Vertex afterTx2 = graph.getVertex(id1);
// Verify that "name" property is gone
assertFalse(afterTx2.getPropertyKeys().contains(name));
// Verify that "address" property is set
assertEquals("xyz", afterTx2.getProperty(address));
// Verify that the edge is properly registered with the endpoint vertex
assertEquals(1, Iterables.size(afterTx2.getEdges(Direction.IN, "parent")));
// Verify that edge is registered under the id
assertNotNull(graph.getEdge(edgeId));
graph.commit();
// Transaction 3: Remove "address" property from v1 with earlier timestamp than
// when the value was set
TitanTransaction tx3 = graph.buildTransaction().setTimestamp(200).start();
v1 = tx3.getVertex(id1);
v1.removeProperty(address);
tx3.commit();
Vertex afterTx3 = graph.getVertex(id1);
graph.commit();
// Verify that "address" is still set
assertEquals("xyz", afterTx3.getProperty(address));
// Transaction 4: Modify "age" property on v2, remove edge between v2 and v1
TitanTransaction tx4 = graph.buildTransaction().setTimestamp(2000).start();
v2 = tx4.getVertex(id2);
v2.setProperty(age, "15");
tx4.removeEdge(tx4.getEdge(edgeId));
tx4.commit();
Vertex afterTx4 = graph.getVertex(id2);
// Verify that "age" property is modified
assertEquals("15", afterTx4.getProperty(age));
// Verify that edge is no longer registered with the endpoint vertex
assertEquals(0, Iterables.size(afterTx4.getEdges(Direction.OUT, "parent")));
// Verify that edge entry disappeared from id registry
assertNull(graph.getEdge(edgeId));
// Transaction 5: Modify "age" property on v2 with earlier timestamp
TitanTransaction tx5 = graph.buildTransaction().setTimestamp(1500).start();
v2 = tx5.getVertex(id2);
v2.setProperty(age, "16");
tx5.commit();
Vertex afterTx5 = graph.getVertex(id2);
// Verify that the property value is unchanged
assertEquals("15", afterTx5.getProperty(age));
}
use of com.tinkerpop.blueprints.Edge in project titan by thinkaurelius.
the class TitanGraphTest method testIndexRetrieval.
@Test
public void testIndexRetrieval() {
TitanKey id = tx.makeKey("uid").single().unique().indexed(Vertex.class).indexed(Edge.class).dataType(Integer.class).make();
TitanKey name = tx.makeKey("name").single().indexed(Vertex.class).indexed(Edge.class).dataType(String.class).make();
TitanLabel connect = tx.makeLabel("connect").signature(id, name).make();
int noNodes = 100;
int div = 10;
int mod = noNodes / div;
for (int i = 0; i < noNodes; i++) {
TitanVertex n = tx.addVertex();
n.addProperty(id, i);
n.addProperty(name, "Name" + (i % mod));
TitanVertex other = tx.getVertex(id, Math.max(0, i - 1));
Preconditions.checkNotNull(other);
TitanEdge e = n.addEdge(connect, other);
e.setProperty(id, i);
e.setProperty(name, "Edge" + (i % mod));
}
clopen();
for (int j = 0; j < mod; j++) {
Iterable<Vertex> nodes = tx.getVertices("name", "Name" + j);
assertEquals(div, Iterables.size(nodes));
for (Vertex n : nodes) {
int nid = ((Number) n.getProperty("uid")).intValue();
assertEquals(j, nid % mod);
}
Iterable<Edge> edges = tx.getEdges("name", "Edge" + j);
assertEquals(div, Iterables.size(edges));
for (Edge e : edges) {
int nid = ((Number) e.getProperty("uid")).intValue();
assertEquals(j, nid % mod);
}
}
clopen();
for (int i = 0; i < noNodes; i++) {
assertEquals(Iterables.getOnlyElement(tx.getVertices("uid", i)).getProperty("name").toString().substring(4), String.valueOf(i % mod));
}
for (int i = 0; i < noNodes; i++) {
assertEquals(Iterables.getOnlyElement(tx.getEdges("uid", i)).getProperty("name").toString().substring(4), String.valueOf(i % mod));
}
}
Aggregations