public void initReport(File xmlFile, File confFile, File logPrc, File reportPrc, Date runDate) throws InstallException
{
Document bossDoc = converHibernateConfig(xmlFile, confFile);;
String strLogPrc = readFile(logPrc);
String strReportPrc = readFile(reportPrc);
HibernateConfig config = new HibernateConfig();
Session session;
try
{
config.configure(bossDoc);
SessionFactory sessionFactory = config.buildSessionFactory();
session = sessionFactory.openSession();
}catch(Exception exp){
throw new InstallException(exp.getMessage());
}
Transaction tran = null;
try
{
tran = session.beginTransaction();
writeLog("创建WriteLog存储过程");
session.connection().createStatement().execute(strLogPrc);
//writeLog("编译存储过程");
//session.connection().createStatement().execute("compile;");
writeLog("创建dialy_report_proc存储过程");
session.connection().createStatement().execute(strReportPrc);
//writeLog("编译存储过程");
//session.connection().createStatement().execute("compile");
tran.commit();
writeLog("报表数据初始化成功");
}catch(HibernateException exp){
try
{
tran.rollback();
}catch(HibernateException exp1){
throw new InstallException(exp1.getMessage());
}
throw new InstallException(exp.getMessage());
}catch(SQLException exp){
try
{
tran.rollback();
}catch(HibernateException exp1){
throw new InstallException(exp1.getMessage());
}
throw new InstallException(exp.getMessage());
}finally{
try
{
session.close();
}catch(HibernateException exp){
throw new InstallException(exp.getMessage());
}
}
}
另外:需要将存储过程的文件保存为Unix格式,否则不能使用。
此博客展示了一个Java方法initReport,用于初始化报表。通过Hibernate配置会话工厂,打开会话并开启事务,执行创建存储过程的操作。若过程中出现异常,会进行回滚处理。最后关闭会话,同时提醒存储过程文件需保存为Unix格式。
1014

被折叠的 条评论
为什么被折叠?



