Skip to content

Commit 4ad229e

Browse files
committed
refactor: clarify table identifier copying responsibilities
1 parent 7fa9a39 commit 4ad229e

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/main/java/net/sf/jsqlparser/schema/Table.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -521,15 +521,16 @@ public Table getResolvedTable() {
521521
}
522522

523523
/**
524-
* Sets resolved table.
524+
* Stores a detached copy of the resolved table's identifier. Reference-specific flags and
525+
* clauses are not copied.
525526
*
526527
* @param resolvedTable the resolved table
527528
* @return this table
528529
*/
529530
public Table setResolvedTable(Table resolvedTable) {
530-
// clone, not reference
531531
if (resolvedTable != null) {
532-
this.resolvedTable = resolvedTable.copyName();
532+
this.resolvedTable = new Table();
533+
resolvedTable.copyIdentifierPartsTo(this.resolvedTable);
533534
}
534535
return this;
535536
}
@@ -577,18 +578,19 @@ public static Table[] setUnsetCatalogAndSchema(String currentCatalogName,
577578
return tables;
578579
}
579580

581+
/** Copies the table identifier, table-variable flag and resolved table identifier. */
580582
@Override
581583
public Table clone() {
582-
Table clone = copyName();
584+
Table clone = new Table();
585+
copyIdentifierPartsTo(clone);
583586
clone.setTableVariable(tableVariable);
584587
clone.setResolvedTable(this.resolvedTable != null ? this.resolvedTable.clone() : null);
585588
return clone;
586589
}
587590

588-
private Table copyName() {
589-
Table copy = new Table();
590-
copy.partItems = new ArrayList<>(partItems);
591-
copy.partDelimiters = new ArrayList<>(partDelimiters);
592-
return copy;
591+
/** Copies identifier components and separators, leaving the target's other state unchanged. */
592+
private void copyIdentifierPartsTo(Table target) {
593+
target.partItems = new ArrayList<>(partItems);
594+
target.partDelimiters = new ArrayList<>(partDelimiters);
593595
}
594596
}

0 commit comments

Comments
 (0)