Ejemplo n.º 1
0
  @Test
  public void shouldLoadAllRelationships() throws Exception {
    // GIVEN
    GraphDatabaseAPI db = getGraphDbAPI();
    Node node;
    try (Transaction tx = db.beginTx()) {
      node = db.createNode();
      for (int i = 0; i < 112; i++) {
        node.createRelationshipTo(db.createNode(), MyRelTypes.TEST);
        db.createNode().createRelationshipTo(node, MyRelTypes.TEST);
      }
      tx.success();
    }
    // WHEN
    db.getDependencyResolver().resolveDependency(NodeManager.class).clearCache();
    int one, two;
    try (Transaction tx = db.beginTx()) {
      one = count(node.getRelationships(MyRelTypes.TEST, Direction.OUTGOING));
      two = count(node.getRelationships(MyRelTypes.TEST, Direction.OUTGOING));
      tx.success();
    }

    // THEN
    assertEquals(two, one);
  }
  public static void main(String[] args) throws IOException {
    GraphDatabaseAPI db = (GraphDatabaseAPI) new GraphDatabaseFactory().newEmbeddedDatabase(dir);
    Transaction tx = db.beginTx();
    db.createNode().createRelationshipTo(db.createNode(), MyRelTypes.TEST);
    tx.success();
    tx.close();

    db.getDependencyResolver().resolveDependency(LogRotation.class).rotateLogFile();

    tx = db.beginTx();
    db.index().forNodes("index").add(db.createNode(), dir, db.createNode());
    tx.success();
    tx.close();
    exit(0);
  }
Ejemplo n.º 3
0
 protected Relationship[] createRelationshipChain(RelationshipType type, int length) {
   try (Transaction transaction = db.beginTx()) {
     Relationship[] relationshipChain = createRelationshipChain(db.createNode(), type, length);
     transaction.success();
     return relationshipChain;
   }
 }
Ejemplo n.º 4
0
 private void setSuccess(GraphDatabaseAPI graphdb, boolean success) {
   try (Transaction tx = graphdb.beginTx()) {
     Node node = graphdb.createNode();
     node.setProperty("success", success);
     tx.success();
   }
 }
 private void createARelationship(GraphDatabaseAPI db) {
   Transaction tx = db.beginTx();
   Node node1 = db.createNode();
   Node node2 = db.createNode();
   node1.createRelationshipTo(node2, withName("friend"));
   tx.success();
   tx.finish();
 }
Ejemplo n.º 6
0
 @Override
 public void run(GraphDatabaseAPI graphdb) {
   try (Transaction tx = graphdb.beginTx()) {
     for (int i = 0; i < 3; i++)
       graphdb.index().forNodes("index" + i).add(graphdb.createNode(), "name", "" + i);
     tx.success();
   }
 }
Ejemplo n.º 7
0
 long createNode() {
   GraphDatabaseAPI graphdb = server().getDatabase().getGraph();
   try (Transaction tx = graphdb.beginTx()) {
     Node node = graphdb.createNode();
     tx.success();
     return node.getId();
   }
 }
Ejemplo n.º 8
0
 private void doTransaction() {
   Transaction tx = db.beginTx();
   try {
     db.createNode();
     tx.success();
   } finally {
     tx.finish();
   }
 }
Ejemplo n.º 9
0
  private Relationship createRelationshipAndLoadFresh(Map<String, Object> properties) {
    Relationship relationship = null;
    Transaction tx = db.beginTx();
    try {
      relationship = db.createNode().createRelationshipTo(db.createNode(), MyRelTypes.TEST);
      setProperties(properties, relationship);
      tx.success();
    } finally {
      tx.finish();
    }

    clearCache();

    if (!properties.isEmpty()) {
      loadProperties(relationship);
    }

    return relationship;
  }
Ejemplo n.º 10
0
  private Node createNodeAndLoadFresh(
      Map<String, Object> properties, int nrOfRelationships, int nrOfTypes, int directionStride) {
    Node node = null;
    Transaction tx = db.beginTx();
    try {
      node = db.createNode();
      setProperties(properties, node);
      for (int t = 0; t < nrOfTypes; t++) {
        RelationshipType type = DynamicRelationshipType.withName(relTypeName(t));
        for (int i = 0, dir = 0; i < nrOfRelationships; i++, dir = (dir + directionStride) % 3) {
          switch (dir) {
            case 0:
              node.createRelationshipTo(db.createNode(), type);
              break;
            case 1:
              db.createNode().createRelationshipTo(node, type);
              break;
            case 2:
              node.createRelationshipTo(node, type);
              break;
            default:
              throw new IllegalArgumentException("Invalid direction " + dir);
          }
        }
      }
      tx.success();
    } finally {
      tx.finish();
    }

    clearCache();

    if (!properties.isEmpty()) {
      loadProperties(node);
    }
    if (nrOfRelationships * nrOfTypes > 0) {
      countRelationships(node);
    }

    return node;
  }
