How would I take the string "KNOWS" and use it as a Relationship type instead of using an enum RelTypes.KNOWS ... I need to dynamically add relationship instead of using only the 2 enums RelTypes.KNOWS and RelTypes.IS_FRIENDS_WITH
// START SNIPPET: createReltype
private static enum RelTypes implements RelationshipType
{
    KNOWS,
    IS_FRIENDS_WITH
}
// END SNIPPET: createReltype
public static void main( final String[] args )
{
    // START SNIPPET: startDb
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase( DB_PATH );
    registerShutdownHook( graphDb );
    // END SNIPPET: startDb
    // START SNIPPET: operationsInATransaction
    Transaction tx = graphDb.beginTx();
    try
    {
        Node john = graphDb.createNode();
        john.setProperty("name", "John" );
        Node george = graphDb.createNode();
        george.setProperty("name", "George" );
        firstNode.createRelationshipTo( secondNode, RelTypes.KNOWS );
        tx.success();
    }
    finally
    {
        tx.finish();
    }
    // END SNIPPET: removingData
    System.out.println( "Shutting down database ..." );
    // START SNIPPET: shutdownServer
    graphDb.shutdown();
    // END SNIPPET: shutdownServer
}
                Creating relationship types dynamically from a string is exactly what org.neo4j.graphdb.DynamicRelationshipType exists for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With