1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| package neo4j;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.graphdb.*;
/**
*
* @author khadi
*/
public class NewMain {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
// TODO code application logic here
GraphDatabaseService graphDb = new EmbeddedGraphDatabase("C:\\Users\\khadi\\Documents\\Neo4j\\default.graphdb");
// Toute lecture et écriture doit se faire dans une transaction avec Neo4J
Transaction tx = graphDb.beginTx();
try
{
Node jamesGosling = graphDb.createNode();
jamesGosling.setProperty( "name", "Thomas Anderson");
jamesGosling.setProperty( "age", 29 );
////
Node java = graphDb.createNode();
//créer une relation entre james et java
Relationship relationship = jamesGosling.createRelationshipTo(java, RelTypes.USES);
jamesGosling.setProperty("nom", "James Gosling");
java.setProperty("date", "1995");
relationship.setProperty("type", "a créé");
tx.success();
}
finally
{
tx.finish();
}
graphDb.shutdown();
}
} |
Partager