File tree Expand file tree Collapse file tree 2 files changed +30
-7
lines changed
src/main/java/org/mybatis/dynamic/sql Expand file tree Collapse file tree 2 files changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -24,9 +24,9 @@ public class TableAliasCalculatorWithParent implements TableAliasCalculator {
2424 private final TableAliasCalculator parent ;
2525 private final TableAliasCalculator child ;
2626
27- public TableAliasCalculatorWithParent (TableAliasCalculator parent , TableAliasCalculator child ) {
28- this . parent = Objects .requireNonNull (parent );
29- this . child = Objects .requireNonNull (child );
27+ private TableAliasCalculatorWithParent (Builder builder ) {
28+ parent = Objects .requireNonNull (builder . parent );
29+ child = Objects .requireNonNull (builder . child );
3030 }
3131
3232 @ Override
@@ -46,4 +46,23 @@ public Optional<String> aliasForTable(SqlTable table) {
4646 }
4747 return parent .aliasForTable (table );
4848 }
49+
50+ public static class Builder {
51+ private TableAliasCalculator parent ;
52+ private TableAliasCalculator child ;
53+
54+ public Builder withParent (TableAliasCalculator parent ) {
55+ this .parent = parent ;
56+ return this ;
57+ }
58+
59+ public Builder withChild (TableAliasCalculator child ) {
60+ this .child = child ;
61+ return this ;
62+ }
63+
64+ public TableAliasCalculatorWithParent build () {
65+ return new TableAliasCalculatorWithParent (this );
66+ }
67+ }
4968}
Original file line number Diff line number Diff line change @@ -59,9 +59,10 @@ private QueryExpressionRenderer(Builder builder) {
5959 }
6060
6161 /**
62- * This function calculates a table alias calculator to use in the current context. In general,
63- * there are two possibilities: this could be a renderer for a regular select statement, or it
64- * could be a renderer for a select statement in an "exists" condition.
62+ * This function calculates a table alias calculator to use in the current context. There are several
63+ * possibilities: this could be a renderer for a regular select statement, or it could be a renderer for a table
64+ * expression in a join, or a column to sub query where condition, or it could be a renderer for a select
65+ * statement in an "exists" condition.
6566 *
6667 * <p>In the case of "exists" conditions, we will have a parent table alias calculator. We want to give visibility
6768 * to the aliases in the outer select statement to this renderer so columns in aliased tables can be used in exists
@@ -91,7 +92,10 @@ private TableAliasCalculator calculateTableAliasCalculator(QueryExpressionModel
9192 if (parentTableAliasCalculator == null ) {
9293 return baseTableAliasCalculator ;
9394 } else {
94- return new TableAliasCalculatorWithParent (parentTableAliasCalculator , baseTableAliasCalculator );
95+ return new TableAliasCalculatorWithParent .Builder ()
96+ .withParent (parentTableAliasCalculator )
97+ .withChild (baseTableAliasCalculator )
98+ .build ();
9599 }
96100 }
97101
You can’t perform that action at this time.
0 commit comments