Created
February 2, 2012 08:25
-
-
Save espeed/1722346 to your computer and use it in GitHub Desktop.
Blueprints Automatic Index Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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