Class PlsqlVariableNamespace

Object
gudusoft.gsqlparser.resolver2.namespace.PlsqlVariableNamespace
All Implemented Interfaces:
INamespace

public class PlsqlVariableNamespace extends Object implements INamespace
Namespace representing PL/SQL variables declared in a block.

PL/SQL blocks (<

 <<main>>
 DECLARE
   ename VARCHAR2(10) := 'KING';
 BEGIN
   DELETE FROM emp WHERE ename = main.ename;  -- main.ename is the variable
 END;
 

This namespace allows the resolver to distinguish between PL/SQL variables (like main.ename) and table columns (like emp.ename) by registering the block's variables as a namespace that can be queried by the block's label.

  • Constructor Details

    • PlsqlVariableNamespace

      public PlsqlVariableNamespace(String blockLabel)
      Create a new PL/SQL variable namespace for a labeled block.
      Parameters:
      blockLabel - The block label (e.g., "main" from <
      >)
  • Method Details

    • addVariable

      public void addVariable(TVarDeclStmt varDecl)
      Add a variable declaration to this namespace.
      Parameters:
      varDecl - The variable declaration statement
    • addParameter

      public void addParameter(String paramName)
      Add a procedure/function parameter to this namespace. Parameters are tracked separately from variables since they don't need ColumnSource lineage - we only need to know if a name is a parameter to filter it from column reference collection.
      Parameters:
      paramName - The parameter name (as String)
    • hasVariable

      public boolean hasVariable(String variableName)
      Check if a variable with the given name exists in this block.
      Parameters:
      variableName - The variable name to check
      Returns:
      true if the variable exists
    • getDisplayName

      Description copied from interface: INamespace
      Get a display name for this namespace (for debugging/error messages)
      Specified by:
      getDisplayName in interface INamespace
    • hasParameter

      public boolean hasParameter(String name)
      Check if a name is a parameter.
      Parameters:
      name - The name to check
      Returns:
      true if the name is a registered parameter
    • hasColumn

      public ColumnLevel hasColumn(String columnName)
      Description copied from interface: INamespace
      Check if a column exists in this namespace. Returns a three-level answer: EXISTS, MAYBE, NOT_EXISTS
      Specified by:
      hasColumn in interface INamespace
      Parameters:
      columnName - Column name to check
      Returns:
      Column existence level
    • resolveColumn

      public ColumnSource resolveColumn(String columnName)
      Description copied from interface: INamespace
      Resolve a column name to its source.
      Specified by:
      resolveColumn in interface INamespace
      Parameters:
      columnName - Column name to resolve
      Returns:
      ColumnSource if found, null otherwise
    • getAllColumnSources

      Description copied from interface: INamespace
      Get all column sources exposed by this namespace. Used for SELECT * expansion and smart completion.
      Specified by:
      getAllColumnSources in interface INamespace
      Returns:
      Map of column name -> ColumnSource
    • getFinalTable

      Description copied from interface: INamespace
      Get the final physical table this namespace represents. For tables: returns the table itself For subqueries/CTEs: recursively traces back to physical table(s)
      Specified by:
      getFinalTable in interface INamespace
      Returns:
      Physical table, or null if not determinable
    • getAllFinalTables

      Description copied from interface: INamespace
      Get all final physical tables this namespace depends on. For simple table namespace: returns single table For subquery/CTE: returns all tables in the query tree
      Specified by:
      getAllFinalTables in interface INamespace
      Returns:
      List of all physical tables
    • isValidated

      public boolean isValidated()
      Description copied from interface: INamespace
      Check if this namespace is validated/resolved. Some namespaces require resolution before they can provide column info.
      Specified by:
      isValidated in interface INamespace
      Returns:
      true if validated
    • validate

      public void validate()
      Description copied from interface: INamespace
      Validate/resolve this namespace. For subqueries: resolve the SELECT list For tables: load metadata if needed
      Specified by:
      validate in interface INamespace
    • getNode

      public Object getNode()
      Description copied from interface: INamespace
      Get the associated AST node (TTable, TSelectSqlStatement, etc.)
      Specified by:
      getNode in interface INamespace
      Returns:
      AST node, or null if not applicable
    • getBlockLabel

      Get the block label.
      Returns:
      The block label
    • getVariables

      Get all variable declarations in this block.
      Returns:
      Unmodifiable map of variable name -> declaration
    • toString

      public String toString()
      Overrides:
      toString in class Object