2011-12-22 11 views
5

Come faccio a prendere la stringa "sa" e usarlo come un tipo di relazione invece di utilizzare un enum RelTypes.KNOWS ... ho bisogno di aggiungere in modo dinamico rapporto invece di utilizzare solo il 2 enums RelTypes.KNOWS e RelTypes.IS_FRIENDS_WITHNeo4j Tipi dinamica di relazione, non con le enumerazioni

// 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 
} 

risposta

Problemi correlati