Class QualifiedName

Object
gudusoft.gsqlparser.resolver2.model.QualifiedName

public class QualifiedName extends Object
Represents a fully qualified name for a database object (table, view, etc.).

A qualified name can be represented in two ways:

  1. As a list of parts (legacy mode) - for generic N-part names
  2. As explicit catalog/schema/name (structured mode) - for table names

For table names, the structured fields provide:

  • catalog (database) - The top-level container (e.g., "mydb")
  • schema - The schema within the catalog (e.g., "dbo", "public")
  • name - The object name itself (e.g., "users", "orders")

Usage Examples


 // Legacy list-based construction
 QualifiedName q1 = new QualifiedName("schema", "table");

 // Structured table name construction
 QualifiedName q2 = QualifiedName.forTable("mydb", "dbo", "users");

 // Apply defaults for unqualified names
 QualifiedName q3 = QualifiedName.forTable(null, null, "users")
     .withDefaults("mydb", "dbo");
 // Result: catalog=mydb, schema=dbo, name=users
 
See Also:
  • Constructor Details

    • QualifiedName

      public QualifiedName(List<String> parts)
      Create a qualified name from a list of parts (legacy mode).
    • QualifiedName

      public QualifiedName(String... parts)
      Create a qualified name from varargs parts (legacy mode).
  • Method Details

    • forTable

      public static QualifiedName forTable(String catalog, String schema, String tableName)
      Create a structured qualified name for a table.
      Parameters:
      catalog - The catalog/database name (nullable)
      schema - The schema name (nullable)
      tableName - The table name (required)
      Returns:
      A new QualifiedName in structured mode
    • forTable

      public static QualifiedName forTable(String tableName)
      Create a qualified name from just the table name.
    • forTable

      public static QualifiedName forTable(String schema, String tableName)
      Create a qualified name from schema and table name.
    • getParts

      public List<String> getParts()
    • getPartCount

      public int getPartCount()
    • getPart

      public String getPart(int index)
    • getFirstPart

      public String getFirstPart()
    • getLastPart

      public String getLastPart()
    • getCatalog

      public String getCatalog()
      Get the catalog (database) part. Only meaningful in structured mode.
    • getSchema

      public String getSchema()
      Get the schema part. Only meaningful in structured mode.
    • getTableName

      public String getTableName()
      Get the table name. In structured mode, returns the explicit table name. In legacy mode, returns the last part.
    • getName

      public String getName()
      Alias for getTableName() - returns the object name.
    • isStructuredMode

      public boolean isStructuredMode()
      Check if this instance uses structured mode.
    • hasCatalog

      public boolean hasCatalog()
      Check if this qualified name has a catalog specified.
    • hasSchema

      public boolean hasSchema()
      Check if this qualified name has a schema specified.
    • isFullyQualified

      public boolean isFullyQualified()
      Check if this is a fully qualified name (all three parts in structured mode).
    • removeFirst

      Returns a new qualified name with the first part removed (legacy mode).
    • prepend

      public QualifiedName prepend(String part)
      Returns a new qualified name with an additional part prepended (legacy mode).
    • append

      public QualifiedName append(String part)
      Returns a new qualified name with an additional part appended (legacy mode).
    • withDefaults

      public QualifiedName withDefaults(String defaultCatalog, String defaultSchema)
      Create a new qualified name by filling in missing parts from defaults.

      This does NOT override existing parts - it only fills in nulls. Only works in structured mode.

      Parameters:
      defaultCatalog - The default catalog to use if this.catalog is null
      defaultSchema - The default schema to use if this.schema is null
      Returns:
      A new qualified name with defaults applied
    • toFullyQualified

      public QualifiedName toFullyQualified(String defaultCatalog, String defaultSchema)
      Create a fully qualified name by applying defaults for all missing parts.
      Parameters:
      defaultCatalog - The default catalog
      defaultSchema - The default schema
      Returns:
      A fully qualified name (all three parts set)
    • matches

      public boolean matches(QualifiedName other, INameMatcher matcher)
      Check if this qualified name matches another, using the given name matcher.

      Matching rules:

      • Object names must always match
      • If both have schemas, they must match
      • If both have catalogs, they must match
      • Missing parts (null) are treated as wildcards
      Parameters:
      other - The other qualified name to compare
      matcher - The name matcher for comparison (handles case sensitivity)
      Returns:
      true if the names match according to the rules
    • matchesExact

      public boolean matchesExact(QualifiedName other, INameMatcher matcher)
      Check exact match (all parts must match, including nulls).
    • toNormalizedKey

      Create a key suitable for use in maps/sets.

      The key is lowercase and includes all three parts separated by null characters to ensure uniqueness.

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toStringWithPlaceholders

      public String toStringWithPlaceholders(String catalogPlaceholder, String schemaPlaceholder)
      Convert to a fully qualified string representation, using placeholders for missing parts.
      Parameters:
      catalogPlaceholder - Placeholder for missing catalog (e.g., "*" or "?")
      schemaPlaceholder - Placeholder for missing schema
      Returns:
      String like "*.*.name" or "catalog.*.name"
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equalsIgnoreCase

      public boolean equalsIgnoreCase(QualifiedName other)
      Check equality ignoring case.
      Parameters:
      other - The other qualified name
      Returns:
      true if all parts match (ignoring case)