3232import org .hibernate .metamodel .mapping .JdbcMapping ;
3333import org .hibernate .metamodel .mapping .ManagedMappingType ;
3434import org .hibernate .metamodel .mapping .ModelPart ;
35- import org .hibernate .metamodel .mapping .ModelPartContainer ;
3635import org .hibernate .metamodel .mapping .PluralAttributeMapping ;
3736import org .hibernate .metamodel .mapping .SelectableConsumer ;
3837import org .hibernate .metamodel .mapping .SelectableMapping ;
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 ,
0 commit comments