gorm - Grails - find where date ranges overlap -


i have grails domain object startdate , enddate property.

what's best way find objects range [startdate, enddate] overlaps specified date range? know how in sql wonder if there's grails/gorm magic more succinctly.

also, enddate optional property.

the sql / jpql query

from myobject obj obj.startdate <= ?1 , (obj.enddate null or obj.enddate >= ?2) 

two ways embrace grails/gorm in case:

lazy:-

def today = new date() def query = myobject.where {     startdate <= (today - 10) && (enddate == null || enddate >= today + 10) } def listofmyobjects = query.list() 

eager:-

def today = new date() def listofmyobjects = myobject.findall {//or find{} if need first occurance     startdate <= (today - 10) && (enddate == null || enddate >= today + 10) } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -