using hibernatedaosupport - not managing the session
using it like so
actionController - *code above* - will call a static method like this
Code:
public static void printValidity_DB(HttpServletRequest req, PrintWriter os, XmlWebApplicationContext webAppCtx){
GuiFieldGroupsDAO_Custom guiGrpDAO = (GuiFieldGroupsDAO_Custom) webAppCtx.getBean("GuiFieldGroupsDAO_Custom");
GuiFieldDisplayDAO_Custom guiDAO = (GuiFieldDisplayDAO_Custom) webAppCtx.getBean("GuiFieldDisplayDAO_Custom");
...
try{
....
ListIterator grpItr = guiGrpDAO.getGroupsInOrder().listIterator();
while(grpItr.hasNext()){
GuiFieldGroups guiGrp = (GuiFieldGroups)grpItr.next();
ListIterator guiItr = guiDAO.getEditDisplayedInOrderByGroup(guiGrp).listIterator();
while(guiItr.hasNext()){
GuiFieldDisplay guiDisp = (GuiFieldDisplay) guiItr.next();
//perform read only operations on the guiDisp object
guiDisp = null;
}
guiItr = null;
guiGrp = null;
}
grpItr = null;
}catch(XXXXX){
.....
}
guiDAO = null;
guiGrpDAO = null;
}
GuiFieldDisplayDAO
Code:
public class GuiFieldDisplayDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(GuiFieldDisplayDAO.class);
//property constants
...............BUNCH OF CONSTANTS
protected void initDao() {
//do nothing
}
public void save(GuiFieldDisplay transientInstance) {
log.debug("saving GuiFieldDisplay instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(GuiFieldDisplay persistentInstance) {
log.debug("deleting GuiFieldDisplay instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public GuiFieldDisplay findById( java.lang.Integer id) {
log.debug("getting GuiFieldDisplay instance with id: " + id);
try {
GuiFieldDisplay instance = (GuiFieldDisplay) getHibernateTemplate()
.get("com.lmco.tad.framework.GuiFieldDisplay", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(GuiFieldDisplay instance) {
log.debug("finding GuiFieldDisplay instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
log.debug("find by example successful, result size: " + results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding GuiFieldDisplay instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from GuiFieldDisplay as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public GuiFieldDisplay merge(GuiFieldDisplay detachedInstance) {
log.debug("merging GuiFieldDisplay instance");
try {
GuiFieldDisplay result = (GuiFieldDisplay) getHibernateTemplate()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(GuiFieldDisplay instance) {
log.debug("attaching dirty GuiFieldDisplay instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(GuiFieldDisplay instance) {
log.debug("attaching clean GuiFieldDisplay instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static GuiFieldDisplayDAO getFromApplicationContext(ApplicationContext ctx) {
return (GuiFieldDisplayDAO) ctx.getBean("GuiFieldDisplayDAO");
}
}
GuiFieldDisplayDAO_Custom
Code:
public class GuiFieldDisplayDAO_Custom extends GuiFieldDisplayDAO {
public List getEditDisplayedInOrderByGroup(GuiFieldGroups guiGroup) {
Criteria crit = null;
try {
crit = getSession().createCriteria(GuiFieldDisplay.class);
crit.add(Expression.eq("guiFieldGroups", guiGroup ));
crit.add(Expression.eq("XXXXX", 1 ));
crit.addOrder(Order.asc("XXXXX"));
return crit.list();
} catch (RuntimeException re) {
throw re;
}finally{
crit = null;
}
}
}
GuiFieldDisplay
Code:
public class GuiFieldDisplay implements java.io.Serializable {
// Fields
private Integer fieldId;
private GuiFieldGroups guiFieldGroups;
.....
//OTHER fields
......
// Constructors
/** default constructor */
public GuiFieldDisplay() {
}
// Property accessors
public Integer getFieldId() {
return this.fieldId;
}
public void setFieldId(Integer fieldId) {
this.fieldId = fieldId;
}
.....
//OTHER GETTERS AND SETTERS
......
}