@Test public void backup() throws IOException { System.out.println("starting tests"); EmbeddedGraphDatabase graphDb = Util.startGraphDbInstance(STORE_LOCATION_DIR); IndexService indexService = new LuceneIndexService(graphDb); configureSourceDb(graphDb); System.out.println("backing up original db without any changes"); tryBackup(graphDb, BACKUP_LOCATION_DIR, 1); Transaction tx = graphDb.beginTx(); try { indexService.index(addNode(graphDb), "number", 2); tx.success(); } finally { tx.finish(); } System.out.println("one node added"); tryBackup(graphDb, BACKUP_LOCATION_DIR, 2); tx = graphDb.beginTx(); try { indexService.index(addNode(graphDb), "number", 3); tx.success(); } finally { tx.finish(); } System.out.println("one node added"); tx = graphDb.beginTx(); try { indexService.index(addNode(graphDb), "number", 4); System.out.println("one node added, not commited"); tryBackup(graphDb, BACKUP_LOCATION_DIR, 3); tx.success(); } finally { tx.finish(); } System.out.println("previous add commited"); tryBackup(graphDb, BACKUP_LOCATION_DIR, 4); Util.stopGraphDb(graphDb, indexService); }
public void generate(String dbPath) { EmbeddedGraphDatabase graphDb = new EmbeddedGraphDatabase(dbPath); Index<Node> nodeIndex = graphDb.index().forNodes("nodes"); Index<Relationship> relationshipIndex = graphDb.index().forRelationships("relationships"); graphDb.beginTx(); Node n = graphDb.createNode(); Relationship rel = graphDb.getReferenceNode().createRelationshipTo(n, REL_TYPE); nodeIndex.add(n, "name", "a"); relationshipIndex.add(rel, "name", "a"); }
public static void main(String[] args) { String storeDir = args[0]; boolean setGraphProperty = args.length > 1 ? Boolean.parseBoolean(args[1]) : false; EmbeddedGraphDatabase db = new EmbeddedGraphDatabase(storeDir); Transaction tx = db.beginTx(); Node node = db.createNode(); node.setProperty("name", "Something"); if (setGraphProperty) db.getNodeManager().getGraphProperties().setProperty("prop", "Some value"); tx.success(); tx.finish(); System.exit(0); }
public Station getStationFromDatabase(EmbeddedGraphDatabase database) { Transaction transaction = database.beginTx(); Station res = null; try { res = new Station(database.getNodeById(this.nodeId)); transaction.success(); } catch (Exception e) { Logger.getLogger(Station.class) .error("Unable to retreive " + this.name() + " from the graph-database.", e); transaction.failure(); } finally { transaction.finish(); } return res; }
@Override public void run(EmbeddedGraphDatabase graphdb) { Node node = graphdb.getReferenceNode(); Transaction tx = graphdb.beginTx(); try { // First do the index operations, to add that data source first graphdb.index().forNodes("nodes").add(node, "value", "indexed"); // Then update the graph node.setProperty("value", "indexed"); enableBreakPoint(); tx.success(); } finally { tx.finish(); } done(); }
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 setup() { Util.deleteDir(new File(VAR)); System.out.println("setting up database and backup-copy including Lucene"); EmbeddedGraphDatabase graphDb = Util.startGraphDbInstance(STORE_LOCATION_DIR); IndexService indexService = new LuceneIndexService(graphDb); configureSourceDb(graphDb); Transaction tx = graphDb.beginTx(); try { indexService.index(addNode(graphDb), "number", 1); tx.success(); } finally { tx.finish(); } Util.stopGraphDb(graphDb, indexService); Util.copyDir(STORE_LOCATION_DIR, BACKUP_LOCATION_DIR); }
public Transaction beginTx() { return inner.beginTx(); }
@Test public void testLowGrabSize() { Map<String, String> config = new HashMap<String, String>(); config.put("relationship_grab_size", "1"); EmbeddedGraphDatabase graphDb = new EmbeddedGraphDatabase(getStorePath("neo2"), config); Transaction tx = graphDb.beginTx(); Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); node1.createRelationshipTo(node2, MyRelTypes.TEST); node2.createRelationshipTo(node1, MyRelTypes.TEST2); node1.createRelationshipTo(node2, MyRelTypes.TEST_TRAVERSAL); tx.success(); tx.finish(); tx = graphDb.beginTx(); Set<Relationship> rels = new HashSet<Relationship>(); RelationshipType types[] = new RelationshipType[] {MyRelTypes.TEST, MyRelTypes.TEST2, MyRelTypes.TEST_TRAVERSAL}; graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache(); for (Relationship rel : node1.getRelationships(types)) { assertTrue(rels.add(rel)); } assertEquals(3, rels.size()); rels.clear(); graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache(); for (Relationship rel : node1.getRelationships()) { assertTrue(rels.add(rel)); } assertEquals(3, rels.size()); rels.clear(); graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache(); for (Relationship rel : node2.getRelationships(types)) { assertTrue(rels.add(rel)); } assertEquals(3, rels.size()); rels.clear(); graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache(); for (Relationship rel : node2.getRelationships()) { assertTrue(rels.add(rel)); } assertEquals(3, rels.size()); rels.clear(); graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache(); for (Relationship rel : node1.getRelationships(Direction.OUTGOING)) { assertTrue(rels.add(rel)); } assertEquals(2, rels.size()); rels.clear(); graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache(); for (Relationship rel : node1.getRelationships(Direction.INCOMING)) { assertTrue(rels.add(rel)); } assertEquals(1, rels.size()); rels.clear(); graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache(); for (Relationship rel : node2.getRelationships(Direction.OUTGOING)) { assertTrue(rels.add(rel)); } assertEquals(1, rels.size()); rels.clear(); graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache(); for (Relationship rel : node2.getRelationships(Direction.INCOMING)) { assertTrue(rels.add(rel)); } assertEquals(2, rels.size()); tx.success(); tx.finish(); graphDb.shutdown(); }