8
8
9
9
import java .lang .reflect .Constructor ;
10
10
import java .util .ArrayList ;
11
- import java .util .Collections ;
12
11
import java .util .Comparator ;
13
12
import java .util .HashMap ;
14
13
import java .util .HashSet ;
61
60
import org .hibernate .type .descriptor .java .spi .JavaTypeRegistry ;
62
61
import org .hibernate .usertype .CompositeUserType ;
63
62
63
+ import static java .util .Collections .unmodifiableList ;
64
64
import static java .util .stream .Collectors .toList ;
65
65
import static org .hibernate .generator .EventType .INSERT ;
66
66
import static org .hibernate .internal .util .StringHelper .qualify ;
@@ -108,10 +108,6 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
108
108
private QualifiedName structName ;
109
109
private String [] structColumnNames ;
110
110
private transient Class <?> componentClass ;
111
- // lazily computed based on 'properties' field: invalidate by setting to null when properties are modified
112
- private transient List <Selectable > cachedSelectables ;
113
- // lazily computed based on 'properties' field: invalidate by setting to null when properties are modified
114
- private transient List <Column > cachedColumns ;
115
111
116
112
private transient Generator builtIdentifierGenerator ;
117
113
@@ -186,7 +182,6 @@ public void addProperty(Property p, XClass declaringClass) {
186
182
}
187
183
propertyDeclaringClasses .put ( p , declaringClass .getName () );
188
184
}
189
- propertiesListModified ();
190
185
}
191
186
192
187
public void addProperty (Property p ) {
@@ -200,45 +195,33 @@ public String getPropertyDeclaringClass(Property p) {
200
195
return null ;
201
196
}
202
197
203
- private void propertiesListModified () {
204
- this .cachedSelectables = null ;
205
- this .cachedColumns = null ;
206
- }
207
-
208
198
@ Override
209
199
public void addColumn (Column column ) {
210
200
throw new UnsupportedOperationException ("Cant add a column to a component" );
211
201
}
212
202
213
203
@ Override
214
204
public List <Selectable > getSelectables () {
215
- if ( cachedSelectables == null ) {
216
- final List <Selectable > selectables = properties .stream ()
217
- .flatMap ( p -> p .getSelectables ().stream () )
218
- .collect ( toList () );
219
- if ( discriminator != null ) {
220
- selectables .addAll ( discriminator .getSelectables () );
221
- }
222
- cachedSelectables = selectables ;
205
+ final List <Selectable > selectables = new ArrayList <>( properties .size () + 2 );
206
+ for ( Property property : properties ) {
207
+ selectables .addAll ( property .getSelectables () );
208
+ }
209
+ if ( discriminator != null ) {
210
+ selectables .addAll ( discriminator .getSelectables () );
223
211
}
224
- return cachedSelectables ;
212
+ return unmodifiableList ( selectables ) ;
225
213
}
226
214
227
215
@ Override
228
216
public List <Column > getColumns () {
229
- if ( cachedColumns != null ) {
230
- return cachedColumns ;
217
+ final List <Column > columns = new ArrayList <>( properties .size () + 2 );
218
+ for ( Property property : properties ) {
219
+ columns .addAll ( property .getValue ().getColumns () );
231
220
}
232
- else {
233
- final List <Column > columns = properties .stream ()
234
- .flatMap ( p -> p .getValue ().getColumns ().stream () )
235
- .collect ( toList () );
236
- if ( discriminator != null ) {
237
- columns .addAll ( discriminator .getColumns () );
238
- }
239
- this .cachedColumns = Collections .unmodifiableList ( columns );
240
- return cachedColumns ;
221
+ if ( discriminator != null ) {
222
+ columns .addAll ( discriminator .getColumns () );
241
223
}
224
+ return unmodifiableList ( columns );
242
225
}
243
226
244
227
public boolean isEmbedded () {
@@ -763,6 +746,10 @@ public String[] getPropertyNames() {
763
746
return propertyNames ;
764
747
}
765
748
749
+ public void clearProperties () {
750
+ properties .clear ();
751
+ }
752
+
766
753
public static class StandardGenerationContextLocator
767
754
implements CompositeNestedGeneratedValueGenerator .GenerationContextLocator {
768
755
private final String entityName ;
@@ -909,7 +896,6 @@ private int[] sortProperties(boolean forceRetainOriginalOrder) {
909
896
}
910
897
}
911
898
}
912
- propertiesListModified ();
913
899
return this .originalPropertyOrder = originalPropertyOrder ;
914
900
}
915
901
0 commit comments