Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-13884 Order.reverse() contract #3272

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
public class SqmSortSpecification implements JpaOrder {
private final SqmExpression sortExpression;
private final String collation;
private SortOrder sortOrder;
private final SortOrder sortOrder;

private NullPrecedence nullPrecedence;

public SqmSortSpecification(
Expand Down Expand Up @@ -73,8 +74,8 @@ public NullPrecedence getNullPrecedence() {

@Override
public JpaOrder reverse() {
this.sortOrder = this.sortOrder == null ? SortOrder.DESCENDING : sortOrder.reverse();
return this;
SortOrder newSortOrder = this.sortOrder == null ? SortOrder.DESCENDING : sortOrder.reverse();
return new SqmSortSpecification( sortExpression, collation, newSortOrder, nullPrecedence );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.query.sqm.tree.select;

import org.hibernate.query.criteria.JpaOrder;
import org.hibernate.query.sqm.tree.expression.SqmExpression;

import org.hibernate.testing.TestForIssue;
import org.junit.Test;

import static org.hibernate.NullPrecedence.FIRST;
import static org.hibernate.SortOrder.ASCENDING;
import static org.hibernate.SortOrder.DESCENDING;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.mockito.Mockito.mock;

/**
* @author seregamorph
*/
@TestForIssue(jiraKey = "HHH-13884")
public class HHH13884Test {

@Test
public void testDefaultSqmSortSpecificationReverse() {
SqmExpression sortExpression = mock( SqmExpression.class );
String collation = "collation";

SqmSortSpecification order = new SqmSortSpecification( sortExpression, collation, ASCENDING, FIRST );

assertEquals( sortExpression, order.getSortExpression() );
assertEquals( collation, order.getCollation() );
assertEquals( ASCENDING, order.getSortOrder() );
assertEquals( FIRST, order.getNullPrecedence() );

JpaOrder reversed = order.reverse();

assertEquals( DESCENDING, reversed.getSortOrder() );
assertEquals( FIRST, reversed.getNullPrecedence() );

assertNotSame( "Order.reverse() should create new instance", order, reversed );
}
}