📄 basedaohibernate.java
字号:
package com.set.appframe.persistence.hibernate;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.set.appframe.persistence.DAO;
import com.set.appframe.persistence.DAOException;
/**
* This class serves as the Base class for all other DAOs - namely to hold
* common methods that they might all use.
* </p>
*
*/
public class BaseDAOHibernate extends HibernateDaoSupport implements DAO {
private Log log = LogFactory.getLog(BaseDAOHibernate.class);
/**
* @see com.set.appframe.persistence.DAO#getObject(java.lang.Object)
*/
// public Object getObject(Object o) throws DAOException {
// Long id = null;
// // use reflection to get the id and fetch the object
// try {
// Method meth = o.getClass().getMethod("getId", new Class[0]);
// id = (Long) meth.invoke(o, new Object[0]);
// o = getHibernateTemplate().get(o.getClass(), id);
// } catch (Exception e) {
// throw new DAOException("exception loading '"
// + o.getClass().getName() + "' with id '" + id + "'");
// }
// return o;
// }
public Object getObject(String id, Class objClass) throws DAOException {
Object o;
try {
o = getHibernateTemplate().get(objClass, id);
} catch (Exception e) {
e.printStackTrace();
throw new DAOException("exception loading '" + objClass.getName()
+ "' with id '" + id + "'");
}
return o;
}
/**
* @see com.set.appframe.persistence.DAO#saveObject(java.lang.Object)
*/
public Object saveObject(Object o) {
try {
getHibernateTemplate().saveOrUpdate(o);
} catch (Exception e) {
e.printStackTrace();
}
return o;
}
/**
* @see com.set.appframe.persistence.DAO#removeObject(java.lang.Object)
*/
public void removeObject(String id, Class objClass) throws DAOException {
if (log.isDebugEnabled()) {
log.debug("loading object to delete....");
}
Object o;
o = getObject(id, objClass);
if (o != null) {
getHibernateTemplate().delete(o);
}
}
public List getObjectList(String listHQL) throws DAOException {
return this.getHibernateTemplate().find(listHQL);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -