Hibernate pagination

43

Click here to load reader

description

Pagination code

Transcript of Hibernate pagination

Page 1: Hibernate pagination

BaseDao.java

package com.action;

import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;

public class BaseDao { private static SessionFactory sf=new Configuration().configure().buildSessionFactory(); public static SessionFactory getSessionFactory(){ return sf; }

}

Start.java

package com.action;

public class Start { private String pgNo;

public String getPgNo() { return pgNo; }

public void setPgNo(String pgNo) { this.pgNo = pgNo; }

public String execute() { return "success"; }

}

AddressEntity.java

/* * System Name COLLEGE MANAGEMENT MODULE * Sub system Name : * Process Outline :Constant. * * Revision History * Date Name(Company Name) Description * ---------- ------------------------------ --------------------- * 2013/11/12 sheik(Infoview) New Creation */package com.pojo;

Page 2: Hibernate pagination

import java.io.Serializable;

/** * The Class AddressEntity. */@SuppressWarnings("serial")public final class AddressEntity implements Serializable{ /** The id. */ private int id; /** The pname. */ private String pname; /** The pmobno. */ private long pmobno; /** The address. */ private String address; /** * Gets the id. * * @return the id */ public int getId() { return id; } /** * Sets the id. * * @param id the new id */ public void setId(int id) { this.id = id; } /** * Gets the pname. * * @return the pname */ public String getPname() { return pname; } /** * Sets the pname. * * @param pname the new pname */ public void setPname(String pname) { this.pname = pname; }

Page 3: Hibernate pagination

/** * Gets the pmobno. * * @return the pmobno */ public long getPmobno() { return pmobno; } /** * Sets the pmobno. * * @param pmobno the new pmobno */ public void setPmobno(long pmobno) { this.pmobno = pmobno; } /** * Gets the address. * * @return the address */ public String getAddress() { return address; } /** * Sets the address. * * @param address the new address */ public void setAddress(String address) { this.address = address; }

}

AdminEntity.java

package com.pojo;

// TODO: Auto-generated Javadoc/** * The Class AdminEntity. */public class AdminEntity { /** The name. */ String name; /** The pass. */ String pass;

Page 4: Hibernate pagination

/** * Gets the name. * * @return the name */ public String getName() { return name; } /** * Sets the name. * * @param name the new name */ public void setName(String name) { this.name = name; } /** * Gets the pass. * * @return the pass */ public String getPass() { return pass; } /** * Sets the pass. * * @param pass the new pass */ public void setPass(String pass) { this.pass = pass; }

}

StudentEntity.java

/* * System Name COLLEGE MANAGEMENT MODULE * Sub system Name : * Process Outline :Constant. * * Revision History * Date Name(Company Name) Description * ---------- ------------------------------ --------------------- * 2013/11/12 Abhinaya R (Infoview) New Creation */package com.pojo;

import java.io.Serializable;

Page 5: Hibernate pagination