Ejemplo n.º 11
0
 private long createNode(Label label, int number)
     throws PropertyKeyNotFoundException, LabelNotFoundKernelException {
   Transaction tx = db.beginTx();
   try {
     Node node = db.createNode(label);
     node.setProperty(NUM_BANANAS_KEY, number);
     tx.success();
     return node.getId();
   } finally {
     tx.finish();
   }
 }
Ejemplo n.º 12
0
 protected Relationship[] createRelationshipChain(
     Node startingFromNode, RelationshipType type, int length) {
   try (Transaction tx = db.beginTx()) {
     Relationship[] rels = new Relationship[length];
     Node firstNode = startingFromNode;
     for (int i = 0; i < rels.length; i++) {
       Node secondNode = db.createNode();
       rels[i] = firstNode.createRelationshipTo(secondNode, type);
       firstNode = secondNode;
     }
     tx.success();
     return rels;
   }
 }
 private Node createNodeWithRelationships(GraphDatabaseAPI db) {
   Transaction tx = db.beginTx();
   Node node;
   try {
     node = db.createNode();
     for (int i = 0; i < relCount / 2; i++) {
       node.createRelationshipTo(node, MyRelTypes.TEST);
     }
     for (int i = 0; i < relCount / 2; i++) {
       node.createRelationshipTo(node, MyRelTypes.TEST2);
     }
     tx.success();
     return node;
   } finally {
     tx.finish();
   }
 }
Ejemplo n.º 14
0
    @Override
    public void run(GraphDatabaseAPI graphdb) {
      Transaction tx = graphdb.beginTx();
      Node node;
      try { // hack to get around another bug
        node = graphdb.createNode();

        tx.success();
      } finally {
        tx.finish();
      }
      tx = graphdb.beginTx();
      try {
        node.setProperty("correct", "yes");
        graphdb.index().forNodes("nodes").add(node, "name", "value");

        tx.success();
      } finally {
        tx.finish();
      }
    }
Ejemplo n.º 15
0
  @Test
  public void shouldHandleLargeAmountsOfNodesAddedAndRemovedInSameTx() throws Exception {
    // Given
    GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
    int labelsToAdd = 80;
    int labelsToRemove = 40;

    // When
    Node node;
    try (Transaction tx = db.beginTx()) {
      node = db.createNode();

      // I create a lot of labels, enough to push the store to use two dynamic records
      for (int l = 0; l < labelsToAdd; l++) {
        node.addLabel(label("Label-" + l));
      }

      // and I delete some of them, enough to bring the number of dynamic records needed down to 1
      for (int l = 0; l < labelsToRemove; l++) {
        node.removeLabel(label("Label-" + l));
      }

      tx.success();
    }

    // Then
    try (Transaction ignore = db.beginTx()) {
      // All the labels remaining should be in the label scan store
      for (int l = labelsToAdd - 1; l >= labelsToRemove; l--) {
        Label label = label("Label-" + l);
        assertThat(
            "Should have founnd node when looking for label " + label,
            single(GlobalGraphOperations.at(db).getAllNodesWithLabel(label)),
            equalTo(node));
      }
    }
  }
Ejemplo n.º 16
0
  @Test
  public void firstRecordOtherThanZeroIfNotFirst() throws Exception {
    String storeDir = forTest(getClass()).cleanDirectory("zero").getAbsolutePath();
    GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase(storeDir);
    Transaction tx = db.beginTx();
    Node node = db.createNode();
    node.setProperty("name", "Yo");
    tx.success();
    tx.finish();
    db.shutdown();

    db = (GraphDatabaseAPI) factory.newImpermanentDatabase(storeDir);
    tx = db.beginTx();
    properties(db).setProperty("test", "something");
    tx.success();
    tx.finish();
    db.shutdown();

    Config config =
        configForStoreDir(
            new Config(Collections.<String, String>emptyMap(), GraphDatabaseSettings.class),
            new File(storeDir));
    Monitors monitors = new Monitors();
    StoreFactory storeFactory =
        new StoreFactory(
            config,
            new DefaultIdGeneratorFactory(),
            pageCacheRule.getPageCache(fs.get(), config),
            fs.get(),
            StringLogger.DEV_NULL,
            monitors);
    NeoStore neoStore = storeFactory.newNeoStore(false);
    long prop = neoStore.getGraphNextProp();
    assertTrue(prop != 0);
    neoStore.close();
  }
Ejemplo n.º 17
0
 private void createNode(GraphDatabaseAPI db) {
   Transaction tx = db.beginTx();
   db.createNode();
   tx.success();
   tx.finish();
 }
Ejemplo n.º 18
0
 private void createNode() {
   try (Transaction tx = db.beginTx()) {
     db.createNode();
     tx.success();
   }
 }