File tree Expand file tree Collapse file tree 2 files changed +69
-0
lines changed
grails-datastore-gorm-tck/src/main/groovy/grails/gorm/tests
grails-datastore-gorm/src/main/groovy/grails/gorm Expand file tree Collapse file tree 2 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 1+ package grails.gorm.tests
2+
3+ import grails.gorm.annotation.Entity
4+ import groovy.transform.CompileStatic
5+
6+ class WhereLazySpec extends GormDatastoreSpec {
7+
8+ @Override
9+ List getDomainClasses () {
10+ [Product ]
11+ }
12+
13+ void createProducts () {
14+ new Product (name : ' tshirt' , color : ' red' ). save(flush : true )
15+ new Product (name : ' tshirt' , color : ' orange' ). save(flush : true )
16+ new Product (name : ' tshirt' , color : ' yellow' ). save(flush : true )
17+ new Product (name : ' tshirt' , color : ' orange' ). save(flush : true )
18+ new Product (name : ' tshirt' , color : ' blue' ). save(flush : true )
19+ }
20+
21+ void " test deleteAll with whereLazy" () {
22+ setup :
23+ createProducts()
24+
25+ when :
26+ Product . removeAllByColor(" orange" )
27+
28+ then :
29+ Product . count() == 3
30+
31+ cleanup :
32+ Product . deleteAll()
33+
34+ }
35+
36+ void " test updateAll with whereLazy" () {
37+ setup :
38+ createProducts()
39+
40+ when :
41+ Product . updateAll(" orange" )
42+
43+ then :
44+ Product . countByName(' tshirt' ) == 3
45+ Product . countByName(' t-shirt orange' ) == 2
46+
47+ cleanup :
48+ Product . deleteAll()
49+ }
50+
51+ }
52+
53+ @CompileStatic
54+ @Entity
55+ class Product {
56+
57+ String name
58+ String color
59+
60+ static Number removeAllByColor (String givenColor ) {
61+ whereLazy { color == givenColor }. deleteAll()
62+ }
63+
64+ static Number updateAll (String givenColor ) {
65+ whereLazy {color == givenColor}. updateAll([name : ' t-shirt ' + givenColor])
66+ }
67+ }
Original file line number Diff line number Diff line change @@ -557,6 +557,7 @@ class DetachedCriteria<T> extends AbstractDetachedCriteria<T> implements GormOpe
557557 */
558558 Number deleteAll () {
559559 GormEnhancer . findStaticApi(targetClass, connectionName). withDatastoreSession { Session session ->
560+ applyLazyCriteria()
560561 session. deleteAll(this )
561562 }
562563 }
@@ -568,6 +569,7 @@ class DetachedCriteria<T> extends AbstractDetachedCriteria<T> implements GormOpe
568569 */
569570 Number updateAll (Map properties ) {
570571 GormEnhancer . findStaticApi(targetClass, connectionName). withDatastoreSession { Session session ->
572+ applyLazyCriteria()
571573 session. updateAll(this , properties)
572574 }
573575 }
You can’t perform that action at this time.
0 commit comments