001package gudusoft.gsqlparser.ir.semantic; 002 003import gudusoft.gsqlparser.ir.semantic.binding.RelationBinding; 004 005/** 006 * One visible relation source in a statement's scope. {@link #alias} is 007 * non-null and defaults to the table name when the SQL omits an alias, so 008 * consumers always have a stable local handle to use in 009 * {@link ColumnRef#getRelationAlias()}. 010 * 011 * <p>For most kinds (TABLE / CTE / SUBQUERY / UNION) the source is a 012 * FROM-clause entry on this statement. For 013 * {@link RelationKind#OUTER_REFERENCE} (slice 14) the source is 014 * synthesised by the builder to record an alias that actually belongs to 015 * an enclosing scope's FROM clause; the inner statement carries it so 016 * {@link ColumnRef#getRelationAlias()} resolves uniformly without needing 017 * an explicit "is-outer" flag. 018 */ 019public final class RelationSource { 020 021 private final String alias; 022 private final RelationBinding binding; 023 024 public RelationSource(String alias, RelationBinding binding) { 025 if (alias == null || alias.isEmpty()) { 026 throw new IllegalArgumentException("alias must be non-empty"); 027 } 028 if (binding == null) { 029 throw new IllegalArgumentException("binding must not be null"); 030 } 031 this.alias = alias; 032 this.binding = binding; 033 } 034 035 public String getAlias() { 036 return alias; 037 } 038 039 public RelationBinding getBinding() { 040 return binding; 041 } 042}