DATACMNS-621 - QSort now treats nested paths correctly.
We now inspect intermediate path elements to build sort order accordingly. Original pull request: #111.
This commit is contained in:
committed by
Oliver Gierke
parent
2e62a16f69
commit
95bda862e7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.querydsl;
|
||||
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -34,6 +33,7 @@ import com.mysema.query.types.OrderSpecifier;
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class QSortUnitTests {
|
||||
|
||||
@@ -147,7 +147,7 @@ public class QSortUnitTests {
|
||||
assertThat(result, is(Matchers.<Order> iterableWithSize(2)));
|
||||
assertThat(result, hasItems(new Order(Direction.ASC, "lastname"), new Order(Direction.ASC, "firstname")));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see DATACMNS-566
|
||||
*/
|
||||
@@ -159,6 +159,44 @@ public class QSortUnitTests {
|
||||
|
||||
Sort result = sort.and(new Sort(Direction.ASC, "lastname"));
|
||||
assertThat(result, is(Matchers.<Order> iterableWithSize(2)));
|
||||
assertThat(result, hasItems(new Order(Direction.ASC, "lastname"), new Order(Direction.ASC, user.dateOfBirth.yearMonth().toString())));
|
||||
assertThat(
|
||||
result,
|
||||
hasItems(new Order(Direction.ASC, "lastname"),
|
||||
new Order(Direction.ASC, user.dateOfBirth.yearMonth().toString())));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-621
|
||||
*/
|
||||
@Test
|
||||
public void shouldCreateSortForNestedPathCorrectly() {
|
||||
|
||||
QSort sort = new QSort(QUserWrapper.userWrapper.user.firstname.asc());
|
||||
|
||||
assertThat(sort, hasItems(new Order(Direction.ASC, "user.firstname")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-621
|
||||
*/
|
||||
@Test
|
||||
public void shouldCreateSortForDeepNestedPathCorrectly() {
|
||||
|
||||
QSort sort = new QSort(QWrapperForUserWrapper.wrapperForUserWrapper.wrapper.user.firstname.asc());
|
||||
|
||||
assertThat(sort, hasItems(new Order(Direction.ASC, "wrapper.user.firstname")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-621
|
||||
*/
|
||||
@Test
|
||||
public void shouldCreateSortForReallyDeepNestedPathCorrectly() {
|
||||
|
||||
QSort sort = new QSort(
|
||||
QWrapperToWrapWrapperForUserWrapper.wrapperToWrapWrapperForUserWrapper.wrapperForUserWrapper.wrapper.user.firstname
|
||||
.asc());
|
||||
|
||||
assertThat(sort, hasItems(new Order(Direction.ASC, "wrapperForUserWrapper.wrapper.user.firstname")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.querydsl;
|
||||
|
||||
import com.mysema.query.annotations.QueryEntity;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@QueryEntity
|
||||
public class UserWrapper {
|
||||
|
||||
User user;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.querydsl;
|
||||
|
||||
import com.mysema.query.annotations.QueryEntity;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@QueryEntity
|
||||
public class WrapperForUserWrapper {
|
||||
|
||||
UserWrapper wrapper;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.querydsl;
|
||||
|
||||
import com.mysema.query.annotations.QueryEntity;
|
||||
import com.mysema.query.annotations.QueryInit;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@QueryEntity
|
||||
public class WrapperToWrapWrapperForUserWrapper {
|
||||
|
||||
@QueryInit("wrapper.user")//
|
||||
WrapperForUserWrapper wrapperForUserWrapper;
|
||||
}
|
||||
Reference in New Issue
Block a user