package org.appfuse.persistence.hibernate;
import java.lang.reflect.Method;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.appfuse.model.Education;
import org.appfuse.model.Experience;
import org.appfuse.model.Membership;
import org.appfuse.model.Reference;
import org.appfuse.model.Resume;
import org.appfuse.persistence.DAOException;
import org.appfuse.persistence.ResumeDAO;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
public class ResumeDAOHibernate extends HibernateDaoSupport implements ResumeDAO {
private Log log = LogFactory.getLog(ResumeDAOHibernate.class);
public List getResumesByUserId(Long userId) throws DAOException {
return getHibernateTemplate().find("from Resume r where r.userId=? order by upper(r.name)",
userId);
}
public Resume getResume(Long id) throws DAOException {
return (Resume) getHibernateTemplate().get(Resume.class, id);
}
public Object saveObject(Object o) throws DAOException {
getHibernateTemplate().saveOrUpdateCopy(o);
return o;
}
public void removeObject(Object o) throws Exception {
if (log.isDebugEnabled()) {
log.debug("loading object to delete....");
}
Method meth = o.getClass().getMethod("getId", new Class[0]);
Long id = (Long) meth.invoke(o, new Object[0]);
o = getHibernateTemplate().get(o.getClass(), id);
if (o != null) {
getHibernateTemplate().delete(o);
}
}
public void removeResume(Object o) throws DAOException {
getHibernateTemplate().delete(o);
}
public Education getEducation(Long id) throws DAOException {
return (Education) getHibernateTemplate().get(Education.class, id);
}
public List getSchools(Long resumeId) throws DAOException {
return getHibernateTemplate().find("from Education e where e.resumeId=?",
resumeId);
}
public Experience getExperience(Long id) throws DAOException {
return (Experience) getHibernateTemplate().get(Experience.class, id);
}
public List getWorkHistory(Long resumeId) throws DAOException {
return getHibernateTemplate().find("from Experience e where e.resumeId=?",
resumeId);
}
public List getReferences(Long resumeId) throws DAOException {
return getHibernateTemplate().find("from Reference r where r.resumeId=?",
resumeId);
}
public Reference getReference(Long id) throws DAOException {
return (Reference) getHibernateTemplate().get(Reference.class, id);
}
public List getMemberships(Long resumeId) throws DAOException {
return getHibernateTemplate().find("from Membership m where m.resumeId=?",
resumeId);
}
public Membership getMembership(Long id) throws DAOException {
return (Membership) getHibernateTemplate().get(Membership.class, id);
}
}