我如何使用字符串“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
}
最佳答案
从字符串动态创建关系类型正是07000的存在.