@@ -43,41 +43,57 @@ public static List<VariablePlaceholder> resolve(SqlDialect sqlDialect, String sr
4343 return Collections .emptyList ();
4444 }
4545
46- List <VariablePlaceholder > placeholders = new LinkedList <>();
4746 Matcher matcher = Const .VARIABLE_PATTERN .matcher (srcSql );
47+ Map <String , ScriptVariable > variablePlaceholderMap = new HashMap <>();
4848 while (matcher .find ()) {
4949 String group = matcher .group ();
5050 ScriptVariable scriptVariable = variableMap .get (group );
51- placeholders .add (createPlaceholder (sqlDialect , srcSql , group , scriptVariable ));
51+ variablePlaceholderMap .put (group , scriptVariable );
52+ }
53+ if (variablePlaceholderMap .isEmpty ()) {
54+ return Collections .emptyList ();
55+ }
56+
57+
58+ List <VariablePlaceholder > placeholders = new LinkedList <>();
59+ for (Map .Entry <String , ScriptVariable > entry : variablePlaceholderMap .entrySet ()) {
60+ placeholders .addAll (createPlaceholder (sqlDialect , srcSql , entry .getKey (), entry .getValue ()));
5261 }
5362 return placeholders ;
5463
5564 }
5665
57- private static VariablePlaceholder createPlaceholder (SqlDialect sqlDialect , String sql , String variableFragment , ScriptVariable variable ) {
66+ private static List < VariablePlaceholder > createPlaceholder (SqlDialect sqlDialect , String sql , String variableFragment , ScriptVariable variable ) {
5867
59- String variableExpression = tryMatchVariableExpression ( sql , variableFragment );
68+ List < VariablePlaceholder > placeholders = new LinkedList <>( );
6069
61- SqlCall sqlCall = parseAsSqlCall ( variableExpression , variableFragment );
70+ List < String > variableExpressions = tryMatchVariableExpression ( sql , variableFragment );
6271
63- if (sqlCall == null ) {
64- return new SimpleVariablePlaceholder (variable , sqlDialect , variableFragment );
65- } else {
66- return new VariablePlaceholder (Collections .singletonList (variable ), sqlDialect , sqlCall , variableExpression );
72+ if (!CollectionUtils .isEmpty (variableExpressions )) {
73+ for (String expression : variableExpressions ) {
74+ SqlCall sqlCall = parseAsSqlCall (expression , variableFragment );
75+ if (sqlCall != null ) {
76+ placeholders .add (new VariablePlaceholder (Collections .singletonList (variable ), sqlDialect , sqlCall , expression ));
77+ } else {
78+ placeholders .add (new SimpleVariablePlaceholder (variable , sqlDialect , variableFragment ));
79+ }
80+ }
6781 }
68-
82+ return placeholders ;
6983 }
7084
7185
72- private static String tryMatchVariableExpression (String sql , String variableFragment ) {
86+ private static List < String > tryMatchVariableExpression (String sql , String variableFragment ) {
7387 String reg = String .format (REG_VARIABLE_EXPRESSION_TEMPLATE , variableFragment .replace ("$" , "\\ $" ));
7488 Pattern pattern = Pattern .compile (reg , Pattern .CASE_INSENSITIVE );
7589 Matcher matcher = pattern .matcher (sql );
76- if (matcher .find ()) {
77- return matcher .group ();
78- } else {
79- return null ;
90+
91+ List <String > expressions = new LinkedList <>();
92+
93+ while (matcher .find ()) {
94+ expressions .add (matcher .group ());
8095 }
96+ return expressions ;
8197 }
8298
8399 public static SqlCall parseAsSqlCall (String variableExpression , String variableFragment ) {
0 commit comments