Interface Schema


public interface Schema
Interface for managing the schema of your graph database. This currently includes the indexing support added in Neo4j 2.0. Please see the Neo4j manual for details. Compatibility note: New methods may be added to this interface without notice, backwards compatibility is only guaranteed for clients of this interface, not for implementors.
  • Method Details

    • indexFor

      IndexCreator indexFor(Label label)
      Begin specifying an index for all nodes with the given label. Returns an IndexCreator where details about the index to create can be specified. When all details have been entered, create must be called for the index to actually be created. Creating an index enables indexing for nodes with the specified label. The index will have the details supplied to the returned index creator. All existing and all future nodes matching the index definition will be indexed, speeding up future read operations.
      Parameters:
      label - label on nodes to be indexed.
      Returns:
      an IndexCreator capable of providing details for, as well as creating an index for the given label.
    • indexFor

      IndexCreator indexFor(Label... labels)
      Begin specifying an index for all nodes with any of the given labels. Returns an IndexCreator where details about the index to create can be specified. When all details have been entered, create must be called for the index to actually be created. Creating an index enables indexing for nodes with any of the specified labels. The index will have the details supplied to the returned index creator. All existing and all future nodes matching the index definition will be indexed, speeding up future read operations. This behaves similar to the indexFor(Label) method, with the exception that multiple labels can be specified. Doing so will create a so-called multi-token index. Note that not all index types support multi-token indexes. See IndexType for more information. The list of labels may not contain any duplicates.
      Parameters:
      labels - The list of labels for which nodes should be indexed.
      Returns:
      an IndexCreator capable of providing details for, as well as creating an index for the given list of labels.
    • indexFor

      Begin specifying an index for all relationships with the given relationship type. Returns an IndexCreator where details about the index to create can be specified. When all details have been entered, create must be called for the index to actually be created. Creating an index enables indexing for relationships with the specified relationship type. The index will have the details supplied to the returned index creator. All existing and all future relationships matching the index definition will be indexed, speeding up future read operations.
      Parameters:
      type - relationship type on relationships to be indexed.
      Returns:
      an IndexCreator capable of providing details for, as well as creating an index for the given RelationshipType.
    • indexFor

      IndexCreator indexFor(RelationshipType... types)
      Begin specifying an index for all relationships with any of the given relationship types. Returns an IndexCreator where details about the index to create can be specified. When all details have been entered, create must be called for the index to actually be created. Creating an index enables indexing for relationships with any of the specified relationship types. The index will have the details supplied to the returned index creator. All existing and all future relationships matching the index definition will be indexes, speeding up future read operations. This behaves similar to the indexFor(RelationshipType) method, with the exception that multiple relationship types can be specified. Doing so will create a so-called multi-token index. Note that not all index types support multi-token indexes. See IndexType for more information.
      Parameters:
      types - relationship types on relationships to be indexed.
      Returns:
      an IndexCreator capable of providing details for, as well as creating an index for the given RelationshipTypes.
    • indexFor

      IndexCreator indexFor(AnyTokens tokens)
      Begin specifying an index of type IndexType.LOOKUP for all labels or relationship types. Returns an IndexCreator where details about the index to create can be specified. When all details have been entered, create must be called for the index to actually be created. Creating such index enables indexing for labeled nodes or relationships. The index will have the details supplied to the returned index creator. All existing and all future label nodes or relationships will be indexed, speeding up future read operations.
      Parameters:
      tokens - kind of tokens to be indexed.
      Returns:
      an IndexCreator capable of providing details for, as well as creating an index for the given label.
    • getIndexes

      Iterable<IndexDefinition> getIndexes(Label label)
      Parameters:
      label - the Label to get indexes for.
      Returns:
      all indexes attached to the given label.
    • getIndexes

      Iterable<IndexDefinition> getIndexes(RelationshipType relationshipType)
      Parameters:
      relationshipType - the RelationshipType to get indexes for.
      Returns:
      all indexes attached to the given relationship type.
    • getIndexes

      Iterable<IndexDefinition> getIndexes()
      Returns:
      all indexes in this database.
    • getIndexState

      Schema.IndexState getIndexState(IndexDefinition index)
      Poll the database for the state of a given index. This can be used to track in which state the creation of the index is, for example if it's still populating in the background, or has come online.
      Parameters:
      index - the index that we want to poll state for
      Returns:
      the current Schema.IndexState of the index
    • getIndexPopulationProgress

      IndexPopulationProgress getIndexPopulationProgress(IndexDefinition index)
      Poll the database for the population progress. This can be used to track the progress of the population job associated to the given index. If the index is populating or online, the state will contain current progress. If the index is failed then the state returned from this method should be regarded as invalid.
      Parameters:
      index - the index that we want to poll state for
      Returns:
      the current population progress for the index
    • getIndexFailure

      String getIndexFailure(IndexDefinition index)
      If getIndexState(IndexDefinition) return Schema.IndexState.FAILED this method will return the failure description.
      Parameters:
      index - the IndexDefinition to get failure from.
      Returns:
      the failure description.
      Throws:
      IllegalStateException - if the index isn't in a Schema.IndexState.FAILED state.
    • constraintFor

      ConstraintCreator constraintFor(Label label)
      Returns a ConstraintCreator where details about the constraint can be specified. When all details have been entered, ConstraintCreator.create() must be called for it to actually be created. Creating a constraint will block on the create method until all existing data has been verified for compliance. If any existing data doesn't comply with the constraint an exception will be thrown, and the constraint will not be created.
      Parameters:
      label - the label this constraint is for.
      Returns:
      a ConstraintCreator capable of providing details for, as well as creating a constraint for the given label.
    • constraintFor

      ConstraintCreator constraintFor(RelationshipType type)
      Returns a ConstraintCreator where details about the constraint can be specified. When all details have been entered, ConstraintCreator.create() must be called for it the actually be created. Creating a constraint will block on the create method until all existing data has been verified for compliance. If any existing data doesn't comply with the constraint an exception will be thrown, and the constraint will not be created.
      Parameters:
      type - the relationship type this constraint is for.
      Returns:
      a ConstraintCreator capable of providing details for, as well as creating a constraint for the given RelationshipType.
    • getConstraints

      Iterable<ConstraintDefinition> getConstraints(Label label)
      Parameters:
      label - the label to get constraints for.
      Returns:
      all constraints for the given label.
    • getConstraints

      Parameters:
      type - the relationship type to get constraints for.
      Returns:
      all constraints for the given relationship type.
    • getConstraints

      Iterable<ConstraintDefinition> getConstraints()
      Returns:
      all constraints
    • awaitIndexOnline

      void awaitIndexOnline(IndexDefinition index, long duration, TimeUnit unit)
      Wait until an index comes online
      Parameters:
      index - the index that we want to wait for
      duration - duration to wait for the index to come online
      unit - TimeUnit of duration
      Throws:
      IllegalStateException - if the index did not enter the ONLINE state within the given duration or if the index entered the FAILED state
    • awaitIndexOnline

      void awaitIndexOnline(String indexName, long duration, TimeUnit unit)
      Wait until an index with the given name comes online.
      Parameters:
      indexName - the name of the index that we want to wait for.
      duration - duration to wait for the index to come online
      unit - TimeUnit of duration
      Throws:
      IllegalStateException - if the index did not enter the ONLINE state within the given duration, or if the index entered the FAILED state.
    • awaitIndexesOnline

      void awaitIndexesOnline(long duration, TimeUnit unit)
      Wait until all indices comes online
      Parameters:
      duration - duration to wait for all indexes to come online
      unit - TimeUnit of duration
      Throws:
      IllegalStateException - if some index did not enter the ONLINE state within the given duration or if the index entered the FAILED state
    • getConstraintByName

      ConstraintDefinition getConstraintByName(String constraintName)
      Get a ConstraintDefinition by the given name of the constraint.
      Parameters:
      constraintName - The name of the constraint.
      Returns:
      The constraint with that name.
      Throws:
      IllegalArgumentException - if there is no constraint with that name.
    • getIndexByName

      IndexDefinition getIndexByName(String indexName)
      Get an IndexDefinition by the name of the index.
      Parameters:
      indexName - The name of the index.
      Returns:
      The index with that name.
      Throws:
      IllegalArgumentException - if there is no index with that name.