Skip to content

Commit

Permalink
HHH-15184 Improve efficiency of Component#getColumns()
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed Apr 6, 2022
1 parent 25aec8d commit 6815c2a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions hibernate-core/src/main/java/org/hibernate/mapping/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable

// lazily computed based on 'properties' field: invalidate by setting to null when properties are modified
private List<Selectable> cachedSelectables;
// lazily computed based on 'properties' field: invalidate by setting to null when properties are modified
private List<Column> cachedColums;

public Component(MetadataBuildingContext metadata, PersistentClass owner) throws MappingException {
this( metadata, owner.getTable(), owner );
Expand Down Expand Up @@ -124,7 +126,8 @@ public void addProperty(Property p) {
}

private void propertiesListModified() {
cachedSelectables = null;
this.cachedSelectables = null;
this.cachedColums = null;
}

@Override
Expand Down Expand Up @@ -167,9 +170,15 @@ public List<Selectable> getSelectables() {

@Override
public List<Column> getColumns() {
return properties.stream()
.flatMap( p -> p.getValue().getColumns().stream() )
.collect(Collectors.toList());
if ( cachedColums != null ) {
return cachedColums;
}
else {
this.cachedColums = properties.stream()
.flatMap( p -> p.getValue().getColumns().stream() )
.collect( Collectors.toList() );
return cachedColums;
}
}

public boolean isEmbedded() {
Expand Down

0 comments on commit 6815c2a

Please sign in to comment.