Chinese Configuration

Last updated by admin 3 years ago

??

????

???????????????"%PROJECT_HOME%grails-appconf"???????????("BootStrap")??????Grails ?????:

class ExampleBootStrap {

init = { servletContext -> // init app } destroy = { // destroy app } }





???????????"init"??????"destroy" ????????

????"destroy"?????????"????"??????????????????shutdown???.??????????

????????????init?????????

?????

??????"DataSource"???????????Grails??????????HSQLDB?????schema?????????????????????:

  • url - ????JDBC??
  • driverClassName - JDBC?????
  • username - ???
  • password - ??

class HsqlDataSource {
   String dbCreate = "update"
   String url = "jdbc:hsqldb:hsql://localhost"
   String driverClassName = "org.hsqldb.jdbcDriver"
   String username = "sa"
   String password = ""
}


???

???????org.apache.commons.dbcp.BasicDataSource,???????????????????????????????????"pooling"???false???????org.springframework.jdbc.datasource.DriverManagerDataSource???DriverManagerDataSource????????????

@Property boolean pooling = false




???????

?????Grails???"dbCreate"??????????????????:

String dbCreate= "update"




???????????????????????dbCreate????????create,create-drop?

??

?????Grails??3???????{{DevelopmentDataSource}}, {{ProductionDataSource}} and {{TestDataSource}}. ??????????????????Grails?????????????????????????

grails run-app      // ???????? "development" ???
grails dev run-app  // runs with the "development" data source
grails prod run-app // runs with the production data source
grails test run-app // runs with the test data source




??????????????????grails-app/views ?????web-app/WEB-INF/grails-app/?, ??grails??????????. ???????????_??_????????

???????????WAR?????????????????_production_:

grails war       // Packages the application with the "production" data source
grails dev war   // Packages the application with the "development" data source
grails prod war  // Packages the application with the "production" data source




??????????????{{BookDataSource}} ????????????

grails -Dgrails.env=book run-app




???

????????org.apache.commons.dbcp.BasicDataSource, ??????????????????????????????????????"pooling"???????false??????org.springframework.jdbc.datasource.DriverManagerDataSource . ????????DriverManagerDataSource ????????????

boolean pooling = false




SQL????

??Grails??????SQL??????????????Grails?????:

def logSql = true




??????? Dialect

??Hibernate???????Dialect????????????'dialect'?????????dialect:

def dialect = MySQLDialect.class




???????

Grilas GORM??Hibernate???/?????????????Hibernate?????????

Hibernate?????SQL????????:

  • DB2 7.1, 7.2, 8.1
  • HSQL DB
  • HypersonicSQL 1.61, 1.7.0, 1.7.2, 1.8
  • Microsoft SQL Server 2000
  • MySQL 3.23, 4.0, 4.1, 5.0
  • Oracle 8i, 9i, 10g
  • PostgreSQL 7.1.2, 7.2, 7.3, 7.4, 8.0, 8.1
  • SAP DB 7.3
  • Sybase 12.5 (JConnect 5.5)
  • Timesten 5.1
Hibernate??????????????????????????????:
  • Apache Derby
  • HP NonStop SQL/MX 2.0 (requires Dialect from HP)
  • Firebird (1.5 with JayBird 1.01 tested)
  • FrontBase
  • Informix
  • Ingres
  • Interbase (6.0.1 tested)
  • Mckoi SQL
  • Pointbase Embedded (4.3 tested)
  • Progress 9

??MySQL

???????MySQL?java??:

http://www.mysql.com/products/connector/j/

?????? mysql*.jar (not the debug jar)???grails???lib???. ?ApplicationDataSource????????.

class ApplicationDataSource {
    boolean pooling = true
    String dbCreate = "create-drop"
    String url = "jdbc:mysql://localhost/yourDB"
    String driverClassName = "com.mysql.jdbc.Driver"
    String username = "yourUser"
    String password = "yourPassword"
}




??spring/resource.xml??JNDI?????

???????????????????JNDI????????J2EE??????????????????????????????????????????"dataSource"????"org.springframework.jndi.JndiObjectFactoryBean"??bean, Grails ?????????bean?????grails-app/conf/ ?????.

??(????????????JNDI??)?

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/myDataSource" />
  </bean>




??: ????Grails 0.3???? (?http://jira.codehaus.org/browse/GRAILS-272)

????? (??? 0.5)

????????????????????????????????????URI??????JAR????

???????? application.properties??app.name????

??Log4J

&nbsp;?"web-app/WEB-INF/log4j.properties"????? Log4j???.???Log4j??????.

Log4j Hibernate Output

??? ???SQL??,???????log4j.properties?

tmp/war/WEB-INF
??
log4j.logger.org.hibernate=debug, stdout