Class QualifiedNameResolver
Object
gudusoft.gsqlparser.resolver2.model.QualifiedNameResolver
Service for normalizing table names into fully qualified names.
This class handles the conversion of potentially partial table names
(e.g., just "table", "schema.table", or "catalog.schema.table") into
fully qualified QualifiedName objects by applying default
catalog and schema from TSQLEnv.
Normalization Rules
| Input | Rule | Output |
|---|---|---|
| table | Apply both defaults | (defaultCatalog, defaultSchema, table) |
| schema.table | Apply catalog default only | (defaultCatalog, schema, table) |
| catalog.schema.table | No defaults applied | (catalog, schema, table) |
Usage Example
// Setup
TSQLEnv env = new TSQLEnv(EDbVendor.dbvmssql);
env.setDefaultCatalogName("mydb");
env.setDefaultSchemaName("dbo");
QualifiedNameResolver resolver = new QualifiedNameResolver(env, EDbVendor.dbvmssql);
// Normalize a simple table name
QualifiedName q1 = resolver.resolve(tableNode);
// Result: (mydb, dbo, tableName)
// Normalize a two-part name
QualifiedName q2 = resolver.resolve("sales", "orders");
// Result: (mydb, sales, orders)
// Three-part name is unchanged
QualifiedName q3 = resolver.resolve("otherdb", "hr", "employees");
// Result: (otherdb, hr, employees)
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionQualifiedNameResolver(TSQLEnv sqlEnv, EDbVendor vendor) Create a QualifiedNameResolver with the given SQL environment.QualifiedNameResolver(String defaultCatalog, String defaultSchema, EDbVendor vendor) Create a QualifiedNameResolver with explicit defaults. -
Method Summary
Modifier and TypeMethodDescriptionGet the current default catalog.Get the current default schema.booleanisSameTable(QualifiedName name1, QualifiedName name2) Check if two qualified names refer to the same table.booleanmatches(QualifiedName reference, QualifiedName target) Check if a qualified name matches a target name, considering defaults.resolve(TObjectName tableName) Resolve a TObjectName (table reference) to a fully qualified name.Resolve a TTable's name to a fully qualified name.Resolve a simple table name string to a fully qualified name.Create a qualified name from explicit parts with defaults applied.toString()
-
Constructor Details
-
QualifiedNameResolver
Create a QualifiedNameResolver with the given SQL environment.- Parameters:
sqlEnv- The SQL environment containing default catalog/schemavendor- The database vendor
-
QualifiedNameResolver
Create a QualifiedNameResolver with explicit defaults.- Parameters:
defaultCatalog- The default catalog namedefaultSchema- The default schema namevendor- The database vendor
-
-
Method Details
-
getDefaultCatalog
Get the current default catalog.If sqlEnv was provided, returns the current value from sqlEnv (which may have changed since construction).
-
getDefaultSchema
Get the current default schema.If sqlEnv was provided, returns the current value from sqlEnv (which may have changed since construction).
-
resolve
Resolve a TTable's name to a fully qualified name.- Parameters:
table- The table node from the AST- Returns:
- A normalized QualifiedName with defaults applied
-
resolve
Resolve a TObjectName (table reference) to a fully qualified name.- Parameters:
tableName- The table name node from the AST- Returns:
- A normalized QualifiedName with defaults applied
-
resolve
Resolve a simple table name string to a fully qualified name.- Parameters:
tableName- The table name (may include dots)- Returns:
- A normalized QualifiedName with defaults applied
-
resolve
Create a qualified name from explicit parts with defaults applied.- Parameters:
catalog- The catalog (null to use default)schema- The schema (null to use default)name- The table name (required)- Returns:
- A normalized QualifiedName
-
isSameTable
Check if two qualified names refer to the same table.Both names are first normalized using current defaults, then compared for equality.
- Parameters:
name1- First qualified name (may be partial)name2- Second qualified name (may be partial)- Returns:
- true if they refer to the same fully-qualified table
-
matches
Check if a qualified name matches a target name, considering defaults.- Parameters:
reference- The reference being checked (may be partial)target- The target table name (should be fully qualified)- Returns:
- true if the reference resolves to the target
-
toString
-