00001 package cedar.hepdata.webapp.pages;
00002
00003 import cedar.hepdata.model.*;
00004 import cedar.hepdata.xml.*;
00005 import cedar.hepdata.db.*;
00006
00007 import org.apache.tapestry5.annotations.*;
00008 import org.apache.tapestry5.ioc.annotations.*;
00009 import org.apache.tapestry5.services.*;
00010
00011 import org.hibernate.*;
00012 import org.hibernate.criterion.*;
00013 import java.util.*;
00014
00015
00016 public class FindPaperGeneral{
00017
00018 @Inject
00019 private RequestGlobals _reqGlobals;
00020
00021 @Inject
00022 private org.hibernate.Session _session;
00023
00024
00025 public String getQueryParam(String param){
00026 return _reqGlobals.getRequest().getParameter(param);
00027 }
00028
00029 public Long getCount(){
00030 return (Long) constructQuery("count").uniqueResult();
00031 }
00032
00033
00034 private Paper _paper;
00035 public Paper getPaper() { return _paper; }
00036 public void setPaper(Paper p) { _paper = p; }
00037
00038 public List <Paper> getPapers(){
00039 Query q = constructQuery();
00040
00041 q.setMaxResults(Integer.parseInt(getQueryParam("number")));
00042
00043 return q.list();
00044 }
00045
00046
00047 private Query constructQuery(){
00048 return this.constructQuery("blank");
00049 }
00050
00051 private Query constructQuery(String flag){
00052
00053 String theIrn = "";
00054 if (!getQueryParam("irn").equals("")){ theIrn = getQueryParam("irn"); }
00055
00056 Query q = null;
00057
00058
00059 StringBuffer b = new StringBuffer();
00060
00061
00062 if(!theIrn.equals("")){
00063 if (flag == "count"){
00064 if(Integer.parseInt(theIrn)> 8000){
00065 b.append("select count(distinct p) from Paper p where p._spiresId = :irn");
00066 }
00067 else{
00068 b.append("select count(distinct p) from Paper p where p._hepdataId = :irn");
00069 }
00070 }
00071 else{
00072 if(Integer.parseInt(theIrn)> 8000){
00073 b.append("select distinct p from Paper p where p._spiresId = :irn");
00074 }
00075 else{
00076 b.append("select distinct p from Paper p where p._hepdataId = :irn");
00077 }
00078 }
00079 q = _session.createQuery(b.toString());
00080 q.setString( "irn",theIrn);
00081 }
00082
00083 q.setMaxResults(Integer.parseInt(getQueryParam("number")));
00084
00085
00086 return q;
00087
00088 }
00089
00090
00091 }