java – neo4j动态关系类型,而不是枚举

前端之家收集整理的这篇文章主要介绍了java – neo4j动态关系类型,而不是枚举前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我如何使用字符串“KNOWS”并将其用作关系类型而不是使用枚举RelTypes.KNOWS …我需要动态添加关系而不是仅使用2个枚举RelTypes.KNOWS和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
}
最佳答案
从字符串动态创建关系类型正是070​​00的存在.

猜你在找的Java相关文章