WEB开发网
开发学院软件开发Java 实战 Groovy: 用 Groovy 打造服务器端 阅读

实战 Groovy: 用 Groovy 打造服务器端

 2009-11-19 00:00:00 来源:WEB开发网   
核心提示: 清单 6. 一个诊断 Groovletimportcom.vanward.resource.hibernate.factory.DefaultHibernateSessionFactory/***TestsVMversionfromenvironment-note,even1.5will*cau


清单 6. 一个诊断 Groovlet
import 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> 
""" 

上一页  1 2 3 4 5 6 7 8 9 10  下一页

Tags:实战 Groovy Groovy

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接