Class NameService

Object
gudusoft.gsqlparser.sqlenv.calcite.NameService

public class NameService extends Object
Centralized name matching service using Apache Calcite's SqlNameMatcher framework.

This service provides vendor-aware and type-aware name comparison utilities, replacing scattered string comparisons throughout GSP with a unified approach.

Key responsibilities:

  • Name equality checking (case-sensitive or insensitive per vendor/type)
  • Case-aware collection operations (indexOf, distinct, Set creation)
  • Bridge between GSP's normalization rules and Calcite's matching framework

Design: This service delegates to NamePolicyFactory for matcher instances and preserves TSQLEnv.normalizeIdentifier(gudusoft.gsqlparser.sqlenv.ESQLDataObjectType, java.lang.String) as the authority for identifier quoting and default-case normalization.

Since:
3.2.0.3 (Phase 1)
  • Constructor Details

    • NameService

      public NameService(EDbVendor vendor)
      Creates a new NameService for the specified database vendor.
      Parameters:
      vendor - the database vendor
  • Method Details

    • getVendor

      public EDbVendor getVendor()
      Returns the database vendor associated with this service.
      Returns:
      the database vendor
    • equals

      public boolean equals(ESQLDataObjectType type, String name1, String name2)
      Checks if two names are equal according to vendor-specific and type-specific rules.

      This method replaces TSQLEnv.compareIdentifier() with a more robust implementation backed by Calcite's SqlNameMatcher framework.

      Names are normalized using GSP's existing rules before matching.

      Parameters:
      type - the SQL object type (table, column, function, etc.)
      name1 - the first name to compare
      name2 - the second name to compare
      Returns:
      true if the names match according to vendor/type rules
    • indexOf

      public int indexOf(ESQLDataObjectType type, Iterable<String> names, String target)
      Finds the index of a name in a collection, using vendor/type-aware matching.

      This is a case-aware version of List.indexOf().

      Parameters:
      type - the SQL object type
      names - the collection of names to search
      target - the name to find
      Returns:
      the index of the first matching name, or -1 if not found
    • distinctCopy

      Creates a distinct copy of a collection, removing duplicates using vendor/type-aware matching.

      Preserves insertion order. For example, with case-insensitive matching:

       ["foo", "FOO", "bar", "Bar"] → ["foo", "bar"]
       
      Parameters:
      type - the SQL object type
      names - the collection of names (may contain duplicates)
      Returns:
      a new list with duplicates removed, preserving order
    • createSet

      Creates a Set that uses vendor/type-aware name matching for equality.

      The returned Set will treat names as equal if they match according to the vendor's case sensitivity rules for the specified object type.

      Implementation note: Uses a wrapper around LinkedHashSet that normalizes keys before insertion/lookup.

      Parameters:
      type - the SQL object type
      Returns:
      a new Set with case-aware equality
    • isCaseSensitive

      public boolean isCaseSensitive(ESQLDataObjectType type)
      Checks if a specific object type is case-sensitive for this vendor.

      Convenience method that delegates to NamePolicyFactory.

      Parameters:
      type - the object type
      Returns:
      true if case-sensitive, false otherwise