17
17
18
18
import java .util .ArrayList ;
19
19
import java .util .List ;
20
- import java .util .concurrent .atomic .AtomicBoolean ;
21
20
22
21
import org .springframework .beans .factory .InitializingBean ;
23
22
import org .springframework .data .convert .PropertyValueConverterFactories .ChainedPropertyValueConverterFactory ;
@@ -40,7 +39,6 @@ public class SimplePropertyValueConversions implements PropertyValueConversions,
40
39
private @ Nullable PropertyValueConverterFactory converterFactory ;
41
40
private @ Nullable ValueConverterRegistry <?> valueConverterRegistry ;
42
41
private boolean converterCacheEnabled = true ;
43
- private final AtomicBoolean initialized = new AtomicBoolean (false );
44
42
45
43
/**
46
44
* Set the {@link PropertyValueConverterFactory factory} responsible for creating the actual
@@ -91,23 +89,13 @@ public void setConverterCacheEnabled(boolean converterCacheEnabled) {
91
89
92
90
@ Override
93
91
public boolean hasValueConverter (PersistentProperty <?> property ) {
94
-
95
- if (!initialized .get ()) {
96
- init ();
97
- }
98
-
99
92
return this .converterFactory .getConverter (property ) != null ;
100
93
}
101
94
102
95
@ Nullable
103
96
@ Override
104
97
public <DV , SV , C extends PersistentProperty <C >, D extends ValueConversionContext <C >> PropertyValueConverter <DV , SV , D > getValueConverter (
105
98
C property ) {
106
-
107
- if (!initialized .get ()) {
108
- init ();
109
- }
110
-
111
99
return this .converterFactory .getConverter (property );
112
100
}
113
101
@@ -116,27 +104,24 @@ public <DV, SV, C extends PersistentProperty<C>, D extends ValueConversionContex
116
104
*/
117
105
public void init () {
118
106
119
- if (initialized .compareAndSet (false , true )) {
120
-
121
- List <PropertyValueConverterFactory > factoryList = new ArrayList <>(3 );
107
+ List <PropertyValueConverterFactory > factoryList = new ArrayList <>(3 );
122
108
123
- if (converterFactory != null ) {
124
- factoryList .add (converterFactory );
125
- } else {
126
- factoryList .add (PropertyValueConverterFactory .simple ());
127
- }
109
+ if (converterFactory != null ) {
110
+ factoryList .add (converterFactory );
111
+ } else {
112
+ factoryList .add (PropertyValueConverterFactory .simple ());
113
+ }
128
114
129
- if ((valueConverterRegistry != null ) && !valueConverterRegistry .isEmpty ()) {
130
- factoryList .add (PropertyValueConverterFactory .configuredInstance (valueConverterRegistry ));
131
- }
115
+ if ((valueConverterRegistry != null ) && !valueConverterRegistry .isEmpty ()) {
116
+ factoryList .add (PropertyValueConverterFactory .configuredInstance (valueConverterRegistry ));
117
+ }
132
118
133
- PropertyValueConverterFactory targetFactory = factoryList .size () > 1
134
- ? PropertyValueConverterFactory .chained (factoryList )
135
- : factoryList .iterator ().next ();
119
+ PropertyValueConverterFactory targetFactory = factoryList .size () > 1
120
+ ? PropertyValueConverterFactory .chained (factoryList )
121
+ : factoryList .iterator ().next ();
136
122
137
- this .converterFactory = converterCacheEnabled ? PropertyValueConverterFactory .caching (targetFactory )
138
- : targetFactory ;
139
- }
123
+ this .converterFactory = converterCacheEnabled ? PropertyValueConverterFactory .caching (targetFactory )
124
+ : targetFactory ;
140
125
}
141
126
142
127
@ Override
0 commit comments