ITeye博客

Grails

共 13 篇文章

Property configuration of dataSource

def props = new Properties() InputStream is = new BufferedInputStream(new FileInputStream("${System.getenv("SITEHOME")}/config/cms.properties")) props.load(is) is.close() environments { test { dataSource { dbCreate = "create" // one of 'create', 'create-drop','update' driverClassName = "org.hsqldb.…

2008-07-11 08:42 · Grails · HTML · CMS · HSQLDB · JDBC · Hibernate

Writing the <g:if> tag in a tag library

The internal if/else tags that come with Grails translate directly into if(..) {} else {} at the syntax level to improve performance of such core tags . But you can quite easily write if/else tags using the pageScope object and Grails' standard tags for example: def ifSomething = { attrs, body -> p…

2008-06-24 11:51 · Grails · performance · Grails

Calling static methods on metaclass

1、MyClass with a static method class MyClass { static processList(list) { // does something } } 2、 Calling static method processList doProcessList(String className, list) { MetaClass mc = GroovySystem.metaClassRegistry.getMetaClass(Class.forName(className)) mc.invokeStaticMethod(‘processList’, list…

2008-06-15 09:37 · Grails

List of all domain classes in BootStrap

import org.codehaus.groovy.grails.commons.ApplicationHolder class BootStrap { def init = {servletContext -> ApplicationHolder.application.domainClasses.each() { println it.fullName // full name with package println it.name // simple class name it.metaClass.delete = {-> throw new RuntimeException("D…

2008-06-14 22:02 · Grails · HTML · Groovy · Grails

Grails ORM id generator in Oracle

默认自动建立名称为HIBERNATE_SEQUENCE的sequence,可以在domain里用以下方法指定: static mapping = { id generator: 'sequence', params: [sequence: 'seq_name'] }

2008-06-14 20:18 · Grails · Hibernate · ORM · Oracle · Grails

Get applicationContext in Bootstrap

import org.codehaus.groovy.grails.commons.ApplicationAttributes def ctx = servletContext.getAttribute(ApplicationAttributes.APPLICATION_CONTEXT) http://www.nabble.com/Bootstrap-and-applicationContext-td16302106.html#a16302106

2008-06-14 20:00 · Grails · HTML · Groovy · Grails

Groovy字符串替换一例

将param替换成paramValue def queryContent = "select * from query where id=${param}" def regex = '\\$\\{param\\}' def matcher = (queryContent =~ /${regex}/) queryContent = matcher.replaceAll('paramValue') 参考: http://docs.codehaus.org/display/GROOVY/Tutorial+5+-+Capturing+regex+groups

2008-06-12 17:11 · Grails · Groovy

GORM many-to-many namimg convention

I have class named User and another one named Role and they are related to each other in a many-to-many way, a user has many roles and in a role there are many users Besides the user and role tables I get another table named role_user which has only two fields: roles_id and users_id roles_id refers…

2008-06-10 11:50 · Grails

Difference between sql.rows().each and sql.eachRow

1、 sql.rows returns a List of g.sql. GroovyRowResult which implements Map def results = [] sql.rows(queryString, args).each {Map row -> println "row.dump():${row.dump()}" results << row } 2、 sql. eachRow iterates providing a g.sql. GroovyResultSet which implements java.sql.ResultSet. ResultSet is n…

2008-06-08 10:20 · Grails · HTML · SQL

The main advantage of using the Spring DSL

The main advantage of using the Spring DSL is that you can now mix logic in within your bean definitions, for example based on the environment : import grails.util.* beans { switch(GrailsUtil.environment) { case "production": myBean(my.company.MyBeanImpl) { bookService = ref("bookService") } break …

2008-05-26 10:56 · Grails · Spring · Grails · Bean

Configure a bean with map property

1、Using XML <bean id="sqlService" class="SqlService"> <property name="dataSourceMap"> <map> <entry key="a"> <ref bean="dataSourceA"/> </entry> <entry key="b"> <ref bean="dataSourceB"/> </entry> </map> </property> </bean> 2、Using the Spring DSL beans = { def dsMap = new HashMap() dsMap.put('a', ref(…

2008-05-26 10:33 · Grails · Spring · XML · Bean

Configure a bean with factory using Spring DSL

1、How do I configure a bean like this using Spring DSL ? <bean id="mailSession" class="javax.mail.Session" factory-method="getInstance"> <constructor-arg> <props> <prop key="mail.smtp.auth">true</prop> </props> </constructor-arg> <constructor-arg ref="smtpAuthenticator" /> </bean> 2、 To answer my o…

2008-05-22 17:38 · Grails · Spring · Bean

Grails学习笔记-1

1、安装JDK和Grails后,设置JAVA_HOME和GRAILS_HOME sudo gedit /etc/environment 加入以下: 1. JAVA_HOME=/usr/lib/j2sdk15-sun //JDK安装路经 2. GRAILS_HOME=/home/boogie/dev/grails //GRails路径 3. PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$GRAILS_HOME/bin" . /etc/environment 2、Mysql数据库编码问…

2007-11-22 11:52 · Grails · Java · MySQL · Grails · SUN · JDK