@SuppressWarnings("serial")public final class StudentEntity implements Serializable { private String name; private String pass; private String dept; private int year; private long mobno; private int id; private AddressEntity addr; public AddressEntity getAddr() { return addr; } public void setAddr(AddressEntity addr) { this.addr = addr; } public String getDept() { return dept; } public void setDept(String dept) { this.dept = dept; } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public long getMobno() { return mobno; } public void setMobno(long mobno) { this.mobno = mobno; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getPass() { return pass; } public void setPass(String pass) { this.pass = pass; } public String getName() { return name; } public void setName(String name) { this.name = name; } }

Page 6: Hibernate pagination

PaginationOperation.java

/* * System Name : Pagination template. * Sub system Name : Hibernate pagination custom tag. * Process Outline : Hibernate pagination custom tag. * * <Revision History> * Date Name(Company Name) Description * ---------- ------------------------------ --------------------- * 2013/11/13 Sheik fareed(Infoview) New Creation */package com.tag.control;

import java.io.IOException;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import javax.servlet.jsp.JspException;import javax.servlet.jsp.JspWriter;import javax.servlet.jsp.tagext.TagSupport;import org.apache.commons.lang.StringUtils;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.util.ValueStack;import com.tag.dao.PaginationDao;

/** * <p> * The Class PaginationOperation. This is main controller of the pagination * class It is used to get the all the input element of the pagination tag value * and fetch the information to the db and print the view page. * </p> * * @author Sheik fareed(Ivtl) * @version 1.0 */public class PaginationOperation extends TagSupport {

/** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L;

/** The s prev. */ private String sPrev = "«";

/** The s next. */ private String sNext = "»";

/** The s first. */ private String sFirst = "««";

/** The s last. */

Page 7: Hibernate pagination

private String sLast = "»»";

/** The pass arquments. */ private String passArquments = "";

/** The hql. */ private String hql;

/** The limit. */ private int limit;

/** The params. */ private String params;

/** The show number count. */ private String showNumberCount;

/** The action. */ private String action;

/** The width. */ private String width;

/** The previous. */ private String previous;

/** The next. */ private String next;

/** The first. */ private String first;

/** The last. */ private String last;

/** The header. */ private String header;

/** The theme. */ private String theme;

/** The argument. */ private String argument;

/** The other links. */ private String otherLinks;

/** The other arquments. */ private String otherArquments;

/** The session factory get. */ private String sessionFactoryGet;

/** The out. */ private JspWriter out;

Page 8: Hibernate pagination

/** * Gets the hql. * * @return the hql */ public String getHql() { return hql; }

/** * Sets the hql. * * @param hql * the new hql */ public void setHql(String hql) { this.hql = hql; }

/** * Gets the limit. * * @return the limit */ public int getLimit() { return limit; }

/** * Sets the limit. * * @param limit * the new limit */ public void setLimit(int limit) { this.limit = limit; }

/** * Gets the params. * * @return the params */ public String getParams() { return params; }

/** * Sets the params. * * @param params * the new params */ public void setParams(String params) { this.params = params; }

Page 9: Hibernate pagination

/** * Gets the show number count. * * @return the show number count */ public String getShowNumberCount() { return showNumberCount; }

/** * Sets the show number count. * * @param showNumberCount * the new show number count */ public void setShowNumberCount(String showNumberCount) { this.showNumberCount = showNumberCount; }

/** * Gets the action. * * @return the action */ public String getAction() { return action; }

/** * Sets the action. * * @param action * the new action */ public void setAction(String action) { this.action = action; }

/** * Gets the width. * * @return the width */ public String getWidth() { return width; }

/** * Sets the width. * * @param width * the new width */ public void setWidth(String width) { this.width = width;

Page 10: Hibernate pagination

}

/** * Gets the previous. * * @return the previous */ public String getPrevious() { return previous; }

/** * Sets the previous. * * @param previous * the new previous */ public void setPrevious(String previous) { this.previous = previous; }

/** * Gets the next. * * @return the next */ public String getNext() { return next; }

/** * Sets the next. * * @param next * the new next */ public void setNext(String next) { this.next = next; }

/** * Gets the first. * * @return the first */ public String getFirst() { return first; }

/** * Sets the first. * * @param first * the new first */ public void setFirst(String first) {

Page 11: Hibernate pagination

this.first = first; }

/** * Gets the last. * * @return the last */ public String getLast() { return last; }

/** * Sets the last. * * @param last * the new last */ public void setLast(String last) { this.last = last; }

/** * Gets the header. * * @return the header */ public String getHeader() { return header; }

/** * Sets the header. * * @param header * the new header */ public void setHeader(String header) { this.header = header; }

/** * Gets the theme. * * @return the theme */ public String getTheme() { return theme; }

/** * Sets the theme. * * @param theme * the new theme */

Page 12: Hibernate pagination

public void setTheme(String theme) { this.theme = theme; }

/** * Gets the argument. * * @return the argument */ public String getArgument() { return argument; }

/** * Sets the argument. * * @param argument * the new argument */ public void setArgument(String argument) { this.argument = argument; }

/** * Gets the other links. * * @return the other links */ public String getOtherLinks() { return otherLinks; }

/** * Sets the other links. * * @param otherLinks * the new other links */ public void setOtherLinks(String otherLinks) { this.otherLinks = otherLinks; }

/** * Gets the other arquments. * * @return the other arquments */ public String getOtherArquments() { return otherArquments; }

/** * Sets the other arquments. * * @param otherArquments * the new other arquments

Page 13: Hibernate pagination

*/ public void setOtherArquments(String otherArquments) { this.otherArquments = otherArquments; }

/** * Gets the session factory get. * * @return the session factory get */ public String getSessionFactoryGet() { return sessionFactoryGet; }

/** * Sets the session factory get. * * @param sessionFactoryGet * the new session factory get */ public void setSessionFactoryGet(String sessionFactoryGet) { this.sessionFactoryGet = sessionFactoryGet; }

/** * <p> * This is main method of the custom tag it is control the all the operation * of the custom tag it get the values from custom tag and fetch the * information from db and get the value. * </p> * * @return the int * @throws JspException * the jsp exception * @see javax.servlet.jsp.tagext.TagSupport#doStartTag() */ public int doStartTag() throws JspException { int result = SKIP_BODY; int count = 0; int size = 0; int pg = 1; String sWidth = "";

if (theme == null || theme.isEmpty()) { theme = "grey"; } try {

size = findSize(); labelSelection(); if (width != null) { sWidth = width; } PaginationDao dao = new PaginationDao(); out = pageContext.getOut(); ValueStack stack = ActionContext.getContext().getValueStack();

Page 14: Hibernate pagination

setPassArgument(stack); String pgNo = (String) stack.findValue("pgNo", String.class); if (pgNo != null && StringUtils.isNumeric(pgNo)) { pg = Integer.parseInt(pgNo); } count = dao.getCount(hql, argument,sessionFactoryGet); pageWrite(count, size, pg, sWidth, dao);

} catch (Exception e) { e.printStackTrace(); result = SKIP_BODY; } return result; }

/** * <p> * Sets the passing argument for all the arguments. * </p> * * * @param stack * the new pass argument */ private void setPassArgument(ValueStack stack) { if (argument != null && !argument.equals("")) { String[] arq = argument.split(","); passArquments = ""; for (int i = 0; i < arq.length; i++) { String[] param = arq[i].split(":"); passArquments = passArquments + "&" + param[2] + "=" + stack.findValue(param[2],Object.class); } } if (otherArquments != null) { String[] arq = otherArquments.split(","); for (int i = 0; i < arq.length; i++) { passArquments = passArquments + "&" + arq[i] + "=" + stack.findValue(arq[i],Object.class); } } }

/** * <p> * Page write this method is used to write the main content on this page. * </p> * * @param count * the count * @param size * the size * @param pg * the pg * @param sWidth * the s width

Page 15: Hibernate pagination

* @param dao * the dao * @throws Exception * the exception */ private void pageWrite(int count, int size, int pg, String sWidth, PaginationDao dao) throwsException { int pgCount; int intialPg; if (count != 0) { pgCount = (count + limit - 1) / limit; intialPg = pg - (size / 2); intialPg = findInitialPage(size, pgCount, intialPg); if (intialPg < 1) { intialPg = 1; } int pgStart = (pg - 1) * limit + 1; if (pgStart < 1) { pgStart = 1; } int pgEnd = pgStart + limit - 1; if (pgEnd > count) { pgEnd = count; } String themeClass = getThems().get(theme); numberCount(size, pg, pgCount, intialPg, sWidth, themeClass);

List li = dao.getTableValues(hql, pg, limit, argument, sessionFactoryGet); String[] parm = params.split(",");

listPrint(li, parm); out.write("<tr class='" + getTableTheme() + "show'><td colspan='3'><b>Showing resutls "+ pgStart + " to " + pgEnd + " of " + count + "</b></td></tr></table>"); } else { out.write("<table width='" + sWidth + "'><tr class='" + getTableTheme() + "show'><td><b>RESULTS NOT FOUND<b></td></tr></table>"); } }

/** * <p> * Number count is used to get the total result count and intial, last * pageno and decide the which are the numbers are shown in this page. * </p> * * @param size * the size * @param pg * the pg * @param pgCount * the pg count * @param intialPg * the intial pg * @param sWidth * the s width

Page 16: Hibernate pagination

* @param themeClass * the theme class * @throws IOException * Signals that an I/O exception has occurred. */ private void numberCount(int size, int pg, int pgCount, int intialPg, String sWidth, StringthemeClass) throws IOException { out.write("<table width='" + sWidth + "' cellspacing='0' cellpadding='0'class='pagination'><tr>" + "<td colspan='3'><center><table><tr><td>"); out.write("<ul class='" + themeClass + "' style='margin-bottom:10px;'>"); if (pg - 1 > 0) { out.write("<li class='previous'><a href='" + action + "?pgNo=1" + passArquments + "'>" +sFirst + "</a></li>"); out.write("<li class='previous'><a href='" + action + "?pgNo=" + (pg - 1) + passArquments +"'>" + sPrev + "</a></li>"); } else { out.write("<li class='off'><a href='#'>" + sFirst + "</a></li>"); out.write("<li class='off'><a href='#'>" + sPrev + "</a></li>"); } for (int i = intialPg; i < (intialPg + size) && i <= pgCount; i++) { if (i == pg) { out.write("<li><a class='current' href='#'>" + i + "</a></li>"); } else { out.write("<li><a href='" + action + "?pgNo=" + i + passArquments + "'>" + i + "</a></li>"); } } if (pg + 1 <= pgCount) { out.write("<li class='next'><a href='" + action + "?pgNo=" + (pg + 1) + passArquments + "'>"+ sNext + "</a></li>"); out.write("<li class='next'><a href='" + action + "?pgNo=" + pgCount + passArquments +"'>" + sLast + "</a></li>"); } else { out.write("<li class='off'><a href='#'>" + sNext + "</a></li>"); out.write("<li class='off'><a href='#'>" + sLast + "</a></li>"); } out.write("</ul></td></tr></table></center></td></tr><tr><td colspan='3'>"); }

/** * <p> * Label selection this class used to show the first, previous, next, last * labels of the current page. * </p> */ private void labelSelection() { if (previous != null) { sPrev = previous; } if (next != null) { sNext = next;

Page 17: Hibernate pagination

} if (last != null) { sLast = last; } if (first != null) { sFirst = first; } }

/** * <p> * List print this class is used to print the real list of the view page. * </p> * * @param li * the li * @param parm * the parm * @throws IOException * Signals that an I/O exception has occurred. * @throws NoSuchMethodException * the no such method exception * @throws IllegalAccessException * the illegal access exception * @throws InvocationTargetException * the invocation target exception */ private void listPrint(List<?> li, String[] parm) throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { int k = 1; Iterator<?> it = li.iterator(); String[] head = header.split(","); out.println("<table width='100%' cellspacing='0' cellpadding='5px' class=" +getTableTheme() + ">"); out.println("<thead ><tr>"); for (int j = 0; j < head.length; j++) { out.print("<th>" + head[j] + "</th>"); } out.println("</tr></thead>"); while (it.hasNext()) { if (k == 1) { out.println("<tr class='odd'>"); k = 2; } else { out.println("<tr class='even'>"); k = 1; } Object o = it.next(); Class<? extends Object> c = o.getClass();

for (int i = 0; i < parm.length; i++) { String par = parm[i].trim(); String[] objArg = par.split("\\."); if (objArg.length <= 1) { String name = "get" + par.replaceFirst(par.substring(0, 1), par.substring(0,1).toUpperCase());

Page 18: Hibernate pagination

Method f = c.getMethod(name); out.println("<td>" + f.invoke(o) + "</td>"); } else { objectIteration(o, c, par, objArg); } } if (otherLinks != null && !otherLinks.equals("")) { String[] links = otherLinks.split(","); out.println("<td>"); otherLinksWriting(o, c, links); out.println("</td>"); } out.println("</tr>"); }

out.println("</table></td></tr>");

}

/** * <p> * Other links writing. this class is used to show the other link like edit, * update etc this type of links shown. * </p> * * @param o * the o * @param c * the c * @param links * the links * @throws IOException * Signals that an I/O exception has occurred. * @throws NoSuchMethodException * the no such method exception * @throws IllegalAccessException * the illegal access exception * @throws InvocationTargetException * the invocation target exception */ private void otherLinksWriting(Object o, Class<? extends Object> c, String[] links) throwsIOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { Object obj = null; for (int l = 0; l < links.length; l++) { String[] linkParam = links[l].split(":"); out.println("<a class='pageLink' href='" + linkParam[1]); if (linkParam[2] != null && !linkParam[2].equals("")) { String[] actionArq = linkParam[2].split("&"); StringBuffer str = new StringBuffer(); for (int arq = 0; arq < actionArq.length; arq++) {

if (arq == 0) { str.append("?"); } else { str.append("&");

Page 19: Hibernate pagination

} String name = ""; String[] paramArq = actionArq[arq].split("="); String par = paramArq[1].trim(); String[] objArg = par.split("\\."); if (objArg.length <= 1) { name = "get" + par.replaceFirst(par.substring(0, 1), par.substring(0,1).toUpperCase()); Method f = c.getMethod(name); obj = f.invoke(o); } else { obj = objectIterationLink(o, c, par, objArg); }

str.append(paramArq[0]).append("=").append(obj); }

out.println(str.toString() + "'>"); } out.println(linkParam[0] + "</a>"); } }

/** * <p> * Object iteration tag is used iterate value object and get the method * using reflection concept. * </p> * * @param o * the o * @param c * the c * @param par * the par * @param objArg * the obj arg * @throws NoSuchMethodException * the no such method exception * @throws IOException * Signals that an I/O exception has occurred. * @throws IllegalAccessException * the illegal access exception * @throws InvocationTargetException * the invocation target exception */ private void objectIteration(Object o, Class<? extends Object> c, String par, String[] objArg) throws NoSuchMethodException, IOException, IllegalAccessException,InvocationTargetException { int i; Object oex = o; Class<? extends Object> cex = c; for (i = 0; i < objArg.length; i++) {

String name = "get" + objArg[i].replaceFirst(objArg[i].substring(0, 1), objArg[i].substring(0,

Page 20: Hibernate pagination

1).toUpperCase()); Method f = cex.getMethod(name); if (objArg.length == (i + 1)) {

out.println("<td>" + f.invoke(oex) + "</td>"); } else { Object o1 = f.invoke(o); Class<? extends Object> c1 = o1.getClass(); oex = o1; cex = c1;

} } }

/** * Object iteration link. * * @param o * the o * @param c * the c * @param par * the par * @param objArg * the obj arg * @return the object * @throws NoSuchMethodException * the no such method exception * @throws IOException * Signals that an I/O exception has occurred. * @throws IllegalAccessException * the illegal access exception * @throws InvocationTargetException * the invocation target exception */ private Object objectIterationLink(Object o, Class<? extends Object> c, String par, String[]objArg) throws NoSuchMethodException, IOException, IllegalAccessException,InvocationTargetException { int i; Object oex = o; Object result = new Object(); Class<? extends Object> cex = c; for (i = 0; i < objArg.length; i++) {

String name = "get" + objArg[i].replaceFirst(objArg[i].substring(0, 1), objArg[i].substring(0,1).toUpperCase()); Method f = cex.getMethod(name); if (objArg.length == (i + 1)) {

result = f.invoke(oex); } else { Object o1 = f.invoke(o); Class<? extends Object> c1 = o1.getClass();

Page 21: Hibernate pagination

oex = o1; cex = c1;

} } return result; }

/** * <p> * Find initial page.this method is used to find the initial page of the * viewing pagenation. * </p> * * @param size * the size * @param pgCount * the pg count * @param iPg * the i pg * @return the int */ private int findInitialPage(int size, int pgCount, int iPg) { int intialPg = iPg; if (intialPg <= 1) { intialPg = 1; } else if (intialPg + size > pgCount) { intialPg = pgCount - size + 1; } return intialPg; }

/** * <p> * Find size.this method get the size of the showing number. * </p> * * @return the int */ private int findSize() { int size; if (showNumberCount != null) { size = Integer.parseInt(showNumberCount); } else { size = 5; } return size; }

/** * <p> * Gets the thems. this method is used to get the whole pagination theme. * </p> * * @return the thems */

Page 22: Hibernate pagination

private Map<String, String> getThems() { Map<String, String> mp = new HashMap<String, String>(); mp.put("grey", "tsc_pagination tsc_paginationA tsc_paginationA01"); mp.put("yellow", "tsc_pagination tsc_paginationA tsc_paginationA02"); mp.put("orange", "tsc_pagination tsc_paginationA tsc_paginationA03"); mp.put("red", "tsc_pagination tsc_paginationA tsc_paginationA04"); mp.put("pale-green", "tsc_pagination tsc_paginationA tsc_paginationA05"); mp.put("green", "tsc_pagination tsc_paginationA tsc_paginationA06"); mp.put("pale-blue", "tsc_pagination tsc_paginationA tsc_paginationA07"); mp.put("blue", "tsc_pagination tsc_paginationA tsc_paginationA08"); mp.put("shadegreen", "tsc_pagination tsc_paginationA tsc_paginationA09"); mp.put("violet", "tsc_pagination tsc_paginationA tsc_paginationA10"); mp.put("brown", "tsc_pagination tsc_paginationA tsc_paginationA11"); mp.put("black", "tsc_pagination tsc_paginationA tsc_paginationA12");

mp.put("trans-yellow", "tsc_pagination tsc_paginationB tsc_paginationB01"); mp.put("trans-pale-blue", "tsc_pagination tsc_paginationB tsc_paginationB02"); mp.put("trans-blue", "tsc_pagination tsc_paginationB tsc_paginationB03"); mp.put("trans-violet", "tsc_pagination tsc_paginationB tsc_paginationB04"); mp.put("trans-orange", "tsc_pagination tsc_paginationB tsc_paginationB05"); mp.put("trans-red", "tsc_pagination tsc_paginationB tsc_paginationB06"); mp.put("trans-brown", "tsc_pagination tsc_paginationB tsc_paginationB07"); mp.put("trans-green", "tsc_pagination tsc_paginationB tsc_paginationB08"); mp.put("trans-pale-grey", "tsc_pagination tsc_paginationB tsc_paginationB9"); mp.put("trans-black", "tsc_pagination tsc_paginationB tsc_paginationB10");

mp.put("light-yellow", "tsc_pagination tsc_paginationC tsc_paginationC01"); mp.put("light-pale-blue", "tsc_pagination tsc_paginationC tsc_paginationC02"); mp.put("light-blue", "tsc_pagination tsc_paginationC tsc_paginationC03"); mp.put("light-violet", "tsc_pagination tsc_paginationC tsc_paginationC04"); mp.put("light-orange", "tsc_pagination tsc_paginationC tsc_paginationC05"); mp.put("light-red", "tsc_pagination tsc_paginationC tsc_paginationC06"); mp.put("light-brown", "tsc_pagination tsc_paginationC tsc_paginationC07"); mp.put("light-green", "tsc_pagination tsc_paginationC tsc_paginationC08"); mp.put("light-pale-grey", "tsc_pagination tsc_paginationC tsc_paginationC9"); mp.put("light-black", "tsc_pagination tsc_paginationC tsc_paginationC10");

return mp; }

/** * <p> * Gets the table theme. this theme is used to get the table theme. * </p> * * @return the table theme */ private String getTableTheme() { String className = ""; if (theme.contains("yellow")) { className = "yellow"; } else if (theme.contains("blue")) { className = "blue"; } else if (theme.contains("green")) { className = "green"; } else if (theme.contains("violet")) {

Page 23: Hibernate pagination

className = "violet"; } else if (theme.contains("orange")) { className = "orange"; } else if (theme.contains("brown")) { className = "brown"; } else if (theme.contains("black")) { className = "red"; } else if (theme.contains("red")) { className = "red"; } else { className = "grey"; } return className; }}

PaginationDao.java

/* * System Name : Pagination template. * Sub system Name : Hibernate pagination custom tag. * Process Outline : Hibernate pagination custom tag. * * <Revision History> * Date Name(Company Name) Description * ---------- ------------------------------ --------------------- * 2013/11/13 Sheik fareed(Infoview) New Creation */package com.tag.dao;

import java.lang.reflect.*;import java.util.List;import org.hibernate.Query;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.util.ValueStack;

/** * <p> * The Class PaginationDao. This class pagination dao is used to get the values * from the db and filter the particular parts. * </p> * * @author Sheik fareed(Infoview) * @version 1.0 */public class PaginationDao {

/** * <p> * Gets the table values from the db and filter the values for given * restrictions. * </p>

Page 24: Hibernate pagination

* * @param hql * the hql * @param pgNo * the pg no * @param limit * the limit * @param arquments * the arquments * @param sessionFactoryGet * @return the table values * @throws Exception * the exception */ public List<?> getTableValues(String hql, int pgNo, int limit, String arquments, StringsessionFactoryGet) throws Exception { List<?> li = null; Session session = getSessionFactory(sessionFactoryGet).openSession(); try { ValueStack stack = ActionContext.getContext().getValueStack(); session.beginTransaction(); Query query = session.createQuery(hql); if (arquments != null && !arquments.equals("")) { String[] arq = arquments.split(","); for (int i = 0; i < arq.length; i++) { String[] param = arq[i].split(":"); String value = (String) stack.findValue(param[2], String.class); String classType = param[1]; if (classType.equalsIgnoreCase("int")) { query.setParameter(param[0], Integer.parseInt(value)); } else if (classType.equalsIgnoreCase("long")) { query.setParameter(param[0], Long.parseLong(value)); } else if (classType.equalsIgnoreCase("float")) { query.setParameter(param[0], Float.parseFloat(value)); } else if (classType.equalsIgnoreCase("double")) { query.setParameter(param[0], Double.parseDouble(value)); } else { query.setParameter(param[0], value); } } } query.setFirstResult((pgNo - 1) * limit); query.setMaxResults(limit); li = query.list(); } catch (Exception e) { li = null; throw e; } finally { if (session != null) { session.close(); } } return li; }

/**

Page 25: Hibernate pagination

* <p> * Gets the count is count the total values of the given tables. * </p> * * @param hql * the hql * @param arquments * the arquments * @param sessionFactoryGet * @return the count * @throws Exception * the exception */ public int getCount(String hql, String arquments, String sessionFactoryGet) throws Exception { int count = 0; Session session = getSessionFactory(sessionFactoryGet).openSession(); try { ValueStack stack = ActionContext.getContext().getValueStack(); session.beginTransaction(); Query query = session.createQuery("select count(*) " + hql); if (arquments != null && !arquments.equals("")) { String[] arq = arquments.split(","); for (int i = 0; i < arq.length; i++) { String[] param = arq[i].split(":"); String value = (String) stack.findValue(param[2], String.class); String classType = param[1]; if (classType.equalsIgnoreCase("int")) { query.setParameter(param[0], Integer.parseInt(value)); } else if (classType.equalsIgnoreCase("long")) { query.setParameter(param[0], Long.parseLong(value)); } else if (classType.equalsIgnoreCase("float")) { query.setParameter(param[0], Float.parseFloat(value)); } else if (classType.equalsIgnoreCase("double")) { query.setParameter(param[0], Double.parseDouble(value)); } else { query.setParameter(param[0], value); } } } count = Integer.parseInt(String.valueOf(query.iterate().next())); } catch (Exception e) { count = 0; throw e; } finally { if (session != null) { session.close(); } } return count; } private SessionFactory getSessionFactory(String params){ String[] par = params.split(":"); SessionFactory sf = null; try { Class c = Class.forName(par[0]);

Page 26: Hibernate pagination

Method method = c.getMethod(par[1]); sf = (SessionFactory) method.invoke(null); } catch (Exception e) { e.printStackTrace(); } return sf; }}

@CHARSET "ISO-8859-1";.pagination li{list-style-type:none; float:left;}.tsc_breadcrumb-1,.tsc_breadcrumb-2 { font: 11px Arial, Helvetica, sans-serif; height:20px; line-height:20px;color:#9b9b9b; border:solid 1px #cacaca; width:100%; overflow:hidden; margin:0px;padding:0px; }.tsc_breadcrumb-1 li.current { color:#9b9b9b; border-right:1px solid #CCC; padding:0 14px; }.tsc_breadcrumb-1 li,.tsc_breadcrumb-2 li { list-style-type:none; float:left; }.tsc_breadcrumb-1 a { height:30px; display:block; border:1px solid #CCC; border-top:0; border-bottom:0; padding:0 14px; margin:0 0 0 -1px; text-decoration: none; color:#454545; }.tsc_breadcrumb-1 a:hover { color:#01C3FD; box-shadow:0 0 4px #c3c3c3; background-color:#eaeaea; }.tsc_breadcrumb-2 a:hover { color:#01C3FD; box-shadow:0 0 4px #FFF; background-color:#FFF;}.tsc_breadcrumb-2 li.current { color:#01C3FD; padding:0 15px; }.tsc_breadcrumb-2 { background:#2C3037; border:solid 1px #2D3238; height:31px; }.tsc_breadcrumb-2 a { height:33px; display:block; padding:0 15px; margin:0 0 0 -1px; text-decoration: none; color:#909EB2; }.tsc_breadcrumb-3 { height:2.3em; border:1px solid #dedede; list-style-type:none; padding:0;7 margin:0; }.tsc_breadcrumb-3 li { float:left; line-height:2.3em; color:#777; padding-left:.75em; } .tsc_breadcrumb-3 li a { background:url(../images/crumbs3.gif) no-repeat right center; display:block; padding:0 15px 0 0; } .tsc_breadcrumb-3 li a:link,.tsc_breadcrumb-3 li a:visited { color:#777; text-decoration:none; } a:link, a:visited, .tsc_breadcrumb-3 li a:hover,.tsc_breadcrumb-3 li a:focus {

Page 27: Hibernate pagination

color:#dd2c0d; }

/* ------------------------------------------- */ .tsc_breadcrumb-4{ list-style-type:none; padding:0; margin:0; background: #eee; border-width: 1px; border-style: solid; border-color: #f5f5f5 #e5e5e5 #ccc; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; -moz-box-shadow: 0 0 2px rgba(0,0,0,.2); -webkit-box-shadow: 0 0 2px rgba(0,0,0,.2); box-shadow: 0 0 2px rgba(0,0,0,.2); /* Clear floats */ overflow: hidden; width: 100%; } .tsc_breadcrumb-4 li{ float: left; } .tsc_breadcrumb-4 a{ padding: .7em 1em .7em 2em; float: left; text-decoration: none; color: #444; position: relative; text-shadow: 0 1px 0 rgba(255,255,255,.5); background-color: #ddd; background-image: -webkit-gradient(linear, left top, right bottom, from(#f5f5f5), to(#ddd)); background-image: -webkit-linear-gradient(left, #f5f5f5, #ddd); background-image: -moz-linear-gradient(left, #f5f5f5, #ddd); background-image: -ms-linear-gradient(left, #f5f5f5, #ddd); background-image: -o-linear-gradient(left, #f5f5f5, #ddd); background-image: linear-gradient(to right, #f5f5f5, #ddd); } .tsc_breadcrumb-4 li:first-child a{ padding-left: 1em; -moz-border-radius: 5px 0 0 5px; -webkit-border-radius: 5px 0 0 5px;

Page 28: Hibernate pagination

border-radius: 5px 0 0 5px; } .tsc_breadcrumb-4 a:hover{ background: #fff; } .tsc_breadcrumb-4 a::after, .tsc_breadcrumb-4 a::before{ content: ""; position: absolute; top: 50%; margin-top: -1.5em; border-top: 1.5em solid transparent; border-bottom: 1.5em solid transparent; border-left: 1em solid; right: -1em; } .tsc_breadcrumb-4 a::after{ z-index: 2; border-left-color: #ddd; } .tsc_breadcrumb-4 a::before{ border-left-color: #ccc; right: -1.1em; z-index: 1; } .tsc_breadcrumb-4 a:hover::after{ border-left-color: #fff; } .tsc_breadcrumb-4 .current, .tsc_breadcrumb-4 .current:hover{ font-weight: bold; background: none; } .tsc_breadcrumb-4 .current::after, .tsc_breadcrumb-4 .current::before{ content: normal; } /*-----------------------------------*/ .tsc_breadcrumb-5{ /* Clear floats */ overflow: hidden; width: 100%; list-style-type:none; padding:0; margin:0; }

Page 29: Hibernate pagination

.tsc_breadcrumb-5 ul{ list-style-type:none; padding:0; margin:0;} .tsc_breadcrumb-5 li{ float: left; margin: 0 .5em 0 1em; } .tsc_breadcrumb-5 a{ background: #ddd; padding: .7em 1em; float: left; text-decoration: none; color: #444; text-shadow: 0 1px 0 rgba(255,255,255,.5); position: relative; } .tsc_breadcrumb-5 a:hover{ background: #99db76; } .tsc_breadcrumb-5 a::before{ content: ""; position: absolute; top: 50%; margin-top: -1.5em; border-width: 1.5em 0 1.5em 1em; border-style: solid; border-color: #ddd #ddd #ddd transparent; left: -1em; } .tsc_breadcrumb-5 a:hover::before{ border-color: #99db76 #99db76 #99db76 transparent; } .tsc_breadcrumb-5 a::after{ content: ""; position: absolute; top: 50%; margin-top: -1.5em; border-top: 1.5em solid transparent; border-bottom: 1.5em solid transparent; border-left: 1em solid #ddd; right: -1em; } .tsc_breadcrumb-5 a:hover::after{ border-left-color: #99db76; } .tsc_breadcrumb-5 .current,

Page 30: Hibernate pagination

.tsc_breadcrumb-5 .current:hover{ font-weight: bold; background: none; } .tsc_breadcrumb-5 .current::after, .tsc_breadcrumb-5 .current::before{ content: normal; } /* ------------------------------------------- */ .tsc_breadcrumb-6{ /* Clear floats */ overflow: hidden; width: 100%; list-style-type:none; padding:0; margin:0; }

.tsc_breadcrumb-6 ul{ list-style-type:none; padding:0; margin:0;} .tsc_breadcrumb-6 ul{ list-style-type:none; padding:0; margin:0;} .tsc_breadcrumb-6 li{ float: left; margin: 0 2em 0 0; } .tsc_breadcrumb-6 a{ padding: .7em 1em .7em 2em; float: left; text-decoration: none; color: #444; background: #ddd; position: relative; z-index: 1; text-shadow: 0 1px 0 rgba(255,255,255,.5); -moz-border-radius: .4em 0 0 .4em; -webkit-border-radius: .4em 0 0 .4em; border-radius: .4em 0 0 .4em; } .tsc_breadcrumb-6 a:hover{ background: #abe0ef; }

Page 31: Hibernate pagination

.tsc_breadcrumb-6 a::after{ background: #ddd; content: ""; height: 2.5em; margin-top: -1.25em; position: absolute; right: -1em; top: 50%; width: 2.5em; z-index: -1; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -ms-transform: rotate(45deg); -o-transform: rotate(45deg); transform: rotate(45deg); -moz-border-radius: .4em; -webkit-border-radius: .4em; border-radius: .4em; } .tsc_breadcrumb-6 a:hover::after{ background: #abe0ef; } .tsc_breadcrumb-6 .current, .tsc_breadcrumb-6 .current:hover{ font-weight: bold; background: none; } .tsc_breadcrumb-6 .current::after{ content: normal; } /* ------------------------------------------- */ .tsc_breadcrumb-7{ /* Clear floats */ overflow: hidden; width: 100%; list-style-type:none; padding:0; margin:0; }

.tsc_breadcrumb-7 ul{ list-style-type:none; padding:0; margin:0;} .tsc_breadcrumb-7 li{ float: left; margin: 0 .5em 0 1em; }

Page 32: Hibernate pagination

.tsc_breadcrumb-7 a{ background: #ddd; padding: 0.1em 0.5em; float: left; text-decoration: none; color: #444; text-shadow: 0 1px 0 rgba(255,255,255,.5); position: relative; } .tsc_breadcrumb-7 a:hover{ background: #efc9ab; } .tsc_breadcrumb-7 a::before, .tsc_breadcrumb-7 a::after{ content:''; position:absolute; top: 0; bottom: 0; width: 1em; background: #ddd; -webkit-transform: skew(-10deg); -moz-transform: skew(-10deg); -ms-transform: skew(-10deg); -o-transform: skew(-10deg); transform: skew(-10deg); } .tsc_breadcrumb-7 a::before{ left: -.5em; -webkit-border-radius: 5px 0 0 5px; -moz-border-radius: 5px 0 0 5px; border-radius: 5px 0 0 5px; } .tsc_breadcrumb-7 a:hover::before{ background: #efc9ab; } .tsc_breadcrumb-7 a::after{ right: -.5em; -webkit-border-radius: 0 5px 5px 0; -moz-border-radius: 0 5px 5px 0; border-radius: 0 5px 5px 0; } .tsc_breadcrumb-7 a:hover::after{ background: #efc9ab; } .tsc_breadcrumb-7 .current, .tsc_breadcrumb-7 .current:hover{ font-weight: bold;

Page 33: Hibernate pagination

background: none; } .tsc_breadcrumb-7 .current::after, .tsc_breadcrumb-7 .current::before{ content: normal; }

pagination.css

ul.tsc_pagination { margin:4px 0; padding:0px; height:100%; overflow:hidden; font:12px'Tahoma'; list-style-type:none; }ul.tsc_pagination li { float:left; margin:0px; padding:0px; margin-left:5px; }ul.tsc_pagination li:first-child { margin-left:0px; }ul.tsc_pagination li a { color:black; display:block; text-decoration:none; padding:7px 9px 7px 9px;font-weight: bold;}ul.tsc_pagination li a img { border:none; }/*A */

ul.tsc_paginationA li a { color:#FFFFFF; border-radius:3px; -moz-border-radius:3px; -webkit-border-radius:3px; }/*01 */ul.tsc_paginationA01 li a { color:#474747; border:solid 1px #B6B6B6; padding:6px 9px 6px 9px;background:#E6E6E6; background:-moz-linear-gradient(top, #FFFFFF 1px, #F3F3F3 1px,#E6E6E6); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #FFFFFF), color-stop(0.02, #F3F3F3), color-stop(1, #E6E6E6)); }ul.tsc_paginationA01 li a:hover,ul.tsc_paginationA01 li a.current { background:#FFFFFF; }/*02 */ul.tsc_paginationA02 li a { color:#893A00; background:#FFCB00; background:-moz-linear-gradient(top, #FFD500, #FFCB00); background:-webkit-gradient(linear, 0 0, 0 100%,from(#FFD500), to(#FFCB00)); }ul.tsc_paginationA02 li a:hover,ul.tsc_paginationA02 li a.current { background:#FFF4BA; }/*03 */ul.tsc_paginationA03 li a { background:#FF7217; background:-moz-linear-gradient(top,#FF8E1F, #FF7217); background:-webkit-gradient(linear, 0 0, 0 100%, from(#FF8E1F),to(#FF7217)); }ul.tsc_paginationA03 li a:hover,ul.tsc_paginationA03 li a.current { color:#C34E00; background:#FFECDE; }/*04 */ul.tsc_paginationA04 li a { background:#D22020; background:-moz-linear-gradient(top,#DB2B2B, #D22020); background:-webkit-gradient(linear, 0 0, 0 100%, from(#DB2B2B),to(#D22020)); }ul.tsc_paginationA04 li a:hover,ul.tsc_paginationA04 li a.current { color:#9F0F0F; background:#FFE0E0; }/*05 */ul.tsc_paginationA05 li a { background:#699613; background:-moz-linear-gradient(top, #87AB19,#699613); background:-webkit-gradient(linear, 0 0, 0 100%, from(#87AB19), to(#699613)); }ul.tsc_paginationA05 li a:hover,ul.tsc_paginationA05 li a.current { color:#4F7119; background:#E7F2C7; }/*06 */ul.tsc_paginationA06 li a { background:#1D8A11; background:-moz-linear-gradient(top,#26A116, #1D8A11); background:-webkit-gradient(linear, 0 0, 0 100%, from(#26A116),to(#1D8A11)); }

Page 34: Hibernate pagination

ul.tsc_paginationA06 li a:hover,ul.tsc_paginationA06 li a.current { color:#176D0E; background:#DCF4C9; }/*07 */ul.tsc_paginationA07 li a { background:#45ABEC; background:-moz-linear-gradient(top,#5CBCF0, #45ABEC); background:-webkit-gradient(linear, 0 0, 0 100%, from(#5CBCF0),to(#45ABEC)); }ul.tsc_paginationA07 li a:hover,ul.tsc_paginationA07 li a.current { color:#358FDD; background:#DFF4FF; }/*08 */ul.tsc_paginationA08 li a { background:#3862C8; background:-moz-linear-gradient(top,#4A81D3, #3862C8); background:-webkit-gradient(linear, 0 0, 0 100%, from(#4A81D3),to(#3862C8)); }ul.tsc_paginationA08 li a:hover,ul.tsc_paginationA08 li a.current { color:#355DDD; background:#DDE8FE; }/*09 */ul.tsc_paginationA09 li a { background:#5A7075; background:-moz-linear-gradient(top,#788C90, #5A7075); background:-webkit-gradient(linear, 0 0, 0 100%, from(#788C90),to(#5A7075)); }ul.tsc_paginationA09 li a:hover,ul.tsc_paginationA09 li a.current { color:#355DDD; background:#DDE8FE; }/*10 */ul.tsc_paginationA10 li a { background:#684BA6; background:-moz-linear-gradient(top,#8663B8, #684BA6); background:-webkit-gradient(linear, 0 0, 0 100%, from(#8663B8),to(#684BA6)); }ul.tsc_paginationA10 li a:hover,ul.tsc_paginationA10 li a.current { color:#643EB3; background:#EAE4F4; }/*11 */ul.tsc_paginationA11 li a { background:#9A6654; background:-moz-linear-gradient(top,#AE846F, #9A6654); background:-webkit-gradient(linear, 0 0, 0 100%, from(#AE846F),to(#9A6654)); }ul.tsc_paginationA11 li a:hover,ul.tsc_paginationA11 li a.current { color:#78594A; background:#F0E7E3; }/*12 */ul.tsc_paginationA12 li a { background:#323232; background:-moz-linear-gradient(top, #434343,#323232); background:-webkit-gradient(linear, 0 0, 0 100%, from(#434343), to(#323232)); }ul.tsc_paginationA12 li a:hover,ul.tsc_paginationA12 li a.current { color:#2F2F2F; background:#EAEAEA; }

/* B */ul.tsc_paginationB li a { border:solid 1px; border-radius:3px; -moz-border-radius:3px; -webkit-border-radius:3px; }ul.tsc_paginationB li { padding-bottom:1px; }ul.tsc_paginationB li a:hover,ul.tsc_paginationB li a.current { color:#FFFFFF; box-shadow:0px 1px #EDEDED; -moz-box-shadow:0px 1px #EDEDED; -webkit-box-shadow:0px 1px #EDEDED; }/* 01 */ul.tsc_paginationB01 li a { color:#A74E0D; border-color:#F3D795; background:#FFFDF2; }ul.tsc_paginationB01 li a:hover,ul.tsc_paginationB01 li a.current { color:#893A00; text-shadow:0px 1px #FFEF42; border-color:#FFA200; background:#FFC800; background:-moz-linear-gradient(top, #FFFFFF 1px,#FFEA01 1px, #FFC800); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02,#FFFFFF), color-stop(0.02, #FFEA01), color-stop(1, #FFC800)); }/* 02 */ul.tsc_paginationB02 li a { color:#0A7EC5; border-color:#8DC5E6; background:#F8FCFF; }ul.tsc_paginationB02 li a:hover,ul.tsc_paginationB02 li a.current { text-shadow:0px 1px #388DBE; border-color:#3390CA;

Page 35: Hibernate pagination

background:#58B0E7; background:-moz-linear-gradient(top, #B4F6FF 1px, #63D0FE 1px,#58B0E7); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #B4F6FF), color-stop(0.02, #63D0FE), color-stop(1, #58B0E7)); }/* 03 */ul.tsc_paginationB03 li a { color:#4A76C6; border-color:#8AAEEF; background:#F7F9FE; }ul.tsc_paginationB03 li a:hover,ul.tsc_paginationB03 li a.current { text-shadow:0px 1px #4876C9; border-color:#3D6DC3;background:#5A8CE7; background:-moz-linear-gradient(top, #C2E0FF 1px, #84AFFE 1px,#5A8CE7); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #C2E0FF), color-stop(0.02, #84AFFE), color-stop(1, #5A8CE7)); }/* 04 */ul.tsc_paginationB04 li a { color:#8D62C8; border-color:#BAA2DA; background:#F9F7FC; }ul.tsc_paginationB04 li a:hover,ul.tsc_paginationB04 li a.current { text-shadow:0px 1px #7955AB; border-color:#6F4DA0;background:#9168C9; background:-moz-linear-gradient(top, #DFBEFA 1px, #B088E7 1px,#9168C9); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #DFBEFA), color-stop(0.02, #B088E7), color-stop(1, #9168C9)); }/* 05 */ul.tsc_paginationB05 li a { color:#EF6420; border-color:#FFBD85; background:#FFFAF7; }ul.tsc_paginationB05 li a:hover,ul.tsc_paginationB05 li a.current { text-shadow:0px 1px #CA470E; border-color:#D13F11;background:#E95B2B; background:-moz-linear-gradient(top, #FFBE01 1px, #FE7C02 1px,#E95B2B); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #FFBE01), color-stop(0.02, #FE7C02), color-stop(1, #E95B2B)); }/* 06 */ul.tsc_paginationB06 li a { color:#E92F2F; border-color:#FFA5A5; background:#FFF8F8; }ul.tsc_paginationB06 li a:hover,ul.tsc_paginationB06 li a.current { text-shadow:0px 1px #B72E2E; border-color:#AD2D2D;background:#E43838; background:-moz-linear-gradient(top, #FF9B9B 1px, #FE5555 1px,#E43838); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #FF9B9B), color-stop(0.02, #FE5555), color-stop(1, #E43838)); }/* 07 */ul.tsc_paginationB07 li a { color:#916C59; border-color:#D6BFB4; background:#FBF9F8; }ul.tsc_paginationB07 li a:hover,ul.tsc_paginationB07 li a.current { text-shadow:0px 1px #866454; border-color:#886756;background:#A37A66; background:-moz-linear-gradient(top, #E9C4B2 1px, #C59882 1px,#A37A66); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #E9C4B2), color-stop(0.02, #C59882), color-stop(1, #A37A66)); }/* 08 */ul.tsc_paginationB08 li a { color:#478223; border-color:#B2D397; background:#F7FAF4; }ul.tsc_paginationB08 li a:hover,ul.tsc_paginationB08 li a.current { text-shadow:0px 1px #4E802C; border-color:#478223;background:#599F2F; background:-moz-linear-gradient(top, #9FE355 1px, #79BF4A 1px,#599F2F); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #9FE355), color-stop(0.02, #79BF4A), color-stop(1, #599F2F)); }/* 09 */ul.tsc_paginationB09 li a { color:#707070; border-color:#CFCFCF; background:#FAFAFA; }ul.tsc_paginationB09 li a:hover,ul.tsc_paginationB09 li a.current { text-shadow:0px 1px #636363; border-color:#5D5D5D;background:#777777; background:-moz-linear-gradient(top, #C0C0C0 1px, #929292 1px,#777777); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #C0C0C0), color-stop(0.02, #929292), color-stop(1, #777777)); }/* 10 */ul.tsc_paginationB10 li a { color:#444444; border-color:#BEBEBE; background:#FAFAFA; }ul.tsc_paginationB10 li a:hover,ul.tsc_paginationB10 li a.current { text-shadow:0px 1px #3C3C3C; border-color:#202020;

Page 36: Hibernate pagination

background:#525252; background:-moz-linear-gradient(top, #9F9F9F 1px, #6C6C6C 1px,#525252); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #9F9F9F), color-stop(0.02, #6C6C6C), color-stop(1, #525252)); }

/* C */ul.tsc_paginationC li a { color:#707070; background:#FFFFFF; border-radius:3px; -moz-border-radius:3px; -webkit-border-radius:3px; border:solid 1px #DCDCDC; }ul.tsc_paginationC li { padding-bottom:1px; }ul.tsc_paginationC li a:hover,ul.tsc_paginationC li a.current { color:#FFFFFF; box-shadow:0px 1px #EDEDED; -moz-box-shadow:0px 1px #EDEDED; -webkit-box-shadow:0px 1px #EDEDED; }/* 01 */ul.tsc_paginationC01 li a:hover,ul.tsc_paginationC01 li a.current { color:#893A00; text-shadow:0px 1px #FFEF42; border-color:#FFA200; background:#FFC800; background:-moz-linear-gradient(top, #FFFFFF 1px,#FFEA01 1px, #FFC800); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02,#FFFFFF), color-stop(0.02, #FFEA01), color-stop(1, #FFC800)); }/* 02 */ul.tsc_paginationC02 li a:hover,ul.tsc_paginationC02 li a.current { text-shadow:0px 1px #388DBE; border-color:#3390CA;background:#58B0E7; background:-moz-linear-gradient(top, #B4F6FF 1px, #63D0FE 1px,#58B0E7); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #B4F6FF), color-stop(0.02, #63D0FE), color-stop(1, #58B0E7)); }/* 03 */ul.tsc_paginationC03 li a:hover,ul.tsc_paginationC03 li a.current { text-shadow:0px 1px #4876C9; border-color:#3D6DC3;background:#5A8CE7; background:-moz-linear-gradient(top, #C2E0FF 1px, #84AFFE 1px,#5A8CE7); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #C2E0FF), color-stop(0.02, #84AFFE), color-stop(1, #5A8CE7)); }/* 04 */ul.tsc_paginationC04 li a:hover,ul.tsc_paginationC04 li a.current { text-shadow:0px 1px #7955AB; border-color:#6F4DA0;background:#9168C9; background:-moz-linear-gradient(top, #DFBEFA 1px, #B088E7 1px,#9168C9); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #DFBEFA), color-stop(0.02, #B088E7), color-stop(1, #9168C9)); }/* 05 */ul.tsc_paginationC05 li a:hover,ul.tsc_paginationC05 li a.current { text-shadow:0px 1px #CA470E; border-color:#D13F11;background:#E95B2B; background:-moz-linear-gradient(top, #FFBE01 1px, #FE7C02 1px,#E95B2B); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #FFBE01), color-stop(0.02, #FE7C02), color-stop(1, #E95B2B)); }/* 06 */ul.tsc_paginationC06 li a:hover,ul.tsc_paginationC06 li a.current { text-shadow:0px 1px #B72E2E; border-color:#AD2D2D;background:#E43838; background:-moz-linear-gradient(top, #FF9B9B 1px, #FE5555 1px,#E43838); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #FF9B9B), color-stop(0.02, #FE5555), color-stop(1, #E43838)); }/* 07 */ul.tsc_paginationC07 li a:hover,ul.tsc_paginationC07 li a.current { text-shadow:0px 1px #866454; border-color:#886756;background:#A37A66; background:-moz-linear-gradient(top, #E9C4B2 1px, #C59882 1px,#A37A66); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #E9C4B2), color-stop(0.02, #C59882), color-stop(1, #A37A66)); }/* 08 */ul.tsc_paginationC08 li a:hover,ul.tsc_paginationC08 li a.current { text-shadow:0px 1px #4E802C; border-color:#478223;

Page 37: Hibernate pagination

background:#599F2F; background:-moz-linear-gradient(top, #9FE355 1px, #79BF4A 1px,#599F2F); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #9FE355), color-stop(0.02, #79BF4A), color-stop(1, #599F2F)); }/* 09 */ul.tsc_paginationC09 li a:hover,ul.tsc_paginationC09 li a.current { text-shadow:0px 1px #636363; border-color:#5D5D5D;background:#777777; background:-moz-linear-gradient(top, #C0C0C0 1px, #929292 1px,#777777); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #C0C0C0), color-stop(0.02, #929292), color-stop(1, #777777)); }/* 10 */ul.tsc_paginationC10 li a:hover,ul.tsc_paginationC10 li a.current { text-shadow:0px 1px #3C3C3C; border-color:#202020;background:#525252; background:-moz-linear-gradient(top, #9F9F9F 1px, #6C6C6C 1px,#525252); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #9F9F9F), color-stop(0.02, #6C6C6C), color-stop(1, #525252)); }.show{color:blue;margin-top:10px;}.grey{ border:1px solid #5D5D5D;}.grey thead{background:#777777; background:-moz-linear-gradient(top, #C0C0C0 1px, #929292 1px,#777777); background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #C0C0C0), color-stop(0.02, #929292), color-stop(1, #777777));}.grey .even{background:#f0f0f0;}

.grey .odd{background:#ffffff;}

.greyshow{ color:#5D5D5D;}

.blue{ border:1px solid #3d6dc3; }

.blue thead {background:#3862C8; background:-moz-linear-gradient(top, #4A81D3, #3862C8);background:-webkit-gradient(linear, 0 0, 0 100%, from(#4A81D3), to(#3862C8)); color:#ffffff;}

.blue .even{background:#cbdbf8;}

.blue .odd{background:#f7f9fe;}

.blueshow{ color:#3d6dc3;}

.green{ border:1px solid #478223; }

Page 38: Hibernate pagination

.green thead {background:#1D8A11; background:-moz-linear-gradient(top, #26A116, #1D8A11);background:-webkit-gradient(linear, 0 0, 0 100%, from(#26A116), to(#1D8A11)); color:#ffffff;}

.green .even{background:#cfe3bf;}

.green .odd{background:#f7faf4;}

.blueshow{ color:#355ddd;}

.red{ border:1px solid #c16161; }

.red thead {background:#D22020; background:-moz-linear-gradient(top, #DB2B2B, #D22020);background:-webkit-gradient(linear, 0 0, 0 100%, from(#DB2B2B), to(#D22020)); color:#ffffff;}

.red .even{background:#ffe0e0;}

.red .odd{background:#fff8f8;}

.redshow{ color:#9f0f0f;}

.violet{ border:1px solid #6f4da0; }

.violet thead {background:#684BA6; background:-moz-linear-gradient(top, #8663B8, #684BA6);background:-webkit-gradient(linear, 0 0, 0 100%, from(#8663B8), to(#684BA6)); color:#ffffff;}

.violet .even{background:#eae4f4;}

.violet .odd{background:#f9f7fc;}.violetshow{ color:#6f4da0; }

.orange{ border:1px solid #d13f11; }

.orange thead {background:#FF7217; background:-moz-linear-gradient(top, #FF8E1F, #FF7217);background:-webkit-gradient(linear, 0 0, 0 100%, from(#FF8E1F), to(#FF7217)); color:#ffffff;}

.orange .even{background:#ffecde;

Page 39: Hibernate pagination

}

.orange .odd{background:#fffaf7;}

.orangeshow{ color:#d13f11; }

start.jsp

<META HTTP-EQUIV="Refresh" CONTENT="0;URL=start.action">

view.jsp

<%@ taglib prefix="s" uri="/struts-tags"%><%@taglib prefix="test" uri="/WEB-INF/pagination.tld"%><html><head><link rel="stylesheet" type="text/css" href="pagenationcss.css"></head><body><test:pagination hql="From StudentEntity" params="name,dept,addr.pname,addr.pmobno" header="Name,Dept,ParentName,MobileNumber" limit="3" showNumberCount="5" action="start" theme="orange" first="First" last="Last" previous="Prev" next="Next"sessionFactoryGet="com.action.BaseDao:getSessionFactory" /></body></html>

Address.hbm.xml

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping> <class name="com.pojo.AddressEntity" table="addressdetails34"> <id name="id" column="aid" type="int" > <generator class="native"/> </id> <property name="pname" column="parentname" type="string"></property> <property name="pmobno" column="parentmobno" type="long"/> <property name="address" column="address" type="string"/> </class></hibernate-mapping>

Page 40: Hibernate pagination

Admin.hbm.xml

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping> <class name="com.pojo.AdminEntity" table="admindetails34"> <id name="name" column="name" type="string" > <generator class="assigned"/> </id> <property name="pass" column="pass" type="string"></property> </class></hibernate-mapping>

Student.hbm.xml

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping> <class name="com.pojo.StudentEntity" table="studentdetails34"> <id name="id" column="sid" type="java.lang.Integer" > <generator class="assigned"/> </id> <property name="name" column="studentname" type="string"/> <property name="pass" column="password" type="string"/> <property name="dept" column="department" type="string"/> <property name="year" column="year" type="int"/> <property name="mobno" column="mobno" type="long"></property> <many-to-one name="addr" class="com.pojo.AddressEntity" column="address" not-null="true"cascade="all" unique="true" /> </class></hibernate-mapping>

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration> <session-factory>

Page 41: Hibernate pagination

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://192.168.0.60:3306/training?characterEncoding=UTF-8</property> <property name="hibernate.connection.username">trauser</property> <property name="connection.password">User@db78</property> <property name="hbm2ddl.auto">update</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property> <mapping resource="Register.hbm.xml"/> <mapping resource="Address.hbm.xml"/> <mapping resource="Admin.hbm.xml"/> <mapping resource="Student.hbm.xml"/> </session-factory></hibernate-configuration>

struts.xml

<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd">

<struts> <constant name="struts.devMode" value="true" /> <constant name="struts.multipart.maxSize" value="1000000000" /> <!--<constant name="struts.custom.i18n.resources" value="global" /> --><package name="reg" extends="struts-default"> <result-types> <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" /> </result-types>

<action name="start" class="com.action.Start"> <result name="success">view.jsp</result> </action> <!--<action name="login" class="com.user.action.LoginAction"> <result name="admin" type="tiles">adminHome</result> </action> <action name="upload" class="com.user.action.LoginAction"> <interceptor-ref name="basicStack"/> <interceptor-ref name="fileUpload"> </interceptor-ref> <result name="success">/success.jsp</result> <result name="error">/error.jsp</result> </action> --></package>

</struts>

web.xml

Page 42: Hibernate pagination

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Hipernate Pagination</display-name> <listener> <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class> </listener> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

<welcome-file-list> <welcome-file>/start.jsp</welcome-file> </welcome-file-list></web-app>

pagination.tld

<?xml version="1.0" encoding="UTF-8"?><taglib><tlibversion>1.0</tlibversion><jspversion>1.1</jspversion><shortname>pagination</shortname><info>Hibernate pagination Custom tag</info><uri></uri><tag> <name>pagination</name> <tagclass>com.tag.control.PaginationOperation</tagclass> <info>Pagination function.</info> <attribute> <name>hql</name> <required>true</required> </attribute> <attribute> <name>limit</name> <required>true</required> </attribute> <attribute> <name>params</name> <required>true</required> </attribute> <attribute> <name>showNumberCount</name> <required>false</required> </attribute> <attribute>

Page 43: Hibernate pagination

<name>action</name> <required>true</required> </attribute> <attribute> <name>width</name> <required>false</required> </attribute> <attribute> <name>first</name> <required>false</required> </attribute> <attribute> <name>last</name> <required>false</required> </attribute> <attribute> <name>previous</name> <required>false</required> </attribute> <attribute> <name>next</name> <required>false</required> </attribute> <attribute> <name>header</name> <required>false</required> </attribute> <attribute> <name>theme</name> <required>false</required> </attribute> <attribute> <name>argument</name> <required>false</required> </attribute> <attribute> <name>otherLinks</name> <required>false</required> </attribute> <attribute> <name>otherArquments</name> <required>false</required> </attribute> <attribute> <name>sessionFactoryGet</name> <required>true</required> </attribute></tag></taglib>