Changeset 700


Ignore:
Timestamp:
Nov 1, 2010, 11:29:11 AM (9 years ago)
Author:
gav
Message:

Fix lazy initialization bug and optimise fetching in AssignedGroupService.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/AssignedGroupService.groovy

    r514 r700  
     1import org.hibernate.FetchMode as FM
     2
    13class AssignedGroupService {
    24
     
    4749        }
    4850
    49         result.assignedGroupInstance = AssignedGroup.get(params.id)
     51        result.assignedGroupInstance = AssignedGroup.createCriteria().get {
     52            idEq(params.id.toLong())
     53            fetchMode("personGroup", FM.EAGER)
     54            fetchMode("personGroup.persons", FM.EAGER)
     55        }
    5056
    5157        if(!result.assignedGroupInstance)
     
    7177            }
    7278
    73             result.personGroup = PersonGroup.get(params.personGroup.id)
     79            result.personGroup = PersonGroup.createCriteria().get {
     80                idEq(params.personGroup.id.toLong())
     81                fetchMode("persons", FM.EAGER)
     82            }
    7483
    7584            // Prevent a null property reference.
     
    140149            }
    141150
    142             result.personGroup = PersonGroup.get(params.personGroup.id)
     151            result.personGroup = PersonGroup.createCriteria().get {
     152                idEq(params.personGroup.id.toLong())
     153                fetchMode("persons", FM.EAGER)
     154            }
    143155
    144156            // Prevent a null property reference.
     
    146158                return fail(code:"personGroup.not.found")
    147159
    148             result.personsInGroup = result.personGroup.persons?.sort { p1, p2 -> p1.firstName.compareToIgnoreCase(p2.firstName) }
     160            result.personsInGroup = result.personGroup.persons.sort { p1, p2 -> p1.firstName.compareToIgnoreCase(p2.firstName) }
    149161
    150162            result.assignedGroupInstance = new AssignedGroup()
     
    178190        }
    179191
    180         result.personGroup = PersonGroup.get(params.personGroup?.id)
     192        if(!params.personGroup?.id?.isLong())
     193            return fail(code:"default.not.found")
     194
     195        result.personGroup = PersonGroup.createCriteria().get {
     196            idEq(params.personGroup.id.toLong())
     197            fetchMode("persons", FM.EAGER)
     198        }
    181199
    182200        if(!result.personGroup)
Note: See TracChangeset for help on using the changeset viewer.