Changeset 360 for trunk/grails-app/services
- Timestamp:
- Feb 16, 2010, 10:02:34 AM (15 years ago)
- Location:
- trunk/grails-app/services
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/AssetService.groovy
r352 r360 47 47 r = assetSubItemService.delete(id: assetSubItem.id) 48 48 if(r.error) { 49 log.debug r.error 49 50 fail(code:"asset.subItems.delete.failure") 50 51 break … … 56 57 return result 57 58 58 try {59 result.assetInstance.delete(flush:true)60 return result //Success.61 }62 catch(org.springframework.dao.DataIntegrityViolationException e) {63 return fail(code:"default.delete.failure")64 }59 // Success. 60 // We have handled all the foreign keys so the delete should go forward. 61 // Can't flush here due to cascading from Section and Site. 62 // And without flush there is no point it trying to catch the dao.DataIntegrityViolationException 63 // since that will only happen after leaving the transaction. 64 result.assetInstance.delete() 65 return result 65 66 66 67 } // end withTransaction -
trunk/grails-app/services/AssetSubItemService.groovy
r352 r360 21 21 22 22 def delete(params) { 23 def result = [:] 24 def fail = { Map m -> 25 result.error = [ code: m.code, args: ["AssetSubItem", params.id] ] 26 return result 27 } 23 AssetSubItem.withTransaction { status -> 24 def result = [:] 28 25 29 result.assetSubItemInstance = AssetSubItem.get(params.id) 26 def fail = { Map m -> 27 status.setRollbackOnly() 28 if(result.assetSubItemInstance && m.field) 29 result.assetSubItemInstance.errors.rejectValue(m.field, m.code) 30 result.error = [ code: m.code, args: ["AssetSubItem", params.id] ] 31 return result 32 } 30 33 31 if(!result.assetSubItemInstance) 32 return fail(code:"default.not.found") 34 result.assetSubItemInstance = AssetSubItem.get(params.id) 33 35 34 if(result.assetSubItemInstance.assets)35 return fail(code:"assetSubItem.assets.associated")36 if(!result.assetSubItemInstance) 37 return fail(code:"default.not.found") 36 38 37 if(result.assetSubItemInstance.maintenanceActions) 38 return fail(code:"maintenanceActions.still.associated") 39 for(subItem in result.assetSubItemInstance.subItems) { 40 if(subItem.maintenanceActions) 41 fail(code:"maintenanceActions.still.associated.subItem") 42 } 39 43 40 try { 41 result.assetSubItemInstance.delete(flush:true) 44 if(result.error) 45 return result 46 47 if(result.assetSubItemInstance.maintenanceActions) 48 return fail(code:"maintenanceActions.still.associated") 49 50 if(result.assetSubItemInstance.assets) 51 return fail(code:"assetSubItem.assets.associated") 52 53 // We have handled all the foreign keys so the delete should go forward. 54 // Can't flush here due to cascading from Section and Site. 55 // And without flush there is no point it trying to catch the dao.DataIntegrityViolationException 56 // since that will only happen after leaving the transaction. 57 result.assetSubItemInstance.delete() 42 58 return result //Success. 43 }44 catch(org.springframework.dao.DataIntegrityViolationException e) {45 return fail(code:"default.delete.failure")46 }47 59 60 } // withTransaction 48 61 } 49 62
Note: See TracChangeset
for help on using the changeset viewer.