Add shortcut to node using built-in API

Using Neo4j 2.0 Milestones 3

Currently this code (working code)

String DB_PATH = "/usr/local/Cellar/neo4j/community-1.8.1-unix/libexec/data/graph.db"; GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); Transaction tx = graphDb.beginTx(); try { Node myNode = graphDb.createNode(); tx.success(); } finally { tx.finish(); } 

This is a built-in API. How to add a shortcut to my node? Thanks!

+6
source share
1 answer

You must first create a shortcut by creating an Enum that implements Label , or use DynamicLabel to create it on the fly.

Once you have created, you will need to add it to Node .

The following shows how to do this with DynamicLabel :

 import org.neo4j.graphdb.DynamicLabel; Label myLabel = DynamicLabel.label("Label_Name"); myNode.addLabel(myLabel); 

You must also do this in a transaction.

+20
source

Source: https://habr.com/ru/post/947310/


All Articles