1
1
/*
2
- * Copyright 2012-2022 the original author or authors.
2
+ * Copyright 2012-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import java .util .Map ;
21
21
22
22
import org .apache .ibatis .mapping .ParameterMapping ;
23
+ import org .apache .ibatis .mapping .ParameterMode ;
24
+ import org .apache .ibatis .reflection .MetaObject ;
25
+ import org .apache .ibatis .reflection .property .PropertyTokenizer ;
23
26
import org .apache .ibatis .session .Configuration ;
24
27
25
28
public class ParameterMappingCollector {
@@ -28,15 +31,16 @@ public class ParameterMappingCollector {
28
31
private final List <ParameterMapping > parameterMappings = new ArrayList <>();
29
32
private final Map <String , Object > context ;
30
33
private final Configuration configuration ;
34
+ private final MetaObject metaParameters ;
31
35
32
- private int uid = 0 ;
33
36
private String itemKey ;
34
37
35
38
public ParameterMappingCollector (ParameterMapping [] newParameterMappingSources , Map <String , Object > newContext ,
36
39
Configuration newConfiguration ) {
37
40
this .parameterMappingSources = newParameterMappingSources ;
38
41
this .context = newContext ;
39
42
this .configuration = newConfiguration ;
43
+ this .metaParameters = configuration .newMetaObject (newContext );
40
44
}
41
45
42
46
public void setItemKey (String value ) {
@@ -49,54 +53,36 @@ public String getItemKey() {
49
53
50
54
public String g (int mapping ) {
51
55
ParameterMapping parameterMapping = this .parameterMappingSources [mapping ];
52
- PropertyInfo vi = getPropertyInfo (parameterMapping .getProperty ());
53
- if (vi .isIterable ) {
54
- parameterMapping = itemize (parameterMapping , vi );
55
- this .context .put (vi .root , this .context .get (this .itemKey ));
56
- }
57
- this .parameterMappings .add (parameterMapping );
56
+ this .parameterMappings .add (mappingWithValue (parameterMapping ));
58
57
return "?" ;
59
58
}
60
59
61
60
public List <ParameterMapping > getParameterMappings () {
62
61
return this .parameterMappings ;
63
62
}
64
63
65
- private ParameterMapping itemize (ParameterMapping source , PropertyInfo var ) {
66
- StringBuilder sb = new StringBuilder ().append ("_RPTITEM_" ).append (this .uid ++);
67
- var .root = sb .toString ();
68
- String propertyName = sb .append (var .path ).toString ();
69
- ParameterMapping .Builder builder = new ParameterMapping .Builder (this .configuration , propertyName ,
70
- source .getJavaType ());
64
+ private ParameterMapping mappingWithValue (ParameterMapping source ) {
65
+ String property = source .getProperty ();
66
+ ParameterMapping .Builder builder = new ParameterMapping .Builder (this .configuration , property , source .getJavaType ());
71
67
builder .expression (source .getExpression ()).jdbcType (source .getJdbcType ()).jdbcTypeName (source .getJdbcTypeName ())
72
68
.mode (source .getMode ()).numericScale (source .getNumericScale ()).resultMapId (source .getResultMapId ())
73
69
.typeHandler (source .getTypeHandler ());
74
- return builder .build ();
75
- }
76
70
77
- private PropertyInfo getPropertyInfo (String name ) {
78
- PropertyInfo i = new PropertyInfo ();
79
- if (name != null ) {
80
- int p = name .indexOf ('.' );
81
- if (p == -1 ) {
82
- i .root = name ;
71
+ PropertyTokenizer propertyTokenizer = new PropertyTokenizer (property );
72
+ Object parameterObject = context .get (SQLScriptSource .PARAMETER_OBJECT_KEY );
73
+ if (!ParameterMode .OUT .equals (source .getMode ())) {
74
+ if (metaParameters .hasGetter (propertyTokenizer .getName ())) {
75
+ builder .value (metaParameters .getValue (property ));
76
+ } else if (parameterObject == null ) {
77
+ builder .value (null );
78
+ } else if (configuration .getTypeHandlerRegistry ().hasTypeHandler (parameterObject .getClass ())) {
79
+ builder .value (parameterObject );
83
80
} else {
84
- i . root = name . substring ( 0 , p );
85
- i . path = name . substring ( p );
81
+ MetaObject metaObject = configuration . newMetaObject ( parameterObject );
82
+ builder . value ( metaObject . getValue ( property ) );
86
83
}
87
84
}
88
- i .isIterable = this .itemKey != null && this .itemKey .equals (i .root );
89
- return i ;
90
- }
91
-
92
- static class PropertyInfo {
93
- boolean isIterable = false ;
94
- String root = "" ;
95
- String path = "" ;
96
-
97
- public PropertyInfo () {
98
- // Prevent synthetic access
99
- }
85
+ return builder .build ();
100
86
}
101
87
102
88
}
0 commit comments