use of com.tinkerpop.blueprints.IndexableGraph in project blueprints by tinkerpop.
the class IndexableGraphHelperTest method testAddUniqueVertex.
public void testAddUniqueVertex() {
IndexableGraph graph = new TinkerGraph();
Vertex marko = graph.addVertex(0);
marko.setProperty("name", "marko");
Index<Vertex> index = graph.createIndex("txIdx", Vertex.class);
index.put("name", "marko", marko);
Vertex vertex = IndexableGraphHelper.addUniqueVertex(graph, null, index, "name", "marko");
assertEquals(vertex.getProperty("name"), "marko");
assertEquals(vertex, graph.getVertex(0));
assertEquals(count(graph.getVertices()), 1);
assertEquals(count(graph.getEdges()), 0);
vertex = IndexableGraphHelper.addUniqueVertex(graph, null, index, "name", "darrick");
assertEquals(vertex.getProperty("name"), "darrick");
assertEquals(count(graph.getVertices()), 2);
assertEquals(vertex.getId(), "1");
}
use of com.tinkerpop.blueprints.IndexableGraph in project blueprints by tinkerpop.
the class ReadOnlyGraphTest method testReadOnlyKeyIndices.
public void testReadOnlyKeyIndices() {
KeyIndexableGraph graph = new ReadOnlyKeyIndexableGraph<TinkerGraph>(TinkerGraphFactory.createTinkerGraph());
((KeyIndexableGraph) ((WrapperGraph<IndexableGraph>) graph).getBaseGraph()).createKeyIndex("blah", Vertex.class);
assertTrue(graph.getIndexedKeys(Vertex.class) instanceof Set);
assertEquals(graph.getIndexedKeys(Vertex.class).size(), 1);
assertTrue(graph.getIndexedKeys(Vertex.class).contains("blah"));
try {
graph.createKeyIndex("whatever", Vertex.class);
assertTrue(false);
} catch (UnsupportedOperationException e) {
assertTrue(true);
}
try {
graph.dropKeyIndex("blah", Vertex.class);
assertTrue(false);
} catch (UnsupportedOperationException e) {
assertTrue(true);
}
}
use of com.tinkerpop.blueprints.IndexableGraph in project blueprints by tinkerpop.
the class Neo4jBatchGraphTest method testIndexParameters.
public void testIndexParameters() throws Exception {
final String directory = this.getWorkingDirectory();
final Neo4jBatchGraph batch = new Neo4jBatchGraph(directory);
Index<Vertex> index = batch.createIndex("testIdx", Vertex.class, new Parameter("analyzer", LowerCaseKeywordAnalyzer.class.getName()));
Vertex a = batch.addVertex(null);
a.setProperty("name", "marko");
index.put("name", "marko", a);
batch.flushIndices();
batch.shutdown();
// native neo4j graph load
IndexableGraph graph = new Neo4jGraph(directory);
Iterator<Vertex> itty = graph.getIndex("testIdx", Vertex.class).query("name", "*rko").iterator();
int counter = 0;
while (itty.hasNext()) {
counter++;
assertEquals(itty.next().getProperty("name"), "marko");
}
assertEquals(counter, 1);
itty = graph.getIndex("testIdx", Vertex.class).query("name", "MaRkO").iterator();
counter = 0;
while (itty.hasNext()) {
counter++;
assertEquals(itty.next().getProperty("name"), "marko");
}
assertEquals(counter, 1);
graph.shutdown();
}
use of com.tinkerpop.blueprints.IndexableGraph in project blueprints by tinkerpop.
the class ReadOnlyGraphTest method testReadOnlyIndices.
public void testReadOnlyIndices() {
IndexableGraph graph = new ReadOnlyIndexableGraph<TinkerGraph>(TinkerGraphFactory.createTinkerGraph());
Index<Vertex> index = ((WrapperGraph<IndexableGraph>) graph).getBaseGraph().createIndex("blah", Vertex.class);
index.put("name", "marko", graph.getVertex(1));
assertTrue(graph.getIndices() instanceof ReadOnlyIndexIterable);
index = graph.getIndex("blah", Vertex.class);
assertTrue(index instanceof ReadOnlyIndex);
assertTrue(index.get("name", "marko") instanceof ReadOnlyVertexIterable);
try {
index.put("name", "noname", graph.getVertex(1));
assertTrue(false);
} catch (UnsupportedOperationException e) {
assertTrue(true);
}
try {
index.remove("name", "marko", graph.getVertex(1));
assertTrue(false);
} catch (UnsupportedOperationException e) {
assertTrue(true);
}
assertTrue(Vertex.class.isAssignableFrom(index.getIndexClass()));
assertEquals(index.getIndexName(), "blah");
}
use of com.tinkerpop.blueprints.IndexableGraph in project blueprints by tinkerpop.
the class RexsterGraphTest method resetGraph.
protected void resetGraph() {
final KeyIndexableGraph graph = (KeyIndexableGraph) this.generateGraph();
final IndexableGraph idxGraph = (IndexableGraph) graph;
// since we don't have graph.clear() anymore we manually reset the graph.
Iterator<Vertex> vertexItty = graph.getVertices().iterator();
List<Vertex> verticesToRemove = new ArrayList<Vertex>();
while (vertexItty.hasNext()) {
verticesToRemove.add(vertexItty.next());
}
for (Vertex vertexToRemove : verticesToRemove) {
graph.removeVertex(vertexToRemove);
}
for (String key : graph.getIndexedKeys(Vertex.class)) {
graph.dropKeyIndex(key, Vertex.class);
}
for (String key : graph.getIndexedKeys(Edge.class)) {
graph.dropKeyIndex(key, Edge.class);
}
for (Index idx : idxGraph.getIndices()) {
idxGraph.dropIndex(idx.getIndexName());
}
}
Aggregations