001package gudusoft.gsqlparser.dlineage.util;
002
003import gudusoft.gsqlparser.sqlenv.QualifiedCanonKey;
004
005/**
006 * The lineage model's key for a physical table: the analysis's own identity for the name, plus
007 * the legacy folded name the rest of dlineage still binds and looks up.
008 *
009 * <p>Equality is the canonical key alone, so two spellings the analysis's
010 * {@link gudusoft.gsqlparser.sqlenv.IdentifierProfile} calls one table share a model, and two it
011 * keeps apart get two, even when the legacy fold (vendor default rules) makes them one string.
012 * The legacy name travels along only so bindings reachable by name — variables, cursors,
013 * qualifier strings — keep working; it never decides table identity.
014 */
015public final class TableIdentityKey {
016
017    private final QualifiedCanonKey canonKey;
018    private final String legacyKey;
019
020    public TableIdentityKey(QualifiedCanonKey canonKey, String legacyKey) {
021        if (canonKey == null) {
022            throw new IllegalArgumentException("canonKey");
023        }
024        this.canonKey = canonKey;
025        this.legacyKey = legacyKey;
026    }
027
028    public QualifiedCanonKey getCanonKey() {
029        return canonKey;
030    }
031
032    /** The vendor-default folded name bound alongside; may be null. */
033    public String getLegacyKey() {
034        return legacyKey;
035    }
036
037    @Override
038    public boolean equals(Object o) {
039        return this == o || (o instanceof TableIdentityKey && canonKey.equals(((TableIdentityKey) o).canonKey));
040    }
041
042    @Override
043    public int hashCode() {
044        return canonKey.hashCode();
045    }
046
047    @Override
048    public String toString() {
049        return canonKey + " (legacy " + legacyKey + ")";
050    }
051}