Lo que pedía el cuerpo era hacer un intento para incluir Gorm en un ejemplo sencillo de Griffon.
El código completo esta en el siguiente repo (https://github.com/ivanarrizabalaga/BookGorm), y las partes relevantes son:
BuildConfig.groovy:
repositories {griffonHome()mavenLocal()mavenCentral()mavenRepo "http://snapshots.repository.codehaus.org"mavenRepo "http://repository.codehaus.org"mavenRepo "http://download.java.net/maven/2/"mavenRepo "http://repository.jboss.com/maven2/"mavenRepo "http://repo.spring.io/milestone"mavenRepo "http://repo.spring.io/release"}dependencies {runtime "org.grails:grails-datastore-gorm-hibernate4:3.0.0.RELEASE"runtime "org.grails:grails-spring:2.3.6"runtime "com.h2database:h2:1.3.164"compile "org.springframework:spring-expression:3.2.4.RELEASE"}
Initialize.groovy:
//TODO Should be a Spring beannew HibernateDatastoreSpringInitializer("bookgorm").configureForDataSource(new DriverManagerDataSource(Driver.name,"jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE", 'sa', ''))
src/main/bookgorm/Book.groovy:
package bookgormimport grails.persistence.Entity
@Entityclass Book{String titleString authorstatic constraints = {title blank:falseauthor blank:false}}
BookController.groovy:
void loadData(){List books=Book.list()edt{model.books.addAll(books)}}def addBook= {evt=null->Book b=new Book(title:view.titleField.text,author:view.authorField.text)b.save()edt{model.books.add(b)view.titleField.text=""view.authorField.text=""}}def clearAll= {evt=null->Book.executeUpdate("delete Book")edt{model.books.clear()}}
Mola, no?
¡A cuidarse!
No hay comentarios:
Publicar un comentario