SearchPeopleAction.java
/**/
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package action;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.struts.ActionSupport;
import service.StudentManagerImpl;
import util.PageSupport;
import domain.People;
/** */ /**
* MyEclipse Struts
* Creation date: 01-17-2007
*
* XDoclet definition:
* @struts.action validate="true"
*/
public class SearchPeopleAction extends ActionSupport ... {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) ...{
People people=(People)form;
String page=request.getParameter("page");
int firstRow=0;
int lastRow=0;
String name=people.getName();
String location=people.getLocation();
String hql="from People where name="+name+" and location="+location;
StudentManagerImpl manager=(StudentManagerImpl)getWebApplicationContext().getBean("studentManager");
PageSupport sPage=new PageSupport(page);
sPage.setPagetotal(manager.searchPeople(hql).size());
firstRow=sPage.calcFirstPage();
lastRow=sPage.calcLastPage();
List studentList=manager.searchPeople(firstRow-1, lastRow, hql);
request.setAttribute("studentList", studentList);
request.setAttribute("currentPage", sPage.getThispage());
return mapping.findForward("success");
}
}
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package action;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.struts.ActionSupport;
import service.StudentManagerImpl;
import util.PageSupport;
import domain.People;
/** */ /**
* MyEclipse Struts
* Creation date: 01-17-2007
*
* XDoclet definition:
* @struts.action validate="true"
*/
public class SearchPeopleAction extends ActionSupport ... {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) ...{
People people=(People)form;
String page=request.getParameter("page");
int firstRow=0;
int lastRow=0;
String name=people.getName();
String location=people.getLocation();
String hql="from People where name="+name+" and location="+location;
StudentManagerImpl manager=(StudentManagerImpl)getWebApplicationContext().getBean("studentManager");
PageSupport sPage=new PageSupport(page);
sPage.setPagetotal(manager.searchPeople(hql).size());
firstRow=sPage.calcFirstPage();
lastRow=sPage.calcLastPage();
List studentList=manager.searchPeople(firstRow-1, lastRow, hql);
request.setAttribute("studentList", studentList);
request.setAttribute("currentPage", sPage.getThispage());
return mapping.findForward("success");
}
}
IDAO.java
package
dao;
import java.util.List;
import org.hibernate.criterion.DetachedCriteria;
public interface IDAO ... {
public void save(Object obj);
public List list(final int firstRow,final int lastRow,final String hql);
public List list();
public void delete(Object obj);
public Object getPeople(Integer id);
public void editPeople(Object obj);
public List searchPeople(final int firstRow,final int lastRow,final String hql);
public List searchPeople(final String sql);
}
import java.util.List;
import org.hibernate.criterion.DetachedCriteria;
public interface IDAO ... {
public void save(Object obj);
public List list(final int firstRow,final int lastRow,final String hql);
public List list();
public void delete(Object obj);
public Object getPeople(Integer id);
public void editPeople(Object obj);
public List searchPeople(final int firstRow,final int lastRow,final String hql);
public List searchPeople(final String sql);
}
StudentDAOImpl.java
package
dao;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import domain.People;
public class StudentDAOImpl extends HibernateDaoSupport implements IDAO ... {
public List searchPeople(final int firstRow,final int lastRow,final String hql)...{
return getHibernateTemplate().executeFind(new HibernateCallback() ...{
public Object doInHibernate(Session s) throws HibernateException, SQLException ...{
Query query = s.createQuery(hql);
query.setFirstResult(firstRow);
query.setMaxResults(lastRow);
List list = query.list();
return list;
}
});
}
public List searchPeople(final String hql)...{
return getHibernateTemplate().executeFind(new HibernateCallback() ...{
public Object doInHibernate(Session s) throws HibernateException, SQLException ...{
Query query = s.createQuery(hql);
List list = query.list();
return list;
}
});
}
public void save(Object obj) ...{
if(obj instanceof People)...{
People people=(People)obj;
try...{
getHibernateTemplate().save(people);
}catch(Exception e)...{
e.printStackTrace();
}
}
}
public List list()...{
return getHibernateTemplate().find("from People");
}
public List list(final int firstRow,final int lastRow,final String hql)...{
return getHibernateTemplate().executeFind(new HibernateCallback() ...{
public Object doInHibernate(Session s) throws HibernateException, SQLException ...{
Query query = s.createQuery(hql);
query.setFirstResult(firstRow);
query.setMaxResults(lastRow);
List list = query.list();
return list;
}
});
}
public void editPeople(Object obj)...{
if(obj instanceof People)...{
People people=(People)obj;
try...{
getHibernateTemplate().saveOrUpdate(people);
}catch(Exception e)...{
e.printStackTrace();
}
}
}
public Object getPeople(Integer id)...{
return getHibernateTemplate().get(People.class, id);
}
public void delete(Object obj)...{
if(obj instanceof People)...{
getHibernateTemplate().delete((People)obj);
}
}
}
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import domain.People;
public class StudentDAOImpl extends HibernateDaoSupport implements IDAO ... {
public List searchPeople(final int firstRow,final int lastRow,final String hql)...{
return getHibernateTemplate().executeFind(new HibernateCallback() ...{
public Object doInHibernate(Session s) throws HibernateException, SQLException ...{
Query query = s.createQuery(hql);
query.setFirstResult(firstRow);
query.setMaxResults(lastRow);
List list = query.list();
return list;
}
});
}
public List searchPeople(final String hql)...{
return getHibernateTemplate().executeFind(new HibernateCallback() ...{
public Object doInHibernate(Session s) throws HibernateException, SQLException ...{
Query query = s.createQuery(hql);
List list = query.list();
return list;
}
});
}
public void save(Object obj) ...{
if(obj instanceof People)...{
People people=(People)obj;
try...{
getHibernateTemplate().save(people);
}catch(Exception e)...{
e.printStackTrace();
}
}
}
public List list()...{
return getHibernateTemplate().find("from People");
}
public List list(final int firstRow,final int lastRow,final String hql)...{
return getHibernateTemplate().executeFind(new HibernateCallback() ...{
public Object doInHibernate(Session s) throws HibernateException, SQLException ...{
Query query = s.createQuery(hql);
query.setFirstResult(firstRow);
query.setMaxResults(lastRow);
List list = query.list();
return list;
}
});
}
public void editPeople(Object obj)...{
if(obj instanceof People)...{
People people=(People)obj;
try...{
getHibernateTemplate().saveOrUpdate(people);
}catch(Exception e)...{
e.printStackTrace();
}
}
}
public Object getPeople(Integer id)...{
return getHibernateTemplate().get(People.class, id);
}
public void delete(Object obj)...{
if(obj instanceof People)...{
getHibernateTemplate().delete((People)obj);
}
}
}
AbstractPeople.java
package
domain;
import org.apache.struts.action.ActionForm;
public abstract class AbstractPeople extends ActionForm implements java.io.Serializable ... {
// Fields
private Integer id;
private String name;
private String location;
// Constructors
/** *//** default constructor */
public AbstractPeople() ...{
}
/** *//** full constructor */
public AbstractPeople(String name, String location) ...{
this.name = name;
this.location = location;
}
// Property accessors
public Integer getId() ...{
return this.id;
}
public void setId(Integer id) ...{
this.id = id;
}
public String getName() ...{
return this.name;
}
public void setName(String name) ...{
this.name = name;
}
public String getLocation() ...{
return this.location;
}
public void setLocation(String location) ...{
this.location = location;
}
}
import org.apache.struts.action.ActionForm;
public abstract class AbstractPeople extends ActionForm implements java.io.Serializable ... {
// Fields
private Integer id;
private String name;
private String location;
// Constructors
/** *//** default constructor */
public AbstractPeople() ...{
}
/** *//** full constructor */
public AbstractPeople(String name, String location) ...{
this.name = name;
this.location = location;
}
// Property accessors
public Integer getId() ...{
return this.id;
}
public void setId(Integer id) ...{
this.id = id;
}
public String getName() ...{
return this.name;
}
public void setName(String name) ...{
this.name = name;
}
public String getLocation() ...{
return this.location;
}
public void setLocation(String location) ...{
this.location = location;
}
}