HHH-16668 Fix SqmWindow copy of partition and order lists

This commit is contained in:
Marco Belladelli 2023-05-25 10:51:59 +02:00
parent 3f54b1261b
commit d903c41414
No known key found for this signature in database
GPG Key ID: D1D0C3030AE3AA35
2 changed files with 18 additions and 15 deletions

View File

@ -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<SqmExpression<?>> partitionsCopy = new ArrayList<>( this.partitions.size() );
for ( SqmExpression<?> partition : this.partitions ) {
partitions.add( partition.copy( context ) );
final List<SqmExpression<?>> partitionsCopy = new ArrayList<>( partitions.size() );
for ( SqmExpression<?> partition : partitions ) {
partitionsCopy.add( partition.copy( context ) );
}
final List<SqmSortSpecification> orderListCopy = new ArrayList<>( this.orderList.size() );
for ( SqmSortSpecification sortSpecification : this.orderList ) {
orderList.add( sortSpecification.copy( context ) );
final List<SqmSortSpecification> orderListCopy = new ArrayList<>( orderList.size() );
for ( SqmSortSpecification sortSpecification : orderList ) {
orderListCopy.add( sortSpecification.copy( context ) );
}
return context.registerCopy(
this,

View File

@ -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)