Skip to content
Permalink
Browse files

HHH-11768 HHH-11714 Apply code suggestions.

  • Loading branch information...
Naros committed Jun 12, 2017
1 parent c6135f2 commit 699b50725d1cab1378cc7617bf92920bd7888b5a
Showing with 25 additions and 32 deletions.
  1. +25 −32 hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java
@@ -1024,7 +1024,7 @@ private TransactionCompletionProcesses(

private Set<String> childEntityNames = new HashSet<>( );

public BatchIdentifier(String entityName, String rootEntityName) {
BatchIdentifier(String entityName, String rootEntityName) {
this.entityName = entityName;
this.rootEntityName = rootEntityName;
}
@@ -1046,38 +1046,30 @@ public int hashCode() {
return Objects.hash( entityName );
}

public String getEntityName() {
String getEntityName() {
return entityName;
}

public String getRootEntityName() {
String getRootEntityName() {
return rootEntityName;
}

public Set<String> getParentEntityNames() {
Set<String> getParentEntityNames() {
return parentEntityNames;
}

public Set<String> getChildEntityNames() {
Set<String> getChildEntityNames() {
return childEntityNames;
}

public boolean hasAnyParentEntityNames(String... entityNames) {
for ( String entityName : entityNames ) {
if ( parentEntityNames.contains( entityName ) ) {
return true;
}
}
return false;
boolean hasAnyParentEntityNames(BatchIdentifier batchIdentifier) {
return parentEntityNames.contains( batchIdentifier.getEntityName() ) ||
parentEntityNames.contains( batchIdentifier.getRootEntityName() );
}

public boolean hasAnyChildEntityNames(String... entityNames) {
for ( String entityName : entityNames ) {
if ( childEntityNames.contains( entityName ) ) {
return true;
}
}
return false;
boolean hasAnyChildEntityNames(BatchIdentifier batchIdentifier) {
return childEntityNames.contains( batchIdentifier.getEntityName() ) ||
parentEntityNames.contains( batchIdentifier.getRootEntityName() );

This comment has been minimized.

Copy link
@skeithyip

skeithyip Sep 18, 2017

Hi, shouldn't this be childEntityNames?

This comment has been minimized.

Copy link
@Naros

Naros Sep 29, 2017

Author Member

This has already been fixed on master here.

}
}

@@ -1123,33 +1115,34 @@ public void sort(List<AbstractEntityInsertAction> insertions) {
}
insertions.clear();

// Examine each entry in the batch list, sorting them based on parent/child associations.
for ( int i = 0; i < latestBatches.size(); i++ ) {
BatchIdentifier batchIdentifier = latestBatches.get( i );
String entityName = batchIdentifier.getEntityName();
String rootEntityName = batchIdentifier.getRootEntityName();

//Make sure that child entries are not before parents
// Iterate previous batches and make sure that parent types are before children
// Since the outer loop looks at each batch entry individually, we need to verify that any
// prior batches in the list are not considered children (or have a parent) of the current
// batch. If so, we reordered them.
for ( int j = i - 1; j >= 0; j-- ) {
BatchIdentifier prevBatchIdentifier = latestBatches.get( j );
if ( prevBatchIdentifier.hasAnyParentEntityNames( entityName, rootEntityName ) ) {
if ( prevBatchIdentifier.hasAnyParentEntityNames( batchIdentifier ) ) {
latestBatches.remove( batchIdentifier );
latestBatches.add( j, batchIdentifier );
}
}

//Make sure that parent entries are not after children
// Iterate next batches and make sure that children types are after parents.
// Since the outer loop looks at each batch entry individually and the prior loop will reorder
// entries as well, we need to look and verify if the current batch is a child of the next
// batch or if the current batch is seen as a parent or child of the next batch.
for ( int j = i + 1; j < latestBatches.size(); j++ ) {
BatchIdentifier nextBatchIdentifier = latestBatches.get( j );

final boolean nextBatchHasChild = nextBatchIdentifier.hasAnyChildEntityNames( entityName, rootEntityName );

final boolean batchHasChild = batchIdentifier.hasAnyChildEntityNames(
nextBatchIdentifier.getEntityName(), nextBatchIdentifier.getRootEntityName() );

final boolean batchHasParent = batchIdentifier.hasAnyParentEntityNames(
nextBatchIdentifier.getEntityName(), nextBatchIdentifier.getRootEntityName() );
final boolean nextBatchHasChild = nextBatchIdentifier.hasAnyChildEntityNames( batchIdentifier );
final boolean batchHasChild = batchIdentifier.hasAnyChildEntityNames( nextBatchIdentifier );
final boolean batchHasParent = batchIdentifier.hasAnyParentEntityNames( nextBatchIdentifier );

//Take care of unidirectional @OneToOne associations but exclude bidirectional @ManyToMany
// Take care of unidirectional @OneToOne associations but exclude bidirectional @ManyToMany
if ( ( nextBatchHasChild && !batchHasChild ) || batchHasParent ) {
latestBatches.remove( batchIdentifier );
latestBatches.add( j, batchIdentifier );

0 comments on commit 699b507

Please sign in to comment.
You can’t perform that action at this time.