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;
 }
 public void verify(String dbPath) {
   EmbeddedGraphDatabase graphDb = new EmbeddedGraphDatabase(dbPath);
   assertEquals(
       "Reference node did not have zero relationships.",
       0,
       IteratorUtil.count(graphDb.getReferenceNode().getRelationships()));
   assertEquals("There was more than one node.", 1, IteratorUtil.count(graphDb.getAllNodes()));
   graphDb.shutdown();
 }
 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);
 }
 protected void configureSourceDb(final EmbeddedGraphDatabase graphDb) {
   XaDataSource neoStoreXaDataSource =
       graphDb
           .getConfig()
           .getPersistenceModule()
           .getPersistenceManager()
           .getPersistenceSource()
           .getXaDataSource();
   neoStoreXaDataSource.keepLogicalLogs(true);
   XaDataSourceManager xaDsm = graphDb.getConfig().getTxModule().getXaDataSourceManager();
   XaDataSource ds = xaDsm.getXaDataSource("lucene");
   ((LuceneDataSource) ds).keepLogicalLogs(true);
 }
 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.index().forNodes("nodes").get("value", "indexed").getSingle();
   if (!acceptNull) assertNotNull("node not in index", node);
   if (node != null) assertEquals("indexed", node.getProperty("value", null));
   resumeThread();
 }
Exemple #7
0
 @After
 public void tearDown() throws IOException {
   mongo.dropDatabase(MONGO_DB_NAME);
   mongo.close();
   neo.shutdown();
   FileUtils.deleteDirectory(new File(NEO_DB_DIR));
 }
    @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();
    }
  @Test
  public void testTxCacheLoadIsolation() throws Exception {
    Node node = getGraphDb().createNode();
    node.setProperty("someproptest", "testing");
    Node node1 = getGraphDb().createNode();
    node1.setProperty("someotherproptest", 2);
    commit();
    EmbeddedGraphDatabase graphDb = (EmbeddedGraphDatabase) getGraphDb();
    TransactionManager txManager = graphDb.getConfig().getTxModule().getTxManager();
    NodeManager nodeManager = graphDb.getConfig().getGraphDbModule().getNodeManager();

    txManager.begin();
    node.setProperty("someotherproptest", "testing2");
    Relationship rel = node.createRelationshipTo(node1, MyRelTypes.TEST);
    javax.transaction.Transaction txA = txManager.suspend();
    txManager.begin();
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(!node.hasProperty("someotherproptest"));
    assertTrue(!node.hasRelationship());
    nodeManager.clearCache();
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(!node.hasProperty("someotherproptest"));
    javax.transaction.Transaction txB = txManager.suspend();
    txManager.resume(txA);
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(node.hasProperty("someotherproptest"));
    assertTrue(node.hasRelationship());
    nodeManager.clearCache();
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(node.hasProperty("someotherproptest"));
    assertTrue(node.hasRelationship());
    txManager.suspend();
    txManager.resume(txB);
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(!node.hasProperty("someotherproptest"));
    assertTrue(!node.hasRelationship());
    txManager.rollback();
    txManager.resume(txA);
    node.delete();
    node1.delete();
    rel.delete();
    txManager.commit();
    newTransaction();
  }
  @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);
  }
  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 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");
  }
  @Override
  public void shutdown() {
    if (TRACK_UNCLOSED_DATABASE_INSTANCES) startedButNotYetClosed.remove(new File(getStoreDir()));

    super.shutdown();
  }
 @Override
 protected void configureSourceDb(final EmbeddedGraphDatabase graphDb) {
   PersistenceSource persistenceSource =
       graphDb.getConfig().getPersistenceModule().getPersistenceManager().getPersistenceSource();
   ((NeoStoreXaDataSource) persistenceSource.getXaDataSource()).keepLogicalLogs(false);
 }
 public void shutdown() {
   inner.shutdown();
   deleteRecursively(new File(storeDir));
 }
 @Override
 public Config getConfig() {
   return inner.getConfig();
 }
 public Iterable<Node> getAllNodes() {
   return inner.getAllNodes();
 }
 public KernelEventHandler unregisterKernelEventHandler(KernelEventHandler handler) {
   return inner.unregisterKernelEventHandler(handler);
 }
 public Node getReferenceNode() {
   return inner.getReferenceNode();
 }
 public Relationship getRelationshipById(long id) {
   return inner.getRelationshipById(id);
 }
 public IndexManager index() {
   return inner.index();
 }
 public Node createNode() {
   return inner.createNode();
 }
 @Override
 public boolean isReadOnly() {
   return inner.isReadOnly();
 }
 @Override
 public <T> T getManagementBean(Class<T> type) {
   return inner.getManagementBean(type);
 }
 public Iterable<RelationshipType> getRelationshipTypes() {
   return inner.getRelationshipTypes();
 }
 public <T> TransactionEventHandler<T> unregisterTransactionEventHandler(
     TransactionEventHandler<T> handler) {
   return inner.unregisterTransactionEventHandler(handler);
 }
 public Transaction beginTx() {
   return inner.beginTx();
 }
 public Node getNodeById(long id) {
   return inner.getNodeById(id);
 }
 @Override
 public String getStoreDir() {
   return inner.getStoreDir();
 }