// 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
// Encapsulate operations in a transaction
Transaction tx = graphDb.beginTx();
try
{
Node firstNode = graphDb.createNode();
firstNode.setProperty( NAME_KEY, "Hello" );
Node secondNode = graphDb.createNode();
secondNode.setProperty( NAME_KEY, "World" );
firstNode.createRelationshipTo( secondNode,
ExampleRelationshipTypes.EXAMPLE );
String greeting = firstNode.getProperty( NAME_KEY ) + " "
+ secondNode.getProperty( NAME_KEY );
System.out.println( greeting );
// END SNIPPET: operationsInATransaction
// START SNIPPET: removingData
// let's remove the data before committing
firstNode.getSingleRelationship( ExampleRelationshipTypes.EXAMPLE,
Direction.OUTGOING ).delete();
firstNode.delete();
secondNode.delete();
tx.success();
}
finally
{
tx.finish();
}
// END SNIPPET: removingData
System.out.println( "Shutting down database ..." );
// START SNIPPET: shutdownServer
graphDb.shutdown();
// END SNIPPET: shutdownServer
}