File tree 2 files changed +11
-17
lines changed
main/java/org/mybatis/dynamic/sql/exception
2 files changed +11
-17
lines changed Original file line number Diff line number Diff line change 32
32
*/
33
33
public class DuplicateTableAliasException extends RuntimeException {
34
34
35
- private final SqlTable table ;
36
- private final String newAlias ;
37
- private final String existingAlias ;
38
-
39
35
public DuplicateTableAliasException (SqlTable table , String newAlias , String existingAlias ) {
40
- this . table = Objects .requireNonNull (table );
41
- this . newAlias = Objects .requireNonNull (newAlias );
42
- this . existingAlias = Objects .requireNonNull (existingAlias );
36
+ super ( generateMessage ( Objects .requireNonNull (table ),
37
+ Objects .requireNonNull (newAlias ),
38
+ Objects .requireNonNull (existingAlias )) );
43
39
}
44
40
45
- @ Override
46
- public String getMessage () {
41
+ private static String generateMessage (SqlTable table , String newAlias , String existingAlias ) {
47
42
return "Table \" " + table .tableNameAtRuntime () //$NON-NLS-1$
48
43
+ "\" with requested alias \" " + newAlias //$NON-NLS-1$
49
44
+ "\" is already aliased in this query with alias \" " + existingAlias //$NON-NLS-1$
Original file line number Diff line number Diff line change 44
44
import org .junit .jupiter .api .Test ;
45
45
import org .mybatis .dynamic .sql .exception .DuplicateTableAliasException ;
46
46
import org .mybatis .dynamic .sql .render .RenderingStrategies ;
47
+ import org .mybatis .dynamic .sql .select .QueryExpressionDSL ;
48
+ import org .mybatis .dynamic .sql .select .SelectModel ;
47
49
import org .mybatis .dynamic .sql .select .render .SelectStatementProvider ;
48
50
import org .mybatis .dynamic .sql .util .mybatis3 .CommonSelectMapper ;
49
51
@@ -948,14 +950,11 @@ void testSelf() {
948
950
949
951
@ Test
950
952
void testSelfWithDuplicateAlias () {
951
- assertThatExceptionOfType (DuplicateTableAliasException .class ).isThrownBy (() ->
952
- select (user .userId , user .userName , user .parentId )
953
- .from (user , "u1" )
954
- .join (user , "u2" ).on (user .userId , equalTo (user .parentId ))
955
- .where (user .userId , isEqualTo (4 ))
956
- .build ()
957
- .render (RenderingStrategies .MYBATIS3 )
958
- ).withMessage ("Table \" User\" with requested alias \" u2\" is already aliased in this query with alias \" u1\" . Attempting to re-alias a table in the same query is not supported." );
953
+ QueryExpressionDSL <SelectModel > dsl = select (user .userId , user .userName , user .parentId )
954
+ .from (user , "u1" );
955
+
956
+ assertThatExceptionOfType (DuplicateTableAliasException .class ).isThrownBy (() -> dsl .join (user , "u2" ))
957
+ .withMessage ("Table \" User\" with requested alias \" u2\" is already aliased in this query with alias \" u1\" . Attempting to re-alias a table in the same query is not supported." );
959
958
}
960
959
961
960
@ Test
You can’t perform that action at this time.
0 commit comments