Exemplo n.º 1
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();
  }
Exemplo n.º 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();
    }
  }