35.2. Batch Graph Database
In case you already have code for data import written against the normal Neo4j API, you could consider using a batch inserter exposing that API.
Note This will not perform as good as using the |
Also be aware of the following:
-
Starting a transaction or invoking
Transaction.finish()/close()
orTransaction.success()
will do nothing. -
Invoking the
Transaction.failure()
method will generate aNotInTransaction
exception. -
Node.delete()
andNode.traverse()
are not supported. -
Relationship.delete()
is not supported. - Event handlers and indexes are not supported.
-
GraphDatabaseService.getRelationshipTypes()
,getAllNodes()
andgetAllRelationships()
are not supported.
With these precautions in mind, this is how to do it:
GraphDatabaseService batchDb = BatchInserters.batchDatabase( "target/batchdb-example", fileSystem ); Label personLabel = DynamicLabel.label( "Person" ); Node mattiasNode = batchDb.createNode( personLabel ); mattiasNode.setProperty( "name", "Mattias" ); Node chrisNode = batchDb.createNode(); chrisNode.setProperty( "name", "Chris" ); chrisNode.addLabel( personLabel ); RelationshipType knows = DynamicRelationshipType.withName( "KNOWS" ); mattiasNode.createRelationshipTo( chrisNode, knows ); batchDb.shutdown();
Tip The source code of the example is found here: BatchInsertDocTest.java |