Skip to content

Commit

Permalink
Fix wrong order in SQL TableGroupJoin rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 committed Mar 16, 2021
1 parent 6c3d0d8 commit 222e3fb
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 83 deletions.
Expand Up @@ -8,7 +8,6 @@

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

Expand All @@ -35,7 +34,6 @@ public class TableGroupImpl implements TableGroup {
private final ModelPartContainer container;
private final LockMode lockMode;

private Set<TableGroupJoin> tableGroupJoins;

public TableGroupImpl(
NavigablePath navigablePath,
Expand Down Expand Up @@ -76,32 +74,22 @@ public LockMode getLockMode() {
}

@Override
public Set<TableGroupJoin> getTableGroupJoins() {
return tableGroupJoins == null ? Collections.emptySet() : tableGroupJoins;
public List<TableGroupJoin> getTableGroupJoins() {
return Collections.emptyList();
}

@Override
public boolean hasTableGroupJoins() {
return tableGroupJoins != null && ! tableGroupJoins.isEmpty();
}

@Override
public void setTableGroupJoins(Set<TableGroupJoin> joins) {
throw new UnsupportedOperationException();
return false;
}

@Override
public void addTableGroupJoin(TableGroupJoin join) {

throw new UnsupportedOperationException();
}

@Override
public void visitTableGroupJoins(Consumer<TableGroupJoin> consumer) {
if ( tableGroupJoins == null ) {
return;
}

tableGroupJoins.forEach( consumer );
}

@Override
Expand Down
Expand Up @@ -7,7 +7,6 @@
package org.hibernate.sql.ast;

import java.util.List;
import java.util.Set;

import org.hibernate.sql.ast.tree.SqlAstTreeLogger;
import org.hibernate.sql.ast.tree.Statement;
Expand Down Expand Up @@ -130,7 +129,7 @@ private void logTableGroupDetails(TableGroup tableGroup) {
);
}

final Set<TableGroupJoin> tableGroupJoins = tableGroup.getTableGroupJoins();
final List<TableGroupJoin> tableGroupJoins = tableGroup.getTableGroupJoins();
if ( ! tableGroupJoins.isEmpty() ) {
logNode(
"TableGroupJoins",
Expand Down
Expand Up @@ -8,7 +8,6 @@

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

Expand Down Expand Up @@ -58,8 +57,8 @@ public ModelPart getExpressionType() {
}

@Override
public Set<TableGroupJoin> getTableGroupJoins() {
return Collections.emptySet();
public List<TableGroupJoin> getTableGroupJoins() {
return Collections.emptyList();
}

@Override
Expand All @@ -82,10 +81,6 @@ public TableReference resolveTableReference(
return cteTableReference;
}

@Override
public void setTableGroupJoins(Set<TableGroupJoin> joins) {
}

@Override
public void visitTableGroupJoins(Consumer<TableGroupJoin> consumer) {
}
Expand Down
Expand Up @@ -6,9 +6,9 @@
*/
package org.hibernate.sql.ast.tree.from;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.List;
import java.util.function.Consumer;

import org.hibernate.LockMode;
Expand All @@ -26,7 +26,7 @@ public abstract class AbstractTableGroup extends AbstractColumnReferenceQualifie
private final LockMode lockMode;
private final SqlAliasBase sqlAliasBase;

private Set<TableGroupJoin> tableGroupJoins;
private List<TableGroupJoin> tableGroupJoins;
private boolean isInnerJoinPossible;

private final SessionFactoryImplementor sessionFactory;
Expand Down Expand Up @@ -93,26 +93,23 @@ protected SessionFactoryImplementor getSessionFactory() {
}

@Override
public Set<TableGroupJoin> getTableGroupJoins() {
return tableGroupJoins == null ? Collections.emptySet() : Collections.unmodifiableSet( tableGroupJoins );
public List<TableGroupJoin> getTableGroupJoins() {
return tableGroupJoins == null ? Collections.emptyList() : Collections.unmodifiableList( tableGroupJoins );
}

@Override
public boolean hasTableGroupJoins() {
return tableGroupJoins != null && !tableGroupJoins.isEmpty();
}

@Override
public void setTableGroupJoins(Set<TableGroupJoin> joins) {
tableGroupJoins = new HashSet<>( joins );
}

@Override
public void addTableGroupJoin(TableGroupJoin join) {
if ( tableGroupJoins == null ) {
tableGroupJoins = new HashSet<>();
tableGroupJoins = new ArrayList<>();
}
if ( !tableGroupJoins.contains( join ) ) {
tableGroupJoins.add( join );
}
tableGroupJoins.add( join );
}

@Override
Expand Down
Expand Up @@ -6,10 +6,9 @@
*/
package org.hibernate.sql.ast.tree.from;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

Expand All @@ -26,7 +25,7 @@ public class CompositeTableGroup implements VirtualTableGroup {

private final TableGroup underlyingTableGroup;

private Set<TableGroupJoin> tableGroupJoins;
private List<TableGroupJoin> tableGroupJoins;

public CompositeTableGroup(
NavigablePath navigablePath,
Expand Down Expand Up @@ -64,26 +63,23 @@ public LockMode getLockMode() {
}

@Override
public Set<TableGroupJoin> getTableGroupJoins() {
return tableGroupJoins == null ? Collections.emptySet() : Collections.unmodifiableSet( tableGroupJoins );
public List<TableGroupJoin> getTableGroupJoins() {
return tableGroupJoins == null ? Collections.emptyList() : Collections.unmodifiableList( tableGroupJoins );
}

@Override
public boolean hasTableGroupJoins() {
return tableGroupJoins != null && !tableGroupJoins.isEmpty();
}

@Override
public void setTableGroupJoins(Set<TableGroupJoin> joins) {
tableGroupJoins = new HashSet<>( joins );
}

@Override
public void addTableGroupJoin(TableGroupJoin join) {
if ( tableGroupJoins == null ) {
tableGroupJoins = new HashSet<>();
tableGroupJoins = new ArrayList<>();
}
if ( !tableGroupJoins.contains( join ) ) {
tableGroupJoins.add( join );
}
tableGroupJoins.add( join );
}

@Override
Expand Down
Expand Up @@ -8,7 +8,6 @@

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

Expand Down Expand Up @@ -90,20 +89,15 @@ public LockMode getLockMode() {
}

@Override
public Set<TableGroupJoin> getTableGroupJoins() {
return Collections.emptySet();
public List<TableGroupJoin> getTableGroupJoins() {
return Collections.emptyList();
}

@Override
public boolean hasTableGroupJoins() {
return false;
}

@Override
public void setTableGroupJoins(Set<TableGroupJoin> joins) {
throw new UnsupportedOperationException();
}

@Override
public void addTableGroupJoin(TableGroupJoin join) {
throw new UnsupportedOperationException();
Expand Down
Expand Up @@ -12,7 +12,6 @@

import org.hibernate.LockMode;
import org.hibernate.metamodel.mapping.ModelPartContainer;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.NavigablePath;
import org.hibernate.query.sqm.sql.internal.DomainResultProducer;
import org.hibernate.query.sqm.sql.internal.SqmPathInterpretation;
Expand Down Expand Up @@ -41,12 +40,10 @@ public interface TableGroup extends SqlAstNode, ColumnReferenceQualifier, SqmPat

LockMode getLockMode();

Set<TableGroupJoin> getTableGroupJoins();
List<TableGroupJoin> getTableGroupJoins();

boolean hasTableGroupJoins();

void setTableGroupJoins(Set<TableGroupJoin> joins);

void addTableGroupJoin(TableGroupJoin join);

void visitTableGroupJoins(Consumer<TableGroupJoin> consumer);
Expand Down
Expand Up @@ -6,10 +6,9 @@
*/
package org.hibernate.sql.ast.tree.from;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

Expand All @@ -24,7 +23,7 @@
*/
public class UnionTableGroup implements VirtualTableGroup {
private final NavigablePath navigablePath;
private Set<TableGroupJoin> tableGroupJoins;
private List<TableGroupJoin> tableGroupJoins;

private final UnionSubclassEntityPersister modelPart;
private final TableReference tableReference;
Expand Down Expand Up @@ -64,26 +63,23 @@ public LockMode getLockMode() {
}

@Override
public Set<TableGroupJoin> getTableGroupJoins() {
return tableGroupJoins == null ? Collections.emptySet() : Collections.unmodifiableSet( tableGroupJoins );
public List<TableGroupJoin> getTableGroupJoins() {
return tableGroupJoins == null ? Collections.emptyList() : Collections.unmodifiableList( tableGroupJoins );
}

@Override
public boolean hasTableGroupJoins() {
return tableGroupJoins != null && !tableGroupJoins.isEmpty();
}

@Override
public void setTableGroupJoins(Set<TableGroupJoin> joins) {
tableGroupJoins = new HashSet<>( joins );
}

@Override
public void addTableGroupJoin(TableGroupJoin join) {
if ( tableGroupJoins == null ) {
tableGroupJoins = new HashSet<>();
tableGroupJoins = new ArrayList<>();
}
if ( !tableGroupJoins.contains( join ) ) {
tableGroupJoins.add( join );
}
tableGroupJoins.add( join );
}

@Override
Expand Down
Expand Up @@ -7,7 +7,6 @@
package org.hibernate.sql.results.graph.collection.internal;

import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

Expand Down Expand Up @@ -64,7 +63,7 @@ public LockMode getLockMode() {
}

@Override
public Set<TableGroupJoin> getTableGroupJoins() {
public List<TableGroupJoin> getTableGroupJoins() {
return collectionTableGroup.getTableGroupJoins();
}

Expand All @@ -73,11 +72,6 @@ public boolean hasTableGroupJoins() {
return collectionTableGroup.hasTableGroupJoins();
}

@Override
public void setTableGroupJoins(Set<TableGroupJoin> joins) {
collectionTableGroup.setTableGroupJoins( joins );
}

@Override
public void addTableGroupJoin(TableGroupJoin join) {
collectionTableGroup.addTableGroupJoin( join );
Expand Down
Expand Up @@ -160,7 +160,7 @@ void testFetchSemanticsWithDeepSubgraph() {

// Check the from-clause
assertEntityValuedJoinedGroup( sqlAst, "owner", Person.class, tableGroup -> {
Set<TableGroupJoin> tableGroupJoins = tableGroup.getTableGroupJoins();
List<TableGroupJoin> tableGroupJoins = tableGroup.getTableGroupJoins();
Map<String, Class<? extends TableGroup>> tableGroupByName = tableGroupJoins.stream()
.map( TableGroupJoin::getJoinedGroup )
.collect( Collectors.toMap(
Expand Down
Expand Up @@ -8,6 +8,7 @@

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
Expand Down Expand Up @@ -155,7 +156,7 @@ void testFetchLoadPlanBuildingWithDeepSubgraph() {

// Check the from-clause
assertEntityValuedJoinedGroup( sqlAst, "owner", Person.class, tableGroup -> {
Set<TableGroupJoin> tableGroupJoins = tableGroup.getTableGroupJoins();
List<TableGroupJoin> tableGroupJoins = tableGroup.getTableGroupJoins();
Map<String, Class<? extends TableGroup>> tableGroupByName = tableGroupJoins.stream()
.map( TableGroupJoin::getJoinedGroup )
.collect( Collectors.toMap(
Expand Down
Expand Up @@ -8,6 +8,7 @@

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
Expand Down Expand Up @@ -157,7 +158,7 @@ void testFetchSemanticsWithDeepSubgraph() {

// Check the from-clause
assertEntityValuedJoinedGroup( sqlAst, "owner", Person.class, tableGroup -> {
Set<TableGroupJoin> tableGroupJoins = tableGroup.getTableGroupJoins();
List<TableGroupJoin> tableGroupJoins = tableGroup.getTableGroupJoins();
Map<String, Class<? extends TableGroup>> tableGroupByName = tableGroupJoins.stream()
.map( TableGroupJoin::getJoinedGroup )
.collect( Collectors.toMap(
Expand Down

0 comments on commit 222e3fb

Please sign in to comment.