TranUtil.java
资源名称:shihua.rar [点击查看]
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:2k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- package com.chinacannel.common;
- import net.sf.hibernate.*;
- import org.apache.commons.logging.LogFactory;
- import org.apache.commons.logging.Log;
- public class TranUtil {
- private net.sf.hibernate.Transaction tran;
- private net.sf.hibernate.Session session;
- private static Log log = LogFactory.getLog(TranUtil.class);
- public void beginTran() throws DAOException {
- try {
- session = HibernateUtil.currentSession();
- tran = session.beginTransaction();
- }
- catch (HibernateException ex) {
- log.error(ex.getMessage(), ex);
- throw new DAOException(ex.getMessage());
- }
- }
- public void rollback() throws DAOException {
- try {
- if(tran!=null)
- tran.rollback();
- }
- catch (HibernateException ex) {
- log.error(ex.getMessage(), ex);
- throw new DAOException(ex.getMessage());
- } finally {
- try {
- HibernateUtil.closeSession();
- }
- catch (HibernateException ex1) {
- log.error(ex1.getMessage(), ex1);
- throw new DAOException(ex1.getMessage());
- }
- }
- }
- public void commit() throws DAOException {
- try {
- if (tran != null)
- tran.commit();
- HibernateUtil.closeSession();
- }
- catch (HibernateException ex) {
- log.error(ex.getMessage(), ex);
- throw new DAOException(ex.getMessage());
- }
- }
- public net.sf.hibernate.Session getSession() throws DAOException {
- try {
- return HibernateUtil.currentSession();
- }
- catch (HibernateException ex) {
- log.error(ex.getMessage(), ex);
- throw new DAOException(ex.getMessage());
- }
- }
- public net.sf.hibernate.Transaction getTran() {
- return tran;
- }
- }