java.lang.Object
org.neo4j.cypherdsl.support.schema_name.SchemaNames

public final class SchemaNames extends Object
A SchemaName can appear according to the OpenCypher-Spec all the following places:
  • NodePattern aka Label
  • RelationshipPattern aka Type
  • PropertyLookup
Some papers refer to a schema name as symbolic names, too. A symbolic name in the context of the Cypher-DSL is usually used to describe variables inside a statement, so we stick with the term schema name here.

A schema name must be escaped in statements with backticks - also known as grave accents - (`) when it contains content that is not a valid identifier or if the name is a reserved word.

Backticks themselves must be escaped with a backtick itself: ``. We always treat two consecutive backticks as escaped backticks. An odd number of backticks will always lead to another backtick being inserted so that the single one will be escaped proper. As a concrete example this means an input like ``` will be sanitised and quoted as ``````. These are one leading and one closing backtick as this schema name needs to be quoted plus one more to escape the outlier. When used as a label or type, the resulting label will be ``.

This utility can be used standalone, the distributed module does not have any dependencies. Shading is ok as well, there is no encapsulation to break.

Since:
2022.8.0
Author:
Michael J. Simons
  • Method Details

    • sanitize

      public static Optional<String> sanitize(String value)
      Sanitizes the given input to be used as a valid schema name, adds quotes if necessary
      Parameters:
      value - The value to sanitize
      Returns:
      A value that is safe to be used in string concatenation, an empty optional indicates a value that cannot be safely quoted
    • sanitize

      public static Optional<String> sanitize(String value, boolean enforceQuotes)
      Sanitizes the given input to be used as a valid schema name
      Parameters:
      value - The value to sanitize
      enforceQuotes - If quotation should be enforced, even when not necessary
      Returns:
      A value that is safe to be used in string concatenation, an empty optional indicates a value that cannot be safely quoted
    • sanitize

      public static Optional<String> sanitize(String value, boolean enforceQuotes, int major, int minor)
      Sanitizes the given input to be used as a valid schema name
      Parameters:
      value - The value to sanitize
      enforceQuotes - If quotation should be enforced, even when not necessary
      major - Neo4j major version, use a value < 0 to assume the latest major version
      minor - Neo4j minor version, use a value < 0 to assume any minor version
      Returns:
      A value that is safe to be used in string concatenation, an empty optional indicates a value that cannot be safely quoted