@Override public Map<String, Node> create( GraphDatabaseService graphdb ) { Map<String, Node> result = new HashMap<>(); try ( Transaction tx = graphdb.beginTx() ) { graphdb.index().getRelationshipAutoIndexer().setEnabled( autoIndexRelationships ); for ( NODE def : nodes ) { Node node = init( graphdb.createNode(), def.setNameProperty() ? def.name() : null, def.properties(), graphdb.index().getNodeAutoIndexer(), autoIndexNodes ); for ( LABEL label : def.labels() ) { node.addLabel( label( label.value() ) ); } result.put( def.name(), node ); } for ( REL def : rels ) { init( result.get( def.start() ).createRelationshipTo( result.get( def.end() ), RelationshipType.withName( def.type() ) ), def.setNameProperty() ? def.name() : null, def.properties(), graphdb.index().getRelationshipAutoIndexer(), autoIndexRelationships ); } tx.success(); } return result; }
@Before public void startDb() { graphDb = (GraphDatabaseAPI) new TestGraphDatabaseFactory(). newImpermanentDatabaseBuilder().setConfig(new HashMap<>()).newGraphDatabase(); try ( Transaction tx = graphDb.beginTx() ) { // Create the node and relationship auto-indexes graphDb.index().getNodeAutoIndexer().setEnabled(true); graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty( "nodeProp"); graphDb.index().getRelationshipAutoIndexer().setEnabled(true); graphDb.index().getRelationshipAutoIndexer().startAutoIndexingProperty( "type"); tx.success(); } try ( Transaction tx = graphDb.beginTx() ) { Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); Node node3 = graphDb.createNode(); id1 = node1.getId(); id2 = node2.getId(); id3 = node3.getId(); Relationship rel = node1.createRelationshipTo(node2, RelationshipType.withName("FOO")); rel.setProperty("type", "FOO"); tx.success(); } }
indexManager.getRelationshipAutoIndexer().setEnabled( false );
graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty( "nodeProp" ); graphDb.index().getRelationshipAutoIndexer().setEnabled( true ); graphDb.index().getRelationshipAutoIndexer().startAutoIndexingProperty( "relProp" );
public <T extends Element> void createKeyIndex(final String key, final Class<T> elementClass, final Parameter... indexParameters) { if (elementClass == null) throw ExceptionFactory.classForElementCannotBeNull(); if (Vertex.class.isAssignableFrom(elementClass)) { this.autoStartTransaction(true); if (!this.rawGraph.index().getNodeAutoIndexer().isEnabled()) this.rawGraph.index().getNodeAutoIndexer().setEnabled(true); this.rawGraph.index().getNodeAutoIndexer().startAutoIndexingProperty(key); if (!this.getInternalIndexKeys(Vertex.class).contains(key)) { KeyIndexableGraphHelper.reIndexElements(this, this.getVertices(), new HashSet<String>(Arrays.asList(key))); this.autoStartTransaction(true); this.createInternalIndexKey(key, elementClass); } } else if (Edge.class.isAssignableFrom(elementClass)) { this.autoStartTransaction(true); if (!this.rawGraph.index().getRelationshipAutoIndexer().isEnabled()) this.rawGraph.index().getRelationshipAutoIndexer().setEnabled(true); this.rawGraph.index().getRelationshipAutoIndexer().startAutoIndexingProperty(key); if (!this.getInternalIndexKeys(Edge.class).contains(key)) { KeyIndexableGraphHelper.reIndexElements(this, this.getEdges(), new HashSet<String>(Arrays.asList(key))); this.autoStartTransaction(true); this.createInternalIndexKey(key, elementClass); } } else { throw ExceptionFactory.classIsNotIndexable(elementClass); } }