Grails多数据源

dataSource {
pooled = true
driverClassName = "oracle.jdbc.driver.OracleDriver"


dialect = org.hibernate.dialect.Oracle10gDialect


}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
//            url = "jdbc:oracle:thin:@localhost:1521:rcjl"
url = "jdbc:oracle:thin:@192.168.1.219:1521:sue"
//            url = "jdbc:oracle:thin:@"******":1521:rcjl"
username = ""******""
password = "******"
//            logSql = true
}
dataSource_lookup {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
//            url = "jdbc:oracle:thin:@localhost:1521:rcjl"
url = "jdbc:oracle:thin:@192.168.1.219:1521:rcjl"
//            url = "jdbc:oracle:thin:@"******":1521:rcjl"
username = ""******""
password = ""******""
//            logSql = true
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:oracle:thin:@192.168.1.219:1521:sue"
//            url = "jdbc:oracle:thin:@localhost:1521:rcjl"
username = ""******""
password = ""******""


}
dataSource_lookup {
dbCreate = "update"
url = "jdbc:oracle:thin:@192.168.1.219:1521:rcjl"
//            url = "jdbc:oracle:thin:@localhost:1521:rcjl"
username = ""******""
password = ""******""
}


}
production {
dataSource {
dbCreate = "update"
//            url = "jdbc:oracle:thin:@192.168.1.219:1521:rcjl"
//            url = "jdbc:oracle:thin:@"******":1521:rcjl"
url = "jdbc:oracle:thin:@localhost:1521:rcjl"
//            url = "jdbc:oracle:thin:@localhost:1521:rcjl"
pooled = true
//            username = "scott"
username = ""******""
password = ""******""
dialect = org.hibernate.dialect.Oracle10gDialect
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
//                validationQuery="SELECT 1"
validationQuery="select 1 from dual"
}
}
dataSource_lookup {
dbCreate = "update"
//            url = "jdbc:oracle:thin:@192.168.1.219:1521:rcjl"
//            url = "jdbc:oracle:thin:@"******":1521:rcjl"
url = "jdbc:oracle:thin:@localhost:1521:rcjl"
//            url = "jdbc:oracle:thin:@localhost:1521:rcjl"
pooled = true
//            username = "scott"
username = ""******""
password = ""******""
dialect = org.hibernate.dialect.Oracle10gDialect
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
//                validationQuery="SELECT 1"
validationQuery="select 1 from dual"
}
}
}
}


在按制器或服务中直接定义就可以用
import groovy.sql.Sql




class TestController {


def dataSource_lookup


def index() {}
def testname(){
      def sql=new Sql(dataSource_lookup)
def a=sql.rows("select * from T_BASE where sf_id='650203199109142128'")


}
}


在域类中
class ZipCode {
   String code


   static mapping = {
      datasource 'lookup'
   }
}
class ZipCode {
   String code


   static mapping = {
      datasources(['lookup', 'DEFAULT'])
   }
}
class ZipCode {
   String code


   static mapping = {
      datasource 'ALL'
   }
}
class ZipCode {
   String code


   static mapping = {
      datasources(['lookup', 'auditing'])
   }
}
def zipCode = ZipCode.auditing.get(42)

zipCode.auditing.save()

你可能感兴趣的:(groovy,garils)