Guest User

Untitled

a guest
Jul 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. // Class
  2. class Book {
  3.  
  4. static hasMany = [:authors => Author]
  5.  
  6. Author author
  7. String name
  8. String email
  9.  
  10. static constraints = {
  11. name :validate => { it.size() > 30 }
  12. email :email => true, :blank => false
  13. }
  14. String toString() { "$id: $name" }
  15. }
  16.  
  17. // Aspect
  18. aspect Book {
  19. declare @Entity Book.class
  20. }
  21.  
  22. // Aspect
  23. aspect Lister<T> {
  24.  
  25. in template
  26.  
  27. declare static List<T> *.list(int max=-1, int offset=0) {
  28. template.list(T, max, offset) as List<T>
  29. }
  30. declare T *.get(Long id) {
  31. template.get(id) as T
  32. }
  33. declare T findBy/s/() {
  34. /* return */ template.execQuery(s.convertToQuery())
  35. }
  36. }
  37.  
  38. // DI
  39. objects {
  40. SessionFactory sessionFactory {
  41. wire = :byType
  42. }
  43.  
  44. HibernateTemplate template {
  45. sessionFactory = sessionFactory
  46. }
  47. }
Add Comment
Please, Sign In to add comment