Skip to content

Commit b853e0c

Browse files
committed
minor cleanups
1 parent b355408 commit b853e0c

File tree

3 files changed

+39
-44
lines changed

3 files changed

+39
-44
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ private SqlSelection resolveSqlSelection(
188188
// If the index is part of the element table group, we must use that explicitly here because the index is basic
189189
// and thus there is no index table group registered. The logic in the PluralTableGroup prevents from looking
190190
// into the element table group though because the element table group navigable path is not the parent of this navigable path
191-
if ( nature == Nature.INDEX && collectionDescriptor.getAttributeMapping().getIndexMetadata().getIndexPropertyName() != null ) {
191+
if ( nature == Nature.INDEX
192+
&& collectionDescriptor.getAttributeMapping().getIndexMetadata().getIndexPropertyName() != null ) {
192193
targetTableGroup = ( (PluralTableGroup) tableGroup ).getElementTableGroup();
193194
}
194195
else {
@@ -199,10 +200,7 @@ private SqlSelection resolveSqlSelection(
199200
getContainingTableExpression()
200201
);
201202
return exprResolver.resolveSqlSelection(
202-
exprResolver.resolveSqlExpression(
203-
tableReference,
204-
selectableMapping
205-
),
203+
exprResolver.resolveSqlExpression( tableReference, selectableMapping ),
206204
getJdbcMapping().getJdbcJavaType(),
207205
fetchParent,
208206
creationState.getSqlAstCreationState().getCreationContext().getTypeConfiguration()
@@ -275,9 +273,9 @@ public Fetch generateFetch(
275273
parentNavigablePath = parentNavigablePath.getParent();
276274
}
277275

278-
final TableGroup tableGroup = creationState.getSqlAstCreationState()
279-
.getFromClauseAccess()
280-
.findTableGroup( parentNavigablePath );
276+
final TableGroup tableGroup =
277+
creationState.getSqlAstCreationState().getFromClauseAccess()
278+
.findTableGroup( parentNavigablePath );
281279
final SqlSelection sqlSelection = resolveSqlSelection( fetchablePath, tableGroup, fetchParent, creationState );
282280

283281
return new BasicFetch<>(

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ManyToManyCollectionPart.java

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.hibernate.metamodel.mapping.JdbcMapping;
3333
import org.hibernate.metamodel.mapping.ManagedMappingType;
3434
import org.hibernate.metamodel.mapping.ModelPart;
35-
import org.hibernate.metamodel.mapping.ModelPartContainer;
3635
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
3736
import org.hibernate.metamodel.mapping.SelectableConsumer;
3837
import org.hibernate.metamodel.mapping.SelectableMapping;
@@ -78,8 +77,8 @@
7877
*
7978
* @author Steve Ebersole
8079
*/
81-
public class ManyToManyCollectionPart extends AbstractEntityCollectionPart implements EntityAssociationMapping,
82-
LazyTableGroup.ParentTableGroupUseChecker {
80+
public class ManyToManyCollectionPart extends AbstractEntityCollectionPart
81+
implements EntityAssociationMapping, LazyTableGroup.ParentTableGroupUseChecker {
8382
private ForeignKeyDescriptor foreignKey;
8483
private ValuedModelPart fkTargetModelPart;
8584

@@ -126,8 +125,9 @@ public ModelPart findSubPart(String name, EntityMappingType targetType) {
126125
// to preserve the cardinality. Also, the OneToManyTableGroup has no reference to the parent table group
127126
if ( getTargetKeyPropertyNames().contains( name ) ) {
128127
final ModelPart keyPart = foreignKey.getKeyPart();
129-
if ( keyPart instanceof EmbeddableValuedModelPart && keyPart instanceof VirtualModelPart ) {
130-
return ( (ModelPartContainer) keyPart ).findSubPart( name, targetType );
128+
if ( keyPart instanceof EmbeddableValuedModelPart embeddableValuedModelPart
129+
&& keyPart instanceof VirtualModelPart ) {
130+
return embeddableValuedModelPart.findSubPart( name, targetType );
131131
}
132132
return keyPart;
133133
}
@@ -170,11 +170,9 @@ public int forEachSelectable(int offset, SelectableConsumer consumer) {
170170
public void forEachInsertable(SelectableConsumer consumer) {
171171
forEachSelectable(
172172
(selectionIndex, selectableMapping) -> {
173-
if ( !foreignKey.getKeyPart().getSelectable( selectionIndex ).isInsertable() ) {
174-
return;
173+
if ( foreignKey.getKeyPart().getSelectable( selectionIndex ).isInsertable() ) {
174+
consumer.accept( selectionIndex, selectableMapping );
175175
}
176-
177-
consumer.accept( selectionIndex, selectableMapping );
178176
}
179177
);
180178
}
@@ -183,11 +181,9 @@ public void forEachInsertable(SelectableConsumer consumer) {
183181
public void forEachUpdatable(SelectableConsumer consumer) {
184182
forEachSelectable(
185183
(selectionIndex, selectableMapping) -> {
186-
if ( !foreignKey.getKeyPart().getSelectable( selectionIndex ).isUpdateable() ) {
187-
return;
184+
if ( foreignKey.getKeyPart().getSelectable( selectionIndex ).isUpdateable() ) {
185+
consumer.accept( selectionIndex, selectableMapping );
188186
}
189-
190-
consumer.accept( selectionIndex, selectableMapping );
191187
}
192188
);
193189
}
@@ -396,8 +392,11 @@ else if ( getNature() == Nature.INDEX ) {
396392
}
397393
}
398394
else if ( StringHelper.isNotEmpty( bootCollectionDescriptor.getMappedByProperty() ) ) {
399-
final ModelPart mappedByPart = resolveNamedTargetPart( bootCollectionDescriptor.getMappedByProperty(), getAssociatedEntityMappingType(), collectionDescriptor );
400-
if ( mappedByPart instanceof ToOneAttributeMapping || mappedByPart instanceof DiscriminatedAssociationAttributeMapping ) {
395+
final ModelPart mappedByPart =
396+
resolveNamedTargetPart( bootCollectionDescriptor.getMappedByProperty(),
397+
getAssociatedEntityMappingType(), collectionDescriptor );
398+
if ( mappedByPart instanceof ToOneAttributeMapping
399+
|| mappedByPart instanceof DiscriminatedAssociationAttributeMapping ) {
401400
////////////////////////////////////////////////
402401
// E.g.
403402
//
@@ -622,7 +621,9 @@ private ForeignKeyDescriptor createForeignKeyDescriptor(
622621
);
623622
}
624623

625-
final String collectionTableName = ( (CollectionMutationTarget) getCollectionDescriptor() ).getCollectionTableMapping().getTableName();
624+
final String collectionTableName =
625+
( (CollectionMutationTarget) getCollectionDescriptor() )
626+
.getCollectionTableMapping().getTableName();
626627

627628
final BasicValuedModelPart basicFkTarget = fkTargetModelPart.asBasicValuedModelPart();
628629
if ( basicFkTarget != null ) {
@@ -662,16 +663,12 @@ private ForeignKeyDescriptor determineForeignKey(
662663
final int selectableCount = foreignKeyDescriptor.getJdbcTypeCount();
663664
final ValuedModelPart keyPart = foreignKeyDescriptor.getKeyPart();
664665
for ( int i = 0; i < selectableCount; i++ ) {
665-
if ( keyPart.getSelectable( i ).isInsertable() != fkBootDescriptorSource.isColumnInsertable( i )
666-
|| keyPart.getSelectable( i ).isUpdateable() != fkBootDescriptorSource.isColumnUpdateable( i ) ) {
666+
final SelectableMapping selectable = keyPart.getSelectable( i );
667+
if ( selectable.isInsertable() != fkBootDescriptorSource.isColumnInsertable( i )
668+
|| selectable.isUpdateable() != fkBootDescriptorSource.isColumnUpdateable( i ) ) {
667669
final AttributeMapping attributeMapping = keyPart.asAttributeMapping();
668-
final ManagedMappingType declaringType;
669-
if ( attributeMapping == null ) {
670-
declaringType = null;
671-
}
672-
else {
673-
declaringType = attributeMapping.getDeclaringType();
674-
}
670+
final ManagedMappingType declaringType =
671+
attributeMapping == null ? null : attributeMapping.getDeclaringType();
675672
final SelectableMappings selectableMappings = SelectableMappingsImpl.from(
676673
keyPart.getContainingTableExpression(),
677674
fkBootDescriptorSource,

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/OneToManyCollectionPart.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,10 @@ public OneToManyCollectionPart(
6666
MappingModelCreationProcess creationProcess) {
6767
super( nature, bootCollectionDescriptor, collectionDescriptor, elementTypeDescriptor, notFoundAction, creationProcess );
6868

69-
if ( nature == Nature.INDEX && bootCollectionDescriptor instanceof Map ) {
70-
mapKeyPropertyName = ( (Map) bootCollectionDescriptor ).getMapKeyPropertyName();
71-
}
72-
else {
73-
mapKeyPropertyName = null;
74-
}
69+
mapKeyPropertyName =
70+
nature == Nature.INDEX && bootCollectionDescriptor instanceof Map map
71+
? map.getMapKeyPropertyName()
72+
: null;
7573
}
7674

7775
/**
@@ -165,10 +163,11 @@ public TableGroupJoin createTableGroupJoin(
165163

166164
// INDEX is implied if mapKeyPropertyName is not null
167165
if ( mapKeyPropertyName != null ) {
168-
final EntityCollectionPart elementPart = (EntityCollectionPart) getCollectionDescriptor().getAttributeMapping().getElementDescriptor();
169-
final EntityMappingType elementEntity = elementPart.getAssociatedEntityMappingType();
170-
final AttributeMapping mapKeyAttribute = elementEntity.findAttributeMapping( mapKeyPropertyName );
171-
if ( mapKeyAttribute instanceof ToOneAttributeMapping toOne ) {
166+
final EntityCollectionPart elementPart =
167+
(EntityCollectionPart)
168+
getCollectionDescriptor().getAttributeMapping().getElementDescriptor();
169+
if ( elementPart.getAssociatedEntityMappingType().findAttributeMapping( mapKeyPropertyName )
170+
instanceof ToOneAttributeMapping toOne ) {
172171
final NavigablePath mapKeyPropertyPath = navigablePath.append( mapKeyPropertyName );
173172
final TableGroupJoin tableGroupJoin = toOne.createTableGroupJoin(
174173
mapKeyPropertyPath,
@@ -180,7 +179,8 @@ public TableGroupJoin createTableGroupJoin(
180179
addsPredicate,
181180
creationState
182181
);
183-
creationState.getFromClauseAccess().registerTableGroup( mapKeyPropertyPath, tableGroupJoin.getJoinedGroup() );
182+
creationState.getFromClauseAccess()
183+
.registerTableGroup( mapKeyPropertyPath, tableGroupJoin.getJoinedGroup() );
184184
return tableGroupJoin;
185185
}
186186
}

0 commit comments

Comments
 (0)