88
99import java .lang .reflect .Constructor ;
1010import java .util .ArrayList ;
11- import java .util .Collections ;
1211import java .util .Comparator ;
1312import java .util .HashMap ;
1413import java .util .HashSet ;
6160import org .hibernate .type .descriptor .java .spi .JavaTypeRegistry ;
6261import org .hibernate .usertype .CompositeUserType ;
6362
63+ import static java .util .Collections .unmodifiableList ;
6464import static java .util .stream .Collectors .toList ;
6565import static org .hibernate .generator .EventType .INSERT ;
6666import static org .hibernate .internal .util .StringHelper .qualify ;
@@ -108,10 +108,6 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
108108 private QualifiedName structName ;
109109 private String [] structColumnNames ;
110110 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 ;
115111
116112 private transient Generator builtIdentifierGenerator ;
117113
@@ -186,7 +182,6 @@ public void addProperty(Property p, XClass declaringClass) {
186182 }
187183 propertyDeclaringClasses .put ( p , declaringClass .getName () );
188184 }
189- propertiesListModified ();
190185 }
191186
192187 public void addProperty (Property p ) {
@@ -200,45 +195,33 @@ public String getPropertyDeclaringClass(Property p) {
200195 return null ;
201196 }
202197
203- private void propertiesListModified () {
204- this .cachedSelectables = null ;
205- this .cachedColumns = null ;
206- }
207-
208198 @ Override
209199 public void addColumn (Column column ) {
210200 throw new UnsupportedOperationException ("Cant add a column to a component" );
211201 }
212202
213203 @ Override
214204 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 () );
223211 }
224- return cachedSelectables ;
212+ return unmodifiableList ( selectables ) ;
225213 }
226214
227215 @ Override
228216 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 () );
231220 }
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 () );
241223 }
224+ return unmodifiableList ( columns );
242225 }
243226
244227 public boolean isEmbedded () {
@@ -763,6 +746,10 @@ public String[] getPropertyNames() {
763746 return propertyNames ;
764747 }
765748
749+ public void clearProperties () {
750+ properties .clear ();
751+ }
752+
766753 public static class StandardGenerationContextLocator
767754 implements CompositeNestedGeneratedValueGenerator .GenerationContextLocator {
768755 private final String entityName ;
@@ -909,7 +896,6 @@ private int[] sortProperties(boolean forceRetainOriginalOrder) {
909896 }
910897 }
911898 }
912- propertiesListModified ();
913899 return this .originalPropertyOrder = originalPropertyOrder ;
914900 }
915901
0 commit comments