Skip to content

Instantly share code, notes, and snippets.

@espeed
Created February 2, 2012 08:25
Show Gist options
  • Select an option

  • Save espeed/1722346 to your computer and use it in GitHub Desktop.

Select an option

Save espeed/1722346 to your computer and use it in GitHub Desktop.
Blueprints Automatic Index Example
// Blueprints Automatic Index Example
// by James Thornton (http://jamesthornton.com)
def createAutomaticVertexIndex(indexName, className, keys) {
classDef = "public abstract class $className implements com.tinkerpop.blueprints.pgm.Vertex {}";
domainClass = this.class.classLoader.parseClass(classDef)
index = g.createAutomaticIndex(indexName, domainClass, keys as Set);
return index;
}
def createAutomaticIndexedVertex(indexName, data) {
g.setMaxBufferSize(0);
g.startTransaction();
try {
elementIndex = g.idx(indexName);
vertex = g.addVertex(data);
AutomaticIndexHelper.addElement(elementIndex, vertex);
g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS);
return vertex;
} catch (e) {
g.stopTransaction(TransactionalGraph.Conclusion.FAILURE);
return e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment