@Autowired private Map<String,String> configuration; @Bean public GraphDatabaseService graphDb() { return new EmbeddedGraphDatabase( "data/neo4j-db", configuration ); }
@Override public GraphDatabaseService newDatabase(Map<String, String> config) { config.put("ephemeral", "false"); EmbeddedGraphDatabase database = new EmbeddedGraphDatabase(path, config, state.databaseDependencies()); database.shutdown(); return new HighlyAvailableGraphDatabase(path, config, state.databaseDependencies()); } });
public static LockManager getLockManager( GraphDatabaseService graphDb ) { return ( ( EmbeddedGraphDatabase ) graphDb ).getConfig().getLockManager(); }
private void addNode( EmbeddedGraphDatabase graphDb ) { Node referenceNode = graphDb.getReferenceNode(); Node node = graphDb.createNode(); referenceNode.createRelationshipTo( node, MyRels.TEST ); } }
EmbeddedGraphDatabase graphDb = new EmbeddedGraphDatabase( STORE_LOCATION_DIR ); graphDb.shutdown(); Util.copyDir( STORE_LOCATION_DIR, BACKUP_LOCATION_DIR ); graphDb = new EmbeddedGraphDatabase( STORE_LOCATION_DIR ); IndexService index = new LuceneIndexService( graphDb ); XaDataSourceManager xaDsMgr = graphDb.getConfig().getTxModule().getXaDataSourceManager(); for ( XaDataSource xaDs : xaDsMgr.getAllRegisteredDataSources() ) Transaction tx = graphDb.beginTx(); try Node node1 = graphDb.createNode(); index.index( node1, "backup_test", "1" ); tx.success(); tx = graphDb.beginTx(); try Node node2 = graphDb.createNode(); index.index( node2, "backup_test", "2" ); tx.success(); graphDb.shutdown();
static void stopGraphDb( EmbeddedGraphDatabase graphDb ) { graphDb.shutdown(); }
@Override protected void tryBackup( EmbeddedGraphDatabase graphDb, String location, int relCount ) throws IOException { System.out.println( "backing up to backup location" ); Backup backupComp = Neo4jBackup.neo4jDataSource( graphDb, location ); backupComp.doBackup(); EmbeddedGraphDatabase bDb = Util.startGraphDbInstance( location ); Transaction bTx = bDb.beginTx(); try { List<Relationship> rels = new ArrayList<Relationship>(); for ( Relationship rel : bDb.getReferenceNode().getRelationships() ) { rels.add( rel ); } assertEquals( relCount, rels.size() ); bTx.success(); } finally { bTx.finish(); } Util.stopGraphDb( bDb ); } }
@Before public void doBefore() { tx = graphDb.beginTx(); }
public void nodeWrapperSetUsage() { Node baseNode = graphDb.createNode(); Node itemNode1 = graphDb.createNode(); Node itemNode2 = graphDb.createNode(); Collection<MyDomainObject> items = new NodeWrapperRelationshipSet<MyDomainObject>( baseNode, ExampleTypes.MY_TYPE, MyDomainObject.class ); MyDomainObject item1 = new MyDomainObject( itemNode1 ); MyDomainObject item2 = new MyDomainObject( itemNode2 ); items.add( item1 ); items.add( item2 ); for ( MyDomainObject item : items ) { // Do something with the item } }
@Override public GraphDatabaseService newHighlyAvailableDatabase(String path) { EmbeddedGraphDatabase database = (EmbeddedGraphDatabase) newEmbeddedDatabase(path); database.shutdown(); return super.newHighlyAvailableDatabase(path); }
protected void tryBackup( EmbeddedGraphDatabase graphDb, String location, int relCount ) throws IOException { System.out.println( "backing up to running EmbeddedGraphDatabase instance" ); EmbeddedGraphDatabase bDb = Util.startGraphDbInstance( location ); Backup backupComp = Neo4jBackup.neo4jDataSource( graphDb, bDb ); configureBackup( backupComp ); backupComp.doBackup(); Util.stopGraphDb( bDb ); bDb = Util.startGraphDbInstance( location ); Transaction bTx = bDb.beginTx(); try { List<Relationship> rels = new ArrayList<Relationship>(); for ( Relationship rel : bDb.getReferenceNode().getRelationships() ) { rels.add( rel ); } assertEquals( relCount, rels.size() ); bTx.success(); } finally { bTx.finish(); } Util.stopGraphDb( bDb ); }
private Node addNode( EmbeddedGraphDatabase graphDb ) { Node referenceNode = graphDb.getReferenceNode(); Node node = graphDb.createNode(); node.setProperty( "theId", node.getId() ); referenceNode.createRelationshipTo( node, MyRels.TEST ); return node; } }
@Test public void handleArrayValues() { Node node = graphDb.createNode(); // START SNIPPET: handleArrayValues node.setProperty( "numbers", 5 ); List<Object> oneNumber = GraphDatabaseUtil.getPropertyValues( node, "numbers" ); // Will contain one item (5). node.setProperty( "numbers", new int[] { 5, 10, 15 } ); List<Object> numbers = GraphDatabaseUtil.getPropertyValues( node, "numbers" ); // Will contain three items (5, 10, 15). // There's also methods for adding/removing values to/from a property. GraphDatabaseUtil.removeValueFromArray( node, "numbers", 10 ); GraphDatabaseUtil.addValueToArray( node, "numbers", 20 ); List<Object> newNumbers = GraphDatabaseUtil.getPropertyValues( node, "numbers" ); // Will contain three items (5, 15, 20). // END SNIPPET: handleArrayValues }
/** * This constructor takes care of creating the Neo4j * {@link GraphDatabaseService}. * * @param storeDir The directory where the Neo4j data is stored. */ public TheMatrix( String storeDir ) { this.graphDb = new EmbeddedGraphDatabase( storeDir ); }
private static GraphDatabaseService createCleanGraphDatabase( String storeDir ) { if ( graphDb != null ) { graphDb.shutdown(); graphDb = null; } deleteFileOrDirectory( new File( storeDir ) ); return graphDb = new EmbeddedGraphDatabase( storeDir ); }
private static TransactionManager getTransactionManagerFor( GraphDatabaseService graphDb ) { if ( graphDb instanceof EmbeddedGraphDatabase ) { return ( ( EmbeddedGraphDatabase ) graphDb ).getConfig().getTxModule() .getTxManager(); } else { throw new IllegalArgumentException( "Cannot get transaction manager from graph database instance of class=" + graphDb.getClass() ); } } }
@AfterClass public static void shutdownDb() { graphDb.shutdown(); }
protected void tryBackup( EmbeddedGraphDatabase graphDb, String location, int relCount ) throws IOException { setupBackup( graphDb, location ); EmbeddedGraphDatabase bDb = Util.startGraphDbInstance( location ); IndexService bIndexService = new LuceneIndexService( bDb ); Transaction bTx = bDb.beginTx(); try { List<Relationship> rels = new ArrayList<Relationship>(); for ( Relationship rel : bDb.getReferenceNode().getRelationships() ) { rels.add( rel ); } assertEquals( relCount, rels.size() ); Node node = bIndexService.getSingleNode( "number", relCount ); assertEquals( true, node != null ); assertEquals( node.getId(), (long) (Long) node.getProperty( "theId", -1L ) ); bTx.success(); } finally { bTx.finish(); } Util.stopGraphDb( bDb, bIndexService ); }
@Before public void clean() { Util.deleteDir( new File( VAR ) ); System.out.println( "setting up simple database and backup-copy" ); EmbeddedGraphDatabase graphDb = Util.startGraphDbInstance( STORE_LOCATION_DIR ); configureSourceDb( graphDb ); Transaction tx = graphDb.beginTx(); try { addNode( graphDb ); tx.success(); } finally { tx.finish(); } Util.stopGraphDb( graphDb ); Util.copyDir( STORE_LOCATION_DIR, BACKUP_LOCATION_DIR ); }