Class NameService
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 Summary
ConstructorsConstructorDescriptionNameService(EDbVendor vendor) Creates a new NameService for the specified database vendor. -
Method Summary
Modifier and TypeMethodDescriptioncreateSet(ESQLDataObjectType type) Creates a Set that uses vendor/type-aware name matching for equality.distinctCopy(ESQLDataObjectType type, Iterable<String> names) Creates a distinct copy of a collection, removing duplicates using vendor/type-aware matching.booleanequals(ESQLDataObjectType type, String name1, String name2) Checks if two names are equal according to vendor-specific and type-specific rules.Returns the database vendor associated with this service.intindexOf(ESQLDataObjectType type, Iterable<String> names, String target) Finds the index of a name in a collection, using vendor/type-aware matching.booleanChecks if a specific object type is case-sensitive for this vendor.
-
Constructor Details
-
NameService
Creates a new NameService for the specified database vendor.- Parameters:
vendor- the database vendor
-
-
Method Details
-
getVendor
Returns the database vendor associated with this service.- Returns:
- the database vendor
-
equals
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 comparename2- the second name to compare- Returns:
- true if the names match according to vendor/type rules
-
indexOf
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 typenames- the collection of names to searchtarget- 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 typenames- 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
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
-