Guest User

Untitled

a guest
Jun 25th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. // Import.groovy
  2.  
  3. includeTargets << grailsScript("Bootstrap")
  4.  
  5. target(main: "Import some data...") {
  6. depends(bootstrap)
  7.  
  8. def Channel = grailsApp.classLoader.loadClass("content.Channel")
  9.  
  10. def c
  11.  
  12. // works: saving a valid Channel succeeds
  13. c = Channel.newInstance(title:"A Channel", slug:"a-channel", position:0).validate()
  14.  
  15. // doesn't work: saving an invalid Channel fails with exception
  16. c = Channel.newInstance().validate()
  17.  
  18. // this line is never reached due to exception
  19. println(c.errors)
  20.  
  21. }
  22.  
  23. setDefaultTarget(main)
  24.  
  25. // Import.groovy
  26.  
  27. def Channel = grailsApp.classLoader.loadClass("content.Channel")
  28.  
  29. def c
  30. c = Channel.newInstance(title:"A Channel", slug:"a-channel", position:0).validate()
  31. c = Channel.newInstance().validate()
  32. println(c.errors)
  33.  
  34. // Import.groovy
  35.  
  36. includeTargets << grailsScript("Bootstrap")
  37.  
  38. target(main: "Import some data...") {
  39. depends(bootstrap)
  40.  
  41. // added this ------------------------------------------------------
  42. def sessionFactory = appCtx.getBean("sessionFactory")
  43. def session = SessionFactoryUtils.getSession(sessionFactory, true)
  44. TransactionSynchronizationManager.bindResource(
  45. sessionFactory, new SessionHolder(session))
  46. // added this ------------------------------------------------------
  47.  
  48. def Channel = grailsApp.classLoader.loadClass("content.Channel")
  49.  
  50. def c
  51.  
  52. // works: saving a valid Channel succeeds
  53. c = Channel.newInstance(title:"A Channel", slug:"a-channel", position:0).validate()
  54.  
  55. // doesn't work: saving an invalid Channel fails with exception
  56. c = Channel.newInstance().validate()
  57.  
  58. // this line is never reached due to exception
  59. println(c.errors)
  60.  
  61. }
  62.  
  63. setDefaultTarget(main)
Add Comment
Please, Sign In to add comment