21
21
import org .apache .seata .common .util .CollectionUtils ;
22
22
import org .apache .seata .common .util .StringUtils ;
23
23
import org .apache .seata .rm .tcc .api .ParamType ;
24
+ import org .slf4j .Logger ;
25
+ import org .slf4j .LoggerFactory ;
24
26
25
27
import javax .annotation .Nonnull ;
26
28
import javax .annotation .Nullable ;
29
+ import java .util .List ;
27
30
import java .util .Map ;
28
31
29
- import static org .apache .seata .integration .tx .api .interceptor .ActionContextUtil .getByIndex ;
30
-
31
32
/**
32
33
* Extracting TCC Context from Method
33
34
*/
@@ -36,6 +37,8 @@ public final class ActionContextUtil {
36
37
private ActionContextUtil () {
37
38
}
38
39
40
+ private static final Logger LOGGER = LoggerFactory .getLogger (ActionContextUtil .class );
41
+
39
42
/**
40
43
* Extracting context data from parameters
41
44
*
@@ -86,6 +89,29 @@ public static void loadParamByAnnotationAndPutToContext(@Nonnull final ParamType
86
89
}
87
90
}
88
91
92
+ @ Nullable
93
+ private static Object getByIndex (@ Nonnull ParamType paramType , @ Nonnull String paramName , @ Nonnull Object paramValue , int index ) {
94
+ if (paramValue instanceof List ) {
95
+ @ SuppressWarnings ("unchecked" )
96
+ List <Object > list = (List <Object >) paramValue ;
97
+ if (list .isEmpty ()) {
98
+ return null ;
99
+ }
100
+ if (list .size () <= index ) {
101
+ if (LOGGER .isDebugEnabled ()) {
102
+ LOGGER .debug ("The index '{}' is out of bounds for the list {} named '{}'," +
103
+ " whose size is '{}', so pass this {}" , index , paramType .getCode (), paramName , list .size (), paramType .getCode ());
104
+ }
105
+ return null ;
106
+ }
107
+ paramValue = list .get (index );
108
+ } else {
109
+ LOGGER .warn ("the {} named '{}' is not a `List`, so the 'index' field of '@{}' cannot be used on it" ,
110
+ paramType .getCode (), paramName , BusinessActionContextParameter .class .getSimpleName ());
111
+ }
112
+
113
+ return paramValue ;
114
+ }
89
115
90
116
public static String getParamNameFromAnnotation (@ Nonnull BusinessActionContextParameter annotation ) {
91
117
String paramName = annotation .paramName ();
0 commit comments