Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #38 from Grimboy/look-before-you-leap

Look before you leap + Rexster+neo4j compatibility
  • Loading branch information...
commit f773823b98b53dd33fa01c6eceb5f0cbc718c5f6 2 parents 4b2c3fe + b8e6242
@espeed authored
Showing with 44 additions and 8 deletions.
  1. +44 −8 bulbs/gremlin.groovy
View
52 bulbs/gremlin.groovy
@@ -90,21 +90,57 @@ def index_count(index_name, key, value) {
}
def get_or_create_vertex_index(index_name, index_params) {
- try {
- index = g.createManualIndex(index_name, Vertex.class, index_params)
- } catch (e) {
+ def getOrCreateVertexIndex = {
index = g.idx(index_name)
+ if (index == null) {
+ if (index_params == null) {
+ index = g.createManualIndex(index_name, Vertex.class)
+ } else {
+ index = g.createManualIndex(index_name, Vertex.class, index_params)
+ }
+ }
+ return index
+ }
+ def transaction = { final Closure closure ->
+ g.setMaxBufferSize(0);
+ g.startTransaction();
+ try {
+ results = closure();
+ g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS);
+ return results;
+ } catch (e) {
+ g.stopTransaction(TransactionalGraph.Conclusion.FAILURE);
+ throw e;
+ }
}
- return index
+ return transaction(getOrCreateVertexIndex);
}
def get_or_create_edge_index(index_name, index_params) {
- try {
- index = g.createManualIndex(index_name, Edge.class, index_params)
- } catch (e) {
+ def getOrCreateEdgeIndex = {
index = g.idx(index_name)
+ if (index == null) {
+ if (index_params == null) {
+ index = g.createManualIndex(index_name, Edge.class)
+ } else {
+ index = g.createManualIndex(index_name, Edge.class, index_params)
+ }
+ }
+ return index
+ }
+ def transaction = { final Closure closure ->
+ g.setMaxBufferSize(0);
+ g.startTransaction();
+ try {
+ results = closure();
+ g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS);
+ return results;
+ } catch (e) {
+ g.stopTransaction(TransactionalGraph.Conclusion.FAILURE);
+ throw e;
+ }
}
- return index
+ return transaction(getOrCreateEdgeIndex);
}
// Utils
Please sign in to comment.
Something went wrong with that request. Please try again.