Frage

Is there a thread safe way to ensure unique vertices are created by a framed graph? Consider the following:

Node n = framedGraph.addVertex(1, Node.class);
Node m = framedGraph.addVertex(1, Node.class);
System.out.println(n.equals(framedGraph.getVertex(1, Node.class)));
System.out.println(m.equals(framedGraph.getVertex(1, Node.class)));

prints true, false.

I'm looking for functionality similar to the get or create unique node functionality provided by Neo4j (which is the backing graph in this case).

As an aside - is there a way to use non-numeric ids?

Node m = framedGraph.addVertex("http://example.org", Node.class);
System.out.println(n.equals(framedGraph.getVertex("http://example.org", Node.class)));

prints false

War es hilfreich?

Lösung

Neo4j and most Graph implementations of Blueprints ignore the ID parameter. Aside from TinkerGraph, they generally all assign their own IDs without methods to create your own. You could always use IdGraph to help simulate your own ID.

Blueprints doesn't maintain the notion of "get or create". You have to implement that yourself or I suppose it's possible to reach down into Neo4j code to do it, with the expectation that your code is no longer portable from one graph to another. In that way, perhaps you could build a graph wrapper implementation similar to IdGraph that exposed a getOrCreate() method. At least that way, you still get to work with the Graph interface and the such logic is encapsulated within that. Of course, that won't help with enabling such functionality directly in Frames.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top