HHH-16668 Fix SqmWindow copy of partition and order lists
This commit is contained in:
parent
3f54b1261b
commit
d903c41414
|
@ -28,6 +28,7 @@ import jakarta.persistence.criteria.Order;
|
||||||
import static org.hibernate.query.sqm.FrameExclusion.NO_OTHERS;
|
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.CURRENT_ROW;
|
||||||
import static org.hibernate.query.sqm.FrameKind.UNBOUNDED_PRECEDING;
|
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.RANGE;
|
||||||
import static org.hibernate.query.sqm.FrameMode.ROWS;
|
import static org.hibernate.query.sqm.FrameMode.ROWS;
|
||||||
|
|
||||||
|
@ -114,28 +115,28 @@ public class SqmWindow extends AbstractSqmNode implements JpaWindow, SqmVisitabl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JpaWindow frameRows(JpaWindowFrame startFrame, JpaWindowFrame endFrame) {
|
public JpaWindow frameRows(JpaWindowFrame startFrame, JpaWindowFrame endFrame) {
|
||||||
return this.setFrames(FrameMode.ROWS, startFrame, endFrame);
|
return this.setFrames( ROWS, startFrame, endFrame );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JpaWindow frameRange(JpaWindowFrame startFrame, JpaWindowFrame endFrame) {
|
public JpaWindow frameRange(JpaWindowFrame startFrame, JpaWindowFrame endFrame) {
|
||||||
return this.setFrames(FrameMode.RANGE, startFrame, endFrame);
|
return this.setFrames( RANGE, startFrame, endFrame );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JpaWindow frameGroups(JpaWindowFrame startFrame, JpaWindowFrame endFrame) {
|
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) {
|
private SqmWindow setFrames(FrameMode frameMode, JpaWindowFrame startFrame, JpaWindowFrame endFrame) {
|
||||||
this.mode = frameMode;
|
this.mode = frameMode;
|
||||||
if (startFrame != null) {
|
if ( startFrame != null ) {
|
||||||
this.startKind = startFrame.getKind();
|
this.startKind = startFrame.getKind();
|
||||||
this.startExpression = (SqmExpression<?>) startFrame.getExpression();
|
this.startExpression = (SqmExpression<?>) startFrame.getExpression();
|
||||||
}
|
}
|
||||||
if (endFrame != null) {
|
if ( endFrame != null ) {
|
||||||
this.endKind = endFrame.getKind();
|
this.endKind = endFrame.getKind();
|
||||||
this.endExpression = (SqmExpression<?>) endFrame.getExpression();
|
this.endExpression = (SqmExpression<?>) endFrame.getExpression();
|
||||||
}
|
}
|
||||||
|
@ -150,15 +151,15 @@ public class SqmWindow extends AbstractSqmNode implements JpaWindow, SqmVisitabl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JpaWindow partitionBy(Expression<?>... expressions) {
|
public JpaWindow partitionBy(Expression<?>... expressions) {
|
||||||
for (Expression<?> expression : expressions) {
|
for ( Expression<?> expression : expressions ) {
|
||||||
this.partitions.add((SqmExpression<?>) expression);
|
this.partitions.add( (SqmExpression<?>) expression );
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JpaWindow orderBy(Order... orders) {
|
public JpaWindow orderBy(Order... orders) {
|
||||||
for (Order order : orders) {
|
for ( Order order : orders ) {
|
||||||
this.orderList.add( (SqmSortSpecification) order );
|
this.orderList.add( (SqmSortSpecification) order );
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
@ -169,13 +170,13 @@ public class SqmWindow extends AbstractSqmNode implements JpaWindow, SqmVisitabl
|
||||||
if ( existing != null ) {
|
if ( existing != null ) {
|
||||||
return existing;
|
return existing;
|
||||||
}
|
}
|
||||||
final List<SqmExpression<?>> partitionsCopy = new ArrayList<>( this.partitions.size() );
|
final List<SqmExpression<?>> partitionsCopy = new ArrayList<>( partitions.size() );
|
||||||
for ( SqmExpression<?> partition : this.partitions ) {
|
for ( SqmExpression<?> partition : partitions ) {
|
||||||
partitions.add( partition.copy( context ) );
|
partitionsCopy.add( partition.copy( context ) );
|
||||||
}
|
}
|
||||||
final List<SqmSortSpecification> orderListCopy = new ArrayList<>( this.orderList.size() );
|
final List<SqmSortSpecification> orderListCopy = new ArrayList<>( orderList.size() );
|
||||||
for ( SqmSortSpecification sortSpecification : this.orderList ) {
|
for ( SqmSortSpecification sortSpecification : orderList ) {
|
||||||
orderList.add( sortSpecification.copy( context ) );
|
orderListCopy.add( sortSpecification.copy( context ) );
|
||||||
}
|
}
|
||||||
return context.registerCopy(
|
return context.registerCopy(
|
||||||
this,
|
this,
|
||||||
|
|
|
@ -9,6 +9,7 @@ package org.hibernate.orm.test.query.criteria;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.dialect.DB2Dialect;
|
import org.hibernate.dialect.DB2Dialect;
|
||||||
import org.hibernate.dialect.SQLServerDialect;
|
import org.hibernate.dialect.SQLServerDialect;
|
||||||
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
|
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.ServiceRegistry;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.Setting;
|
||||||
import org.hibernate.testing.orm.junit.SkipForDialect;
|
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
@ -39,7 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
/**
|
/**
|
||||||
* @author Marco Belladelli
|
* @author Marco Belladelli
|
||||||
*/
|
*/
|
||||||
@ServiceRegistry
|
@ServiceRegistry(settings = @Setting(name = AvailableSettings.CRITERIA_COPY_TREE, value = "true"))
|
||||||
@DomainModel(standardModels = StandardDomainModel.GAMBIT)
|
@DomainModel(standardModels = StandardDomainModel.GAMBIT)
|
||||||
@SessionFactory
|
@SessionFactory
|
||||||
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsWindowFunctions.class)
|
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsWindowFunctions.class)
|
||||||
|
|
Loading…
Reference in New Issue