实战 Groovy: 用 Groovy 打造服务器端
2009-11-19 00:00:00 来源:WEB开发网
清单 6. 一个诊断 Groovletimport com.vanward.resource.hibernate.factory.DefaultHibernateSessionFactory
/**
* Tests VM version from environment- note, even 1.5 will
* cause an assertion error.
*/
def testVMVersion(){
println "<h3>JVM Version Check: </h3>"
vers = System.getProperty("java.version")
assert vers.startsWith("1.4"): "JVM must be at least 1.4"
println "<p>JVM version: ${vers} </p>"
}
/**
* Attempts to create an instance of a hibernate session. If this
* works we have a connection to a database; additionally, we
* have a properly configured hibernate instance.
*/
def testHibernate(){
println "<h3>Hibernate Configuration Check: </h3>"
try{
sessFactory = DefaultHibernateSessionFactory.getInstance()
session = sessFactory.getHibernateSession()
assert session != null: "Unable to create hibernate session.
Session was null"
println "<p>Hibernate configuration check was successful</p>"
}catch(Throwable tr){
println """
<p>Unable to create hibernate session. Exception type is: <br/>
<i>${tr.toString()} </i><br/>
</p>
"""
}
}
println """
<html><head>
<title>Diagnostics Check</title></head>
<body>
"""
testVMVersion()
testHibernate()
println """
</body></html>
"""
- ››Groovy轻松入门
- ››实战:企业使用交换机VLAN路由配置
- ››实战案例分析:高质量软文对网站百度排名的影响
- ››实战经验浅谈网站搬家后的优化工作
- ››实战Active Directory站点部署与管理,Active Dir...
- ››实战操作主机角色转移,Active Directory系列之十...
- ››实战经验:巧用微博推广淘宝网店
- ››实战iPhone GPS定位系统
- ››实战Linux环境配置DBD:Oracle模块
- ››实战DeviceIoControl系列之一:通过API访问设备驱...
- ››实战DeviceIoControl系列之二:获取软盘/硬盘/光盘...
- ››实战DeviceIoControl系列之三:制作磁盘镜像文件
更多精彩
赞助商链接