Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

GRAILS-9839 - Add the possibility of get a ScrollableResults object from named queries #330

Closed
wants to merge 2 commits into from

3 participants

@ivogallego

I hope it helps...

Url to the issue: http://jira.grails.org/browse/GRAILS-9839

@jeffbrown jeffbrown was assigned
@jeffbrown
Owner

Ivan,

Would you be willing to put together a corresponding pull request for https://github.com/grails/grails-doc?

@ivogallego

Yes, no problem, I'll try to do it for today.

@ivogallego

Ok, I've already done another pull request for this in the grails-doc project.

@lhotari lhotari closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 13, 2013
  1. GRAILS-9839 - Add the possibility of get a ScrollableResults object f…

    Ivan Gallego authored
    …rom named queries
Commits on Feb 14, 2013
  1. Merge remote-tracking branch 'upstream/master'

    Ivan Gallego authored
This page is out of date. Refresh to see the latest.
View
8 ...bernate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/cfg/HibernateNamedQueriesBuilder.groovy
@@ -183,6 +183,14 @@ class NamedCriteriaProxy<T> {
domainClass.clazz.withCriteria(countClosure)
}
+ def scroll(Closure additionalCriteriaClosure = null) {
+ def scrollClosure = {
+ queryBuilder = delegate
+ invokeCriteriaClosure(additionalCriteriaClosure)
+ }
+ domainClass.clazz.createCriteria().scroll(scrollClosure)
+ }
+
def findWhere(params) {
findAllWhere(params, true)
}
View
31 ...est-suite-persistence/src/test/groovy/org/codehaus/groovy/grails/orm/hibernate/NamedCriteriaTests.groovy
@@ -895,4 +895,35 @@ class NamedCriteriaTests extends AbstractGrailsHibernateTests {
def pub = NamedCriteriaPublication.recentPublications.findWhere(title: 'Book Number 2')
assertEquals 'Book Number 2', pub.title
}
+
+ void testScrollWithNamedQuery() {
+ def now = new Date()
+ (1..5).each {num ->
+ assert new NamedCriteriaPublication(title: "Book Number ${num}",
+ datePublished: now).save()
+ }
+
+ def sr = NamedCriteriaPublication.recentPublications.scroll()
+ def res = []
+ while (sr.next()) {
+ res << sr.get(0)
+ }
+ sr.close()
+ assertEquals 5, res.size()
+
+ sr = NamedCriteriaPublication.recentPublications.scroll({
+ or{
+ eq 'title', 'Book Number 1'
+ eq 'title', 'Book Number 2'
+ }
+ })
+ res = []
+ while (sr.next()) {
+ res << sr.get(0)
+ }
+ sr.close()
+ assertEquals 2, res.size()
+ assertTrue 'Book Number 1' in res.title
+ assertFalse 'Book Number 3' in res.title
+ }
}
Something went wrong with that request. Please try again.