Esempio n. 1
0
  public IndexDefinition _createIndex(Label label, String key) {
    Schema schema = graphDb.schema();

    for (IndexDefinition index : schema.getIndexes(label))
      for (String property : index.getPropertyKeys())
        if (property.equals(key)) return index; // already existing

    return schema.indexFor(label).on(key).create();
  }
Esempio n. 2
0
  public ConstraintDefinition _createConstrant(Label label, String key) {
    Schema schema = graphDb.schema();

    for (ConstraintDefinition constraint : schema.getConstraints(label))
      for (String property : constraint.getPropertyKeys())
        if (property.equals(key)) return constraint; // already existing

    return schema.constraintFor(label).assertPropertyIsUnique(key).create();
  }
  private static void setLabelSystem() {
    IndexDefinition indexDefinition;
    try (Transaction tx = graphDb.beginTx()) {
      Schema schema = graphDb.schema();
      indexDefinition = schema.indexFor(DynamicLabel.label("Nome")).on("name").create();
      tx.success();
    }

    try (Transaction tx = graphDb.beginTx()) {
      Schema schema = graphDb.schema();
      schema.awaitIndexOnline(indexDefinition, 10, TimeUnit.SECONDS);
    }
  }
Esempio n. 4
0
  /**
   * Defines constraints for the graph property model. Creates indexes for blocks and transactions.
   */
  protected void createIndexesAndUniqueConstraints() {
    try (Transaction tx = graphDatabase.beginTx()) {
      Schema schema = graphDatabase.schema();

      if (!schema.getIndexes().iterator().hasNext()) {
        LOGGER.debug("Creating Indexes and Unique Constraints.");

        schema.constraintFor(LabelType.Block).assertPropertyIsUnique("hash").create();

        schema.constraintFor(LabelType.Block).assertPropertyIsUnique("height").create();

        // No unique constraints for transactions (see BIP30)
        schema.indexFor(LabelType.Transaction).on("hash").create();

        schema.constraintFor(LabelType.Address).assertPropertyIsUnique("hash").create();

        schema.indexFor(LabelType.Coinbase).on("hash").create();

        schema.indexFor(LabelType.LatestBlock).on("height").create();
      }
      tx.success();
    }
  }