Skip to content

Commit 9c900bd

Browse files
committed
Note to future self about a difficult method
1 parent 6bf1c05 commit 9c900bd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/main/java/org/mybatis/dynamic/sql/select/render/QueryExpressionRenderer.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@ private QueryExpressionRenderer(Builder builder) {
5858
.build();
5959
}
6060

61+
/**
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.
65+
*
66+
* <p>In the case of "exists" conditions, we will have a parent table alias calculator. We want to give visibility
67+
* to the aliases in the outer select statement to this renderer so columns in aliased tables can be used in exists
68+
* conditions without having to re-specify the alias.
69+
*
70+
* <p>Another complication is that we calculate aliases differently if there are joins and sub queries. The
71+
* cases are as follows:
72+
*
73+
* <ol>
74+
* <li>If there are no joins, then we will only use aliases that are explicitly set by the user</li>
75+
* <lI>If there are joins and sub queries, we will also only use explicit aliases</lI>
76+
* <li>If there are joins, but no sub queries, then we will automatically use the table name
77+
* as an alias if no explicit alias has been specified</li>
78+
* </ol>
79+
*
80+
* @param queryExpression the model to render
81+
* @param parentTableAliasCalculator table alias calculator from the parent query
82+
* @return a table alias calculator appropriate for this context
83+
*/
6184
private TableAliasCalculator calculateTableAliasCalculator(QueryExpressionModel queryExpression,
6285
TableAliasCalculator parentTableAliasCalculator) {
6386
TableAliasCalculator baseTableAliasCalculator = queryExpression.joinModel()

0 commit comments

Comments
 (0)