Created
December 26, 2010 17:38
-
-
Save chanwit/755526 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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