From d903c414146d67a78d1c6e9d1350047c00489ba2 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Thu, 25 May 2023 10:51:59 +0200 Subject: [PATCH] HHH-16668 Fix SqmWindow copy of partition and order lists --- .../query/sqm/tree/expression/SqmWindow.java | 29 ++++++++++--------- .../criteria/CriteriaWindowFunctionTest.java | 4 ++- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmWindow.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmWindow.java index 0570d86b42..576dc4738d 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmWindow.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmWindow.java @@ -28,6 +28,7 @@ import jakarta.persistence.criteria.Order; import static org.hibernate.query.sqm.FrameExclusion.NO_OTHERS; import static org.hibernate.query.sqm.FrameKind.CURRENT_ROW; import static org.hibernate.query.sqm.FrameKind.UNBOUNDED_PRECEDING; +import static org.hibernate.query.sqm.FrameMode.GROUPS; import static org.hibernate.query.sqm.FrameMode.RANGE; import static org.hibernate.query.sqm.FrameMode.ROWS; @@ -114,28 +115,28 @@ public class SqmWindow extends AbstractSqmNode implements JpaWindow, SqmVisitabl @Override public JpaWindow frameRows(JpaWindowFrame startFrame, JpaWindowFrame endFrame) { - return this.setFrames(FrameMode.ROWS, startFrame, endFrame); + return this.setFrames( ROWS, startFrame, endFrame ); } @Override public JpaWindow frameRange(JpaWindowFrame startFrame, JpaWindowFrame endFrame) { - return this.setFrames(FrameMode.RANGE, startFrame, endFrame); + return this.setFrames( RANGE, startFrame, endFrame ); } @Override public JpaWindow frameGroups(JpaWindowFrame startFrame, JpaWindowFrame endFrame) { - return this.setFrames(FrameMode.GROUPS, startFrame, endFrame); + return this.setFrames( GROUPS, startFrame, endFrame ); } private SqmWindow setFrames(FrameMode frameMode, JpaWindowFrame startFrame, JpaWindowFrame endFrame) { this.mode = frameMode; - if (startFrame != null) { + if ( startFrame != null ) { this.startKind = startFrame.getKind(); this.startExpression = (SqmExpression) startFrame.getExpression(); } - if (endFrame != null) { + if ( endFrame != null ) { this.endKind = endFrame.getKind(); this.endExpression = (SqmExpression) endFrame.getExpression(); } @@ -150,15 +151,15 @@ public class SqmWindow extends AbstractSqmNode implements JpaWindow, SqmVisitabl @Override public JpaWindow partitionBy(Expression... expressions) { - for (Expression expression : expressions) { - this.partitions.add((SqmExpression) expression); + for ( Expression expression : expressions ) { + this.partitions.add( (SqmExpression) expression ); } return this; } @Override public JpaWindow orderBy(Order... orders) { - for (Order order : orders) { + for ( Order order : orders ) { this.orderList.add( (SqmSortSpecification) order ); } return this; @@ -169,13 +170,13 @@ public class SqmWindow extends AbstractSqmNode implements JpaWindow, SqmVisitabl if ( existing != null ) { return existing; } - final List> partitionsCopy = new ArrayList<>( this.partitions.size() ); - for ( SqmExpression partition : this.partitions ) { - partitions.add( partition.copy( context ) ); + final List> partitionsCopy = new ArrayList<>( partitions.size() ); + for ( SqmExpression partition : partitions ) { + partitionsCopy.add( partition.copy( context ) ); } - final List orderListCopy = new ArrayList<>( this.orderList.size() ); - for ( SqmSortSpecification sortSpecification : this.orderList ) { - orderList.add( sortSpecification.copy( context ) ); + final List orderListCopy = new ArrayList<>( orderList.size() ); + for ( SqmSortSpecification sortSpecification : orderList ) { + orderListCopy.add( sortSpecification.copy( context ) ); } return context.registerCopy( this, diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/CriteriaWindowFunctionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/CriteriaWindowFunctionTest.java index e2e998fe69..d257387c9c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/CriteriaWindowFunctionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/CriteriaWindowFunctionTest.java @@ -9,6 +9,7 @@ package org.hibernate.orm.test.query.criteria; import java.util.Date; import java.util.List; +import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.SQLServerDialect; import org.hibernate.query.criteria.HibernateCriteriaBuilder; @@ -23,6 +24,7 @@ import org.hibernate.testing.orm.junit.RequiresDialectFeature; import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.testing.orm.junit.Setting; import org.hibernate.testing.orm.junit.SkipForDialect; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -39,7 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; /** * @author Marco Belladelli */ -@ServiceRegistry +@ServiceRegistry(settings = @Setting(name = AvailableSettings.CRITERIA_COPY_TREE, value = "true")) @DomainModel(standardModels = StandardDomainModel.GAMBIT) @SessionFactory @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsWindowFunctions.class)