Skip to content

Commit 7eece4b

Browse files
committed
Progress
1 parent 92858b6 commit 7eece4b

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

Diff for: data-model/src/main/java/io/micronaut/data/model/Page.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ public interface Page<T> extends Slice<T> {
7676
*/
7777
default int getTotalPages() {
7878
int size = getSize();
79-
return size == 0 ? 1 : (int) Math.ceil((double) getTotalSize() / (double) size);
79+
long totalSize = getTotalSize();
80+
if (totalSize == -1) {
81+
throw new IllegalStateException("Page does not contain total count. " +
82+
"It is likely that the Pageable needs to be modified to request this information.");
83+
}
84+
return size == 0 ? 1 : (int) Math.ceil((double) totalSize / (double) size);
8085
}
8186

8287
@Override

Diff for: data-processor/src/test/groovy/io/micronaut/data/processor/sql/BuildQuerySpec.groovy

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ import io.micronaut.data.model.entities.Invoice
2828
import io.micronaut.data.model.query.QueryModel
2929
import io.micronaut.data.model.query.builder.sql.Dialect
3030
import io.micronaut.data.model.query.builder.sql.SqlQueryBuilder
31-
import io.micronaut.data.model.runtime.StoredQuery
3231
import io.micronaut.data.processor.entity.ActivityPeriodEntity
3332
import io.micronaut.data.processor.visitors.AbstractDataSpec
3433
import io.micronaut.data.tck.entities.Author
3534
import io.micronaut.data.tck.entities.Restaurant
3635
import io.micronaut.data.tck.jdbc.entities.EmployeeGroup
37-
import io.micronaut.inject.ExecutableMethod
3836
import spock.lang.Issue
3937
import spock.lang.PendingFeature
4038
import spock.lang.Unroll
@@ -2137,7 +2135,7 @@ interface TestRepository extends GenericRepository<Book, Long> {
21372135
""")
21382136
def findAll = repository.findPossibleMethods("findAll").findFirst().get()
21392137
expect:
2140-
getQuery(findAll) == """SELECT book_.`id`,book_.`author_id`,book_.`genre_id`,book_.`title`,book_.`total_pages`,book_.`publisher_id`,book_.`last_updated`,book_author_.`name` AS author_name,book_author_.`nick_name` AS author_nick_name FROM `book` book_ INNER JOIN `author` book_author_ ON book_.`author_id`=book_author_.`id` WHERE (book_.`id` IN (SELECT book_book_.`id` FROM `book` book_book_ WHERE (book_book_.`id` IN (SELECT book_book_book_.`id` FROM `book` book_book_book_ INNER JOIN `author` book_book_book_author_ ON book_book_book_.`author_id`=book_book_book_author_.`id` ORDER BY book_book_book_author_.`name` ASC,book_book_book_.`title` ASC))"""
2138+
getQuery(findAll) == """SELECT book_.`id`,book_.`author_id`,book_.`genre_id`,book_.`title`,book_.`total_pages`,book_.`publisher_id`,book_.`last_updated`,book_author_.`name` AS author_name,book_author_.`nick_name` AS author_nick_name FROM `book` book_ INNER JOIN `author` book_author_ ON book_.`author_id`=book_author_.`id` WHERE (book_.`id` IN (SELECT book_book_.`id` FROM `book` book_book_ WHERE (book_book_.`id` IN (SELECT book_book_book_.`id` FROM `book` book_book_book_ INNER JOIN `author` book_book_book_author_ ON book_book_book_.`author_id`=book_book_book_author_.`id`))"""
21412139
getParameterRoles(findAll) == ["pageableRequired", "sort"]
21422140
}
21432141

Diff for: data-tck/src/main/groovy/io/micronaut/data/tck/tests/AbstractPageSpec.groovy

+2-5
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,8 @@ abstract class AbstractPageSpec extends Specification {
126126
then:
127127
thrown(IllegalStateException)
128128

129-
when:
130-
page.getTotalSize()
131-
132-
then:
133-
thrown(IllegalStateException)
129+
and:
130+
page.getTotalSize() == -1
134131
}
135132

136133
void "test pageable sort"() {

Diff for: data-tck/src/main/groovy/io/micronaut/data/tck/tests/AbstractRepositorySpec.groovy

+2-6
Original file line numberDiff line numberDiff line change
@@ -683,23 +683,19 @@ abstract class AbstractRepositorySpec extends Specification {
683683
when:
684684
def books1 = bookRepository.listPageableCustomQuery(Pageable.from(0).order("author.name").order("title")).getContent()
685685
def books2 = bookRepository.findAll(Pageable.from(0).order("author.name").order("title")).getContent()
686-
// Duplicate order
687-
def books3 = bookRepository.findAllSorted(Pageable.from(0).order("author.name").order("title")).getContent()
688686
// Order defined only by method
689-
def books4 = bookRepository.findAllSorted(Pageable.from(0)).getContent()
687+
def books3 = bookRepository.findAllSorted(Pageable.from(0)).getContent()
690688
// Extra order
691-
def books5 = bookRepository.findAllSorted2(Pageable.from(0).order("title")).getContent()
689+
def books4 = bookRepository.findAllSorted2(Pageable.from(0).order("title")).getContent()
692690
then:
693691
books1.size() == 6
694692
books2.size() == 6
695693
books3.size() == 6
696694
books4.size() == 6
697-
books5.size() == 6
698695
books1[0].title == "The Border"
699696
books2[0].title == "The Border"
700697
books3[0].title == "The Border"
701698
books4[0].title == "The Border"
702-
books5[0].title == "The Border"
703699
cleanup:
704700
cleanupData()
705701
}

0 commit comments

Comments
 (0)