Skip to content

Commit 9639798

Browse files
committed
a couple of tiny optimizations, and use of 'var'
1 parent 4c42ff2 commit 9639798

File tree

16 files changed

+137
-97
lines changed

16 files changed

+137
-97
lines changed

hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static boolean includeInBaseFetchGroup(
8787
return false;
8888
}
8989

90-
if ( toOne.getColumnSpan() == 0 ) {
90+
if ( !toOne.hasColumns() ) {
9191
// generally this would indicate a "shared PK" one-to-one and there
9292
// is no column for the association on the owner table - do not add
9393
// the association to the base group (which would force an immediate

hibernate-core/src/main/java/org/hibernate/generator/GeneratorCreationContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ default Type getType() {
8181
* The {@link SqlStringGenerationContext} to use when generating SQL.
8282
*/
8383
default SqlStringGenerationContext getSqlStringGenerationContext() {
84-
final Database database = getDatabase();
84+
final var database = getDatabase();
8585
return fromExplicit( database.getJdbcEnvironment(), database, getDefaultCatalog(), getDefaultSchema() );
8686
}
8787
}

hibernate-core/src/main/java/org/hibernate/graph/EntityGraphs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public static <R> void setFetchGraph(TypedQuery<R> query, EntityGraph<R> graph)
171171
}
172172

173173
/**
174-
* Allows a treated subgraph to ve created for a {@link Subgraph}, since the
174+
* Allows a treated subgraph to be created for a {@link Subgraph}, since the
175175
* JPA-standard operation {@link EntityGraph#addTreatedSubgraph(Class)} is
176176
* declared by {@link EntityGraph}.
177177
*

hibernate-core/src/main/java/org/hibernate/id/enhanced/ExportableColumnHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public List<Column> getColumns() {
4747
return List.of( column );
4848
}
4949

50+
@Override
51+
public boolean hasColumns() {
52+
return true;
53+
}
54+
5055
@Override
5156
public Type getType() {
5257
return type;

hibernate-core/src/main/java/org/hibernate/mapping/Any.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void addFormula(Formula formula) {
157157
private void applySelectableLocally(Selectable selectable) {
158158
// note: adding column to meta or key mapping ultimately calls back into `#applySelectableToSuper`
159159
// to add the column to the ANY super.
160-
if ( discriminatorDescriptor == null && getColumnSpan() == 0 ) {
160+
if ( discriminatorDescriptor == null && !hasColumns() ) {
161161
if ( selectable instanceof Column column ) {
162162
metaMapping.addColumn( column );
163163
}
@@ -247,7 +247,7 @@ public boolean isValid(MappingContext mappingContext) throws MappingException {
247247
}
248248

249249
private static String columnName(Column column, MetadataBuildingContext buildingContext) {
250-
final JdbcServices jdbcServices =
250+
final var jdbcServices =
251251
buildingContext.getBootstrapContext().getServiceRegistry()
252252
.requireService( JdbcServices.class );
253253
return column.getQuotedName( jdbcServices.getDialect() );

hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public Function<TypeConfiguration, java.lang.reflect.Type> getImplicitJavaTypeAc
235235
}
236236

237237
public Selectable getColumn() {
238-
return getColumnSpan() == 0 ? null : getColumn( 0 );
238+
return hasColumns() ? getColumn( 0 ) : null;
239239
}
240240

241241
public java.lang.reflect.Type getResolvedJavaType() {

hibernate-core/src/main/java/org/hibernate/mapping/Collection.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,11 @@ public int getColumnSpan() {
424424
return 0;
425425
}
426426

427+
@Override
428+
public boolean hasColumns() {
429+
return false;
430+
}
431+
427432
@Override
428433
public Type getType() throws MappingException {
429434
return getCollectionType();

hibernate-core/src/main/java/org/hibernate/mapping/Component.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,17 @@ public int getColumnSpan() {
246246
return getSelectables().size();
247247
}
248248

249+
@Override
250+
public boolean hasColumns() {
251+
for ( var property : properties ) {
252+
if ( property.hasColumns() ) {
253+
return true;
254+
}
255+
}
256+
return discriminator != null
257+
&& discriminator.hasColumns();
258+
}
259+
249260
public List<Column> getAggregatedColumns() {
250261
final List<Column> aggregatedColumns = new ArrayList<>( getPropertySpan() );
251262
collectAggregatedColumns( aggregatedColumns, this );
@@ -490,7 +501,7 @@ public boolean isSame(Component other) {
490501

491502
@Override
492503
public boolean[] getColumnInsertability() {
493-
final boolean[] result = new boolean[getColumnSpan()];
504+
final var result = new boolean[getColumnSpan()];
494505
int i = 0;
495506
for ( var property : getProperties() ) {
496507
i += copyFlags( property.getValue().getColumnInsertability(), result, i, property.isInsertable() );
@@ -522,7 +533,7 @@ public boolean hasAnyInsertableColumns() {
522533

523534
@Override
524535
public boolean[] getColumnUpdateability() {
525-
final boolean[] result = new boolean[getColumnSpan()];
536+
final var result = new boolean[getColumnSpan()];
526537
int i = 0;
527538
for ( var property : getProperties() ) {
528539
i += copyFlags( property.getValue().getColumnUpdateability(), result, i, property.isUpdatable() );
@@ -582,8 +593,8 @@ public boolean matchesAllProperties(String... propertyNames) {
582593
}
583594

584595
public boolean hasProperty(String propertyName) {
585-
for ( Property prop : properties ) {
586-
if ( prop.getName().equals(propertyName) ) {
596+
for ( var property : properties ) {
597+
if ( property.getName().equals(propertyName) ) {
587598
return true;
588599
}
589600
}
@@ -680,7 +691,7 @@ private Generator buildIdentifierGenerator(Dialect dialect, RootClass rootClass,
680691
for ( int i = 0; i < properties.size(); i++ ) {
681692
final var property = properties.get( i );
682693
if ( property.getValue().isSimpleValue() ) {
683-
final SimpleValue value = (SimpleValue) property.getValue();
694+
final var value = (SimpleValue) property.getValue();
684695
if ( !value.getCustomIdGeneratorCreator().isAssigned() ) {
685696
// skip any 'assigned' generators, they would have been
686697
// handled by the StandardGenerationContextLocator
@@ -850,9 +861,10 @@ public boolean isValid(MappingContext mappingContext) throws MappingException {
850861
}
851862
if ( assignedPropertyNames.size() != properties.size() ) {
852863
final ArrayList<String> missingProperties = new ArrayList<>();
853-
for ( Property property : properties ) {
854-
if ( !assignedPropertyNames.contains( property.getName() ) ) {
855-
missingProperties.add( property.getName() );
864+
for ( var property : properties ) {
865+
final String propertyName = property.getName();
866+
if ( !assignedPropertyNames.contains( propertyName ) ) {
867+
missingProperties.add( propertyName );
856868
}
857869
}
858870
throw new MappingException( "component type [" + componentClassName + "] has " + properties.size() + " properties but the instantiator only assigns " + assignedPropertyNames.size() + " properties. missing properties: " + missingProperties );
@@ -886,7 +898,7 @@ private int[] sortProperties(boolean forceRetainOriginalOrder) {
886898
// because XML mappings might refer to this through the defined order
887899
if ( forceRetainOriginalOrder || isAlternateUniqueKey() || isEmbedded()
888900
|| getBuildingContext() instanceof MappingDocument ) {
889-
final Property[] originalProperties = properties.toArray( new Property[0] );
901+
final var originalProperties = properties.toArray( new Property[0] );
890902
properties.sort( Comparator.comparing( Property::getName ) );
891903
originalPropertyOrder = new int[originalProperties.length];
892904
for ( int j = 0; j < originalPropertyOrder.length; j++ ) {

hibernate-core/src/main/java/org/hibernate/mapping/OneToMany.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public int getColumnSpan() {
9393
return associatedClass.getKey().getColumnSpan();
9494
}
9595

96+
@Override
97+
public boolean hasColumns() {
98+
return associatedClass.getKey().hasColumns();
99+
}
100+
96101
@Override
97102
public FetchMode getFetchMode() {
98103
return FetchMode.JOIN;

hibernate-core/src/main/java/org/hibernate/mapping/OneToOne.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public String getEntityName() {
6161
}
6262

6363
public OneToOneType getType() throws MappingException {
64-
if ( getColumnSpan()>0 ) {
64+
if ( hasColumns() ) {
6565
return new SpecialOneToOneType(
6666
getTypeConfiguration(),
6767
getReferencedEntityName(),
@@ -93,7 +93,7 @@ public OneToOneType getType() throws MappingException {
9393

9494
@Override
9595
public void createUniqueKey(MetadataBuildingContext context) {
96-
if ( !hasFormula() && getColumnSpan()>0 ) {
96+
if ( !hasFormula() && hasColumns() ) {
9797
getTable().createUniqueKey( getConstraintColumns(), context );
9898
}
9999
}

0 commit comments

Comments
 (0)