Example #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();
  }
Example #2
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();
    }
  }