Skip to content

Instantly share code, notes, and snippets.

@chanwit
Created December 26, 2010 17:38
Show Gist options
  • Select an option

  • Save chanwit/755526 to your computer and use it in GitHub Desktop.

Select an option

Save chanwit/755526 to your computer and use it in GitHub Desktop.
// Class
class Book {
static hasMany = [:authors => Author]
Author author
String name
String email
static constraints = {
name :validate => { it.size() > 30 }
email :email => true, :blank => false
}
String toString() { "$id: $name" }
}
// Aspect
aspect Book {
declare @Entity Book.class
}
// Aspect
aspect Lister<T> {
in template
declare static List<T> *.list(int max=-1, int offset=0) {
template.list(T, max, offset) as List<T>
}
declare T *.get(Long id) {
template.get(id) as T
}
declare T findBy/s/() {
/* return */ template.execQuery(s.convertToQuery())
}
}
// DI
objects {
SessionFactory sessionFactory {
wire = :byType
}
HibernateTemplate template {
sessionFactory = sessionFactory
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment