[英]neo4j Dynamic Relationship Types, not with enums
我如何使用字符串“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
}
從字符串動態創建關系類型正是org.neo4j.graphdb.DynamicRelationshipType
針對的類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.