【Java开源代码栏目提醒】:以下是网学会员为您推荐的Java开源代码-BaseHbmDAO.java,希望本篇文章对您学习有所帮助。
// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov Date: 2004-12-7 21:14:13
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: BaseHbmDAO.java
package com.hr.dao;
import net.sf.hibernate.*;
// Referenced classes of package com.bandbrother.icp.dao:
// DAOException, ObjDAO
public class BaseHbmDAO
{
public BaseHbmDAO()
{
autoClose = true;
isTransaction = false;
}
public BaseHbmDAO(Session aSes)
{
autoClose = true;
isTransaction = false;
ses = aSes;
}
public void setSession(Session aSes)
{
ses = aSes;
}
public void remove(Object obj)
throws DAOException
{
Transaction trans = null;
try
{
trans = ses.beginTransaction();
ses.delete(obj);
trans.commit();
}
catch(Exception e)
{
try
{
if(trans != null)
trans.rollback();
}
catch(Exception ex)
{
e.printStackTrace();
}
throw new DAOException(e);
}
finally
{
if(autoClose)
closeSession();
}
}
public void remove(Class clazz, String id)
throws DAOException
{
Transaction trans = null;
try
{
trans = ses.beginTransaction();
Object obj = ses.load(clazz, id);
ses.delete(obj);
trans.commit();
}
catch(Exception e)
{
try
{
if(trans != null)
trans.rollback();
}
catch(Exception ex)
{
e.printStackTrace();
}
throw new DAOException(e);
}
finally
{
if(autoClose)
closeSession();
}
}
public void remove(Class clazz, Long id)
throws DAOException
{
Transaction trans = null;
try
{
trans = ses.beginTransaction();
Object obj = ses.load(clazz, id);
ses.delete(obj);
trans.commit();
}
catch(Exception e)
{
try
{
if(trans != null)
trans.rollback();
}
catch(Exception ex)
{
e.printStackTrace();
}
throw new DAOException(e);
}
finally
{
if(autoClose)
closeSession();
}
}
public void remove(String hql)
throws DAOException
{
Transaction trans = null;
try
{
trans = ses.beginTransaction();
ses.delete(hql);
trans.commit();
}
catch(Exception e)
{
try
{
if(trans != null)
trans.rollback();
}
catch(Exception ex)
{
e.printStackTrace();
}
throw new DAOException(e);
}
finally
{
if(autoClose)
closeSession();
}
}
public Object retrieve(Class clazz, String id)
throws DAOException
{
Object obj = null;
try
{
obj = ses.load(clazz, id);
}
catch(Exception e)
{
throw new DAOException(e);
}
finally
{
if(autoClose)
closeSession();
}
return obj;
}
public Object retrieve(Class clazz, Long id)
throws DAOException
{
Object obj = null;
try
{
obj = ses.load(clazz, id);
}
catch(Exception e)
{
e.printStackTrace();
throw new DAOException(e);
}
finally
{
if(autoClose)
closeSession();
}
return obj;
}
public void store(Object obj)
throws DAOException
{
Transaction trans = null;
try
{
trans = ses.beginTransaction();
ses.saveOrUpdate(obj);
trans.commit();
}
catch(Exception e)
{
try
{
if(trans != null)
trans.rollback();
}
catch(Exception ex)
{
e.printStackTrace();
}
throw new DAOException(e);
}
finally
{
if(autoClose)
closeSession();
}
}
public void save(Object obj)
throws DAOException
{
Transaction trans = null;
try
{
trans = ses.beginTransaction();
ses.save(obj);
trans.commit();
}
catch(Exception e)
{
try
{
if(trans != null)
trans.rollback();
}
catch(Exception ex)
{
e.printStackTrace();
}
throw new DAOException(e);
}
finally
{
if(autoClose)
closeSession();
}
}
public void update(Object obj)
throws DAOException
{
Transaction trans = null;
try
{
trans = ses.beginTransaction();
ses.update(obj);
ses.flush();
trans.commit();
}
catch(Exception e)
{
try
{
if(trans != null)
trans.rollback();
}
catch(Exception ex)
{
e.printStackTrace();
}
throw new DAOException(e);
}
finally
{
if(autoClose)
closeSession();
}
}
public void closeSession()
{
try
{
ses.close();
}
catch(HibernateException ex)
{
ex.printStackTrace();
}
}
public boolean isAutoClose()
{
return autoClose;
}
public void setAutoClose(boolean autoClose)
{
this.autoClose = autoClose;
}
protected Session ses;
private boolean autoClose;
private boolean isTransaction;
}
上一篇:
BaseGameEntity.java
下一篇:
扛起年轻化大旗,哈弗F系玩转行业新风潮