[英]neo4j Dynamic Relationship Types, not with enums
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 我如何使用字符串“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.