[HepData-svn] r1520 - trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/query

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Tue Mar 13 16:48:55 GMT 2012


Author: whalley
Date: Tue Mar 13 16:48:54 2012
New Revision: 1520

Log:
constructs re query for dsreaction search

Modified:
   trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/query/ConstructQueryPaper.java

Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/query/ConstructQueryPaper.java
==============================================================================
--- trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/query/ConstructQueryPaper.java	Tue Mar 13 16:33:03 2012	(r1519)
+++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/query/ConstructQueryPaper.java	Tue Mar 13 16:48:54 2012	(r1520)
@@ -74,6 +74,7 @@
        String reference = null;
        String date = null;
        String datetype = "=";
+       String sqrtstype = "=";
 //       System.out.println(queryString);
        for (int i=0; i<words.length; i++){
            String parts[] = words[i].split("\\s+");
@@ -91,7 +92,18 @@
 		   if(parts[0].equals("RED")) {redid = parts[1];}
  	 	   if(parts[0].equals("EXP") || parts[0].equals("DE") || parts[0].equals("CN")) {experiment = parts[1];}
  	 	   if(parts[0].equals("AUTH") || parts[0].equals("A") || parts[0].equals("AUTHOR") ) {author = parts[1];}
- 	 	   if(parts[0].equals("SQRTS") || parts[0].equals("ECM")) {sqrts = parts[1];}
+ 	 	   if(parts[0].equals("SQRTS") || parts[0].equals("ECM")) {
+		       int next = 1;
+		       if(parts[1].equals("<") || 
+		  	      parts[1].equals(">") ){
+			       sqrtstype=parts[1];
+			       next=2;
+		       }
+		       sqrts = parts[next];
+		       for (int j=next+1; j<parts.length; j++){
+		           sqrts = sqrts.concat(" " + parts[j]);
+		       }
+           }
  	 	   if(parts[0].equals("REF") || parts[0].equals("R") ) {
 		       reference = parts[1];
 		       for (int j=2; j<parts.length; j++){
@@ -101,7 +113,7 @@
  	 	   if(parts[0].equals("DATE") || parts[0].equals("YEAR") || parts[0].equals("D") ) {
 		       int next = 1;
 		       if(parts[1].equals("<") || 
-			  parts[1].equals(">") ){
+		  	  parts[1].equals(">") ){
 			  datetype=parts[1];
 			  next=2;
 		       }
@@ -114,12 +126,12 @@
            if(parts[0].equals("FSP")){
                if(parts[1].equals("HADRONS")){parts[1] = "2HADRON";}
                if(parts[1].equals("JETS")){parts[1] = "2JET";}
-		       reaction = "--> " + parts[1];
+		       reaction = "%-->%" + parts[1] + "%";
 		   }
            if(parts[0].equals("FS")){
                if(parts[1].equals("HADRONS")){parts[1] = "2HADRON";}
                if(parts[1].equals("JETS")){parts[1] = "2JET";}
-		       reaction = "--> " + parts[1];
+		       reaction = "%--> " + parts[1];
 		       for (int j=2; j<parts.length; j++){
                        if(parts[j].equals("HADRONS")){parts[j] = "2HADRON";}
                        if(parts[j].equals("JETS")){parts[j] = "2JET";}
@@ -127,7 +139,7 @@
 		       }
 		   }
            if(parts[0].equals("BEAM") || parts[0].equals("TARG")){
-		       reaction = parts[1];
+		       reaction = "%"+parts[1]+"%-->%";
 		   }
            if(parts[0].equals("DSREACTION")){
                dsreaction = parts[1];
@@ -148,7 +160,7 @@
        else if(experiment != null) {
            if(date  != null){
  	       if(reaction != null || observable != null || sqrts != null){
-                  return Physics(experiment,date,datetype,reaction,observable,sqrts,flag,_session);
+                  return Physics(experiment,date,datetype,reaction,observable,sqrts,sqrtstype,flag,_session);
 	       }
 	       else{
 //                  System.out.println("calling ExperimentDate" + experiment + date);
@@ -157,7 +169,7 @@
 	   }
 	   else{
 	       if(reaction != null || observable != null || sqrts != null){
-                  return Physics(experiment,date,datetype,reaction,observable,sqrts,flag,_session); 
+                  return Physics(experiment,date,datetype,reaction,observable,sqrts,sqrtstype,flag,_session); 
 	       }
 	       else{
                    return Experiment(experiment,flag,_session);
@@ -167,7 +179,7 @@
        else if(date != null) { 
             if(experiment !=null) {   
  	       if(reaction != null || observable != null || sqrts != null){
-                  return Physics(experiment,date,datetype,reaction,observable,sqrts,flag,_session);
+                  return Physics(experiment,date,datetype,reaction,observable,sqrts,sqrtstype,flag,_session);
 	       }
 	       else{
 //                  System.out.println("calling ExperimentDate" + experiment + date);
@@ -176,7 +188,7 @@
 	   }
 	   else{
 	       if(reaction != null || observable != null || sqrts != null){
-                  return Physics(experiment,date,datetype,reaction,observable,sqrts,flag,_session); 
+                  return Physics(experiment,date,datetype,reaction,observable,sqrts,sqrtstype,flag,_session); 
 	       }
 	       else{
                    return Date(date,datetype,flag,_session);
@@ -184,7 +196,7 @@
 	   }
        }
        else if(reference != null) { return Reference(reference,flag,_session);}
-       else{ return Physics(experiment,date,datetype,reaction,observable,sqrts,flag,_session); }
+       else{ return Physics(experiment,date,datetype,reaction,observable,sqrts,sqrtstype,flag,_session); }
     }
 ////// Special  constructors///
     public static Query EventShapes(String flag,org.hibernate.Session _session){
@@ -408,9 +420,60 @@
        b.append(",DsReactions dr");
        if(dsobservable != null) {b.append(",DsObservables do");}
 
-       b.append(" where dr.DsReactions like '");
+       b.append(" where (dr.DsReactions like '");
        b.append(dsreaction);
        b.append("'");
+       
+       if(!dsreaction.endsWith("%")){
+           List<String> fsp = new ArrayList();
+           String is = getInitialState(dsreaction);
+           String fs = getFinalState(dsreaction);
+           java.util.StringTokenizer stfs = new java.util.StringTokenizer(fs);
+           while(stfs.hasMoreTokens()){ fsp.add(stfs.nextToken()); }
+           for (int n1=0; n1<fsp.size(); n1++){
+               if(fsp.size()>1){
+                   for(int n2=0; n2<fsp.size(); n2++){
+                       if(fsp.size()==2
+                                            &&n2!=n1){
+                            if(n1!=0&&n2!=1){                           
+                     b.append(" or dr.DsReactions like '"+is+" --> "+fsp.get(n1)+" "+fsp.get(n2)+"'");
+                            }                
+                       } else{
+                           for(int n3=0; n3<fsp.size(); n3++){
+                               if(fsp.size()==3
+                                                   &&n3!=n2&&n3!=n1
+                                                   &&n2!=n1){
+                 b.append(" or dr.DsReactions like '"+is+" --> "+fsp.get(n1)+" "+fsp.get(n2)+" "+fsp.get(n3)+"'");                
+                               }
+                               else{
+                                   for(int n4=0; n4<fsp.size(); n4++){
+                                       if(fsp.size()==4  
+                                                            &&n4!=n3&&n4!=n2&&n4!=n1
+                                                            &&n3!=n2&&n3!=n1
+                                                            &&n2!=n1){
+                b.append(" or dr.DsReactions like '"+is+" --> "+fsp.get(n1)+" "+fsp.get(n2)+" "+fsp.get(n3)+" "+fsp.get(n4)+"'");                
+                                       }
+                                       else{
+                                           for(int n5=0; n5<fsp.size(); n5++){
+                                               if(fsp.size()==5  
+                                                                &&n5!=n4&&n5!=n3&&n5!=n2&&n5!=n1
+                                                                &&n4!=n3&&n4!=n2&&n4!=n1
+                                                                &&n3!=n2&&n3!=n1
+                                                                &&n2!=n1){
+                b.append(" or dr.DsReactions like '"+is+" --> "+fsp.get(n1)+" "+fsp.get(n2)+" "+fsp.get(n3)+" "+fsp.get(n4)+" "+fsp.get(n5)+"'");                
+                                               }
+                                           }
+                                       }
+                                   }
+                               }
+                           }
+                       }
+                   }
+               }
+           }
+       }
+       
+       b.append(")");
        if(dsobservable != null) {
            b.append(" and do.DsObservables like '");
            b.append(dsobservable);
@@ -421,6 +484,8 @@
        b.append(" and p.PAPER_ID=ds._paper_PAPER_ID");
        b.append(" order by p.SpiresId desc");
 
+       System.out.println(b.toString());
+
        if(flag.equals("count")){
            q = _session.createSQLQuery(b.toString());
        }
@@ -636,367 +701,288 @@
     }
 /////////////// now the query constructer for Papers /////////////////
 
-    public static Query Physics(String experiment, String date, String datetype, String reaction, String observable, String sqrts, String flag, org.hibernate.Session _session){
-//       System.out.println("using Physics");
 
-        List <String> isp = new ArrayList();
-        List  <String> fsp = new ArrayList();
-        List <String>  mfsp = new ArrayList();
-        List <String>  misp = new ArrayList();
-	
+    private static String getInitialState(String r){
+        String is="";
+	int ipos = r.indexOf("-->");
+	if(ipos > -1 ){ is = r.substring(0,ipos); }
+	else { is = r; }
+        return is.trim();
+    }
+    private static String getFinalState(String r){
+        String fs="";
+	int ipos = r.indexOf("-->");
+	if(ipos > -1) {fs = r.substring(ipos+3);}
+        return fs.trim();
+    }
+
+    public static Query Physics(String experiment, String date, String datetype, String reaction, String observable, String sqrts, String sqrtstype, String flag, org.hibernate.Session _session){
+//       System.out.println("using Physics");
+// new version
+ 
 //        System.out.println("Here we are in Papers");
 //        System.out.println("sorting reaction: " + reaction);
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-	if( reaction != null && !reaction.equals("") && !reaction.equals("null")) {
-////> here we have a reaction 
-	    String is = getInitialState(reaction);
-            java.util.StringTokenizer stis = new java.util.StringTokenizer(is);
-	    String st = "";
-	    while(stis.hasMoreTokens()){
-	        st = stis.nextToken();
-	        if(st.matches("^[A-Za-z].*")){
-                    if(isp.isEmpty()){
-	                isp.add(st);
-	                misp.add("1");
-		    }
-		    else{
-	                int isize = isp.size();
-		        for (int i=0; i<isize; i++){
-			    if(isp.get(i).equals(st)){
-			        int n = Integer.parseInt(misp.get(i));
-				n += 1;
-			        misp.set(i,Integer.toString(n));
-			    }
-			    else{
-	                        isp.add(st);
-	                        misp.add("1");
-			    }
-			}
-		    }	
-	        }
-	        else{
-	            isp.add(st.substring(1));
-	            misp.add(st.substring(0,1));
-	        }
-//	       isp.add(stis.nextToken());
-	    }
-	    String fs = getFinalState(reaction);
-            java.util.StringTokenizer stfs = new java.util.StringTokenizer(fs);
-	    while(stfs.hasMoreTokens()){
-	        st = stfs.nextToken();
-	        if(st.matches("^[A-Za-z].*")){
-                    if(fsp.isEmpty()){
-	                fsp.add(st);
-	                mfsp.add("1");
-		    }
-		    else{
-	                int fsize = fsp.size();
-		        for (int i=0; i<fsize; i++){
-			    if(fsp.get(i).equals(st)){
-			        int n = Integer.parseInt(mfsp.get(i));
-				n += 1;
-			        mfsp.set(i,Integer.toString(n));
-			    }
-			    else{
-	                        fsp.add(st);
-	                        mfsp.add("1");
-			    }
-			}
-		    }	
-	        }
-	        else{
-	            fsp.add(st.substring(1));
-	            mfsp.add(st.substring(0,1));
-	        }
-	    }
- 	}
+     
+        String theReaction = "";
+	    if( reaction != null && !reaction.equals("") && !reaction.equals("null")) { theReaction = reaction; }
         String theObs = "";
         if ( observable != null && !observable.equals("") && !observable.equals("null") ) { theObs  = observable;  }
-        
         String theSqrtsLo = "";
-//       System.out.println("sqrts is: " + sqrts);
         if ( sqrts != null && !sqrts.equals("") && !sqrts.equals("null")) { theSqrtsLo  = sqrts; }
 
-        Query q = null;
-
         // the string buffer way!!
         StringBuffer b = new StringBuffer();
-
-        if(isp.size() > 0){
-//select...
-//            System.out.println("we have an intial state " + isp + "/" + misp);
-//            System.out.println("and final state " + fsp + "/" + mfsp );
-//            System.out.println("and observable " + observable);
-            if (flag.equals("count")){
-     	        b.append("select count(distinct pbeam) from Paper pbeam");
+        
+        if (flag.equals("count")){
+     	   b.append("select count(distinct p.PAPER_ID) from Papers p");
 	    }
 	    else{
-     	        b.append("select distinct pbeam from Paper pbeam");
+     	    b.append("select distinct {p.*} from Papers {p}");
 	    }
+
+        if( !theReaction.equals("")){
+//   here we have a reaction       
 //joins....
-            if(experiment != null) {b.append(" join pbeam._experiments exp");}
-            if(date       != null) {b.append(" join pbeam._references ref");}
-	    b.append(" join pbeam._datasets dsbeam");
-	    b.append(" join dsbeam._yAxes yabeam");
-	    b.append(" join yabeam._reactions yrbeam");
-	    b.append(" join yrbeam._initialState beam"); 
-     	    if (isp.size() > 1){ 
-	        b.append(",Paper ptarg");
-	        b.append(" join ptarg._datasets dstarg");
-	        b.append(" join dstarg._yAxes yatarg");
-		b.append(" join yatarg._reactions yrtarg");
-		b.append(" join yrtarg._initialState targ"); 
-	    }
-            for (int i = 1 ; i <= fsp.size(); i++){ 
-	       b.append(",Paper pfsp"+i);
-	       b.append(" join pfsp"+i+"._datasets dsfsp"+i); 
-	       b.append(" join dsfsp"+i+"._yAxes yafsp"+i);
-	       b.append(" join yafsp"+i+"._reactions yrfsp"+i);
-	       b.append(" join yrfsp"+i+"._finalState fsp"+i);
-	    }
-            if( theSqrtsLo != null && !theSqrtsLo.equals("") && !theSqrtsLo.equals("null") ){
-	       b.append(",Paper pprop");
-	       b.append(" join pprop._datasets dsprop");
-	       b.append(" join dsprop._yAxes yaprop");
-	       b.append(" join yaprop._properties prop");
-	    }
+            if(experiment != null) { 
+                b.append(",PaperExpts exp");
+            }
+            b.append(",PaperRefs ref");
+	        b.append(",Datasets ds");
+	        b.append(", DsReactions dr");
+	        if ( observable != null && !observable.equals("") && !observable.equals("null") ) {b.append(", DsObservables do");}
+	        if ( sqrts != null && !sqrts.equals("") && !sqrts.equals("null") ) {
+                b.append(",YAxes ya");
+                b.append(",AxisProperties ap");
+                b.append(",BaseProperties bp");
+            }
 //where...
-    	    b.append(" where beam.name like :beampart and beam.multiplicity=:beammult");
+            b.append(" where p.PAPER_ID=ds._paper_PAPER_ID");
+            b.append(" and (dr.DsReactions like '");
+            b.append(reaction);
+            b.append("'");
+            
+            if(!reaction.endsWith("%")){
+                List<String> fsp = new ArrayList();
+                String is = getInitialState(reaction);
+                String fs = getFinalState(reaction);
+                java.util.StringTokenizer stfs = new java.util.StringTokenizer(fs);
+                while(stfs.hasMoreTokens()){ fsp.add(stfs.nextToken()); }
+                for (int n1=0; n1<fsp.size(); n1++){
+                    if(fsp.size()>1){
+                        for(int n2=0; n2<fsp.size(); n2++){
+                            if(fsp.size()==2
+                                             &&n2!=n1){
+                                 if(n1!=0&&n2!=1)
+                                 {b.append(" or dr.DsReactions like '"+is+" --> "+fsp.get(n1)+" "+fsp.get(n2)+"'");}
+                             } 
+                             else{
+                                for(int n3=0; n3<fsp.size(); n3++){
+                                    if(fsp.size()==3
+                                                    &&n3!=n2&&n3!=n1
+                                                    &&n2!=n1){
+                                    b.append(" or dr.DsReactions like '"+is+" --> "+fsp.get(n1)+" "+fsp.get(n2)+" "+fsp.get(n3)+"'");
+                                    }
+                                    else{
+                                        for(int n4=0; n4<fsp.size(); n4++){
+                                            if(fsp.size()==4  
+                                                                 &&n4!=n3&&n4!=n2&&n4!=n1
+                                                                 &&n3!=n2&&n3!=n1
+                                                                 &&n2!=n1){
+                                            b.append(" or dr.DsReactions like '"+is+" --> "+fsp.get(n1)+" "+fsp.get(n2)+" "+fsp.get(n3)+" "+fsp.get(n4)+"'");
+                                            }
+                                            else{
+                                                for(int n5=0; n5<fsp.size(); n5++){
+                                                    if(fsp.size()==5  
+                                                                 &&n5!=n4&&n5!=n3&&n5!=n2&&n5!=n1
+                                                                 &&n4!=n3&&n4!=n2&&n4!=n1
+                                                                 &&n3!=n2&&n3!=n1
+                                                                 &&n2!=n1){
+                                                    b.append(" or dr.DsReactions like '"+is+" --> "+fsp.get(n1)+" "+fsp.get(n2)+" "+fsp.get(n3)+" "+fsp.get(n4)+" "+fsp.get(n5)+"'");
+                                                    }
+                                                    else{
+                                                        for(int n6=0; n6<fsp.size(); n6++){
+                                                            if(fsp.size()==6  
+                                                                 &&n6!=n5&&n6!=n4&&n6!=n3&&n6!=n2&&n6!=n1
+                                                                 &&n5!=n4&&n5!=n3&&n5!=n2&&n5!=n1
+                                                                 &&n4!=n3&&n4!=n2&&n4!=n1
+                                                                 &&n3!=n2&&n3!=n1
+                                                                 &&n2!=n1){
+                                                            b.append(" or dr.DsReactions like '"+is+" --> "+fsp.get(n1)+" "+fsp.get(n2)+" "+fsp.get(n3)+" "+fsp.get(n4)+" "+fsp.get(n5)+" "+fsp.get(n6)+"'");
+                                                            }
+                                                        }
+                                                    }
+                                                }
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            b.append(")");
+            b.append(" and dr.DATASET_ID=ds.DATASET_ID");
+	        if ( observable != null && !observable.equals("") && !observable.equals("null") ) {
+                b.append(" and do.DsObservables like '");
+                b.append(observable);
+                b.append("' and do.DATASET_ID=ds.DATASET_ID");
+            }
+	        if ( sqrts != null && !sqrts.equals("") && !sqrts.equals("null") ) {
+                if(sqrtstype.equals(">")){ b.append(" and bp.Name like 'sqrts' and bp.LowValue>"+sqrts);} 
+                else if(sqrtstype.equals("<")){b.append(" and bp.Name like 'sqrts' and bp.HighValue<"+sqrts);}
+                else{
+                    b.append(" and bp.Name like 'sqrts' and bp.LowValue>="+sqrts);
+                    b.append(" and bp.HighValue<="+sqrts);
+                }
+                b.append(" and bp.PROPERTY_ID=ap.PROPERTY_ID");
+                b.append(" and ap._yAxis_AXIS_ID=ya.AXIS_ID");
+                b.append(" and ya._dataset_DATASET_ID=ds.DATASET_ID");
+            }
+
             if(experiment != null){       
-	        b.append(" and (exp._name like '%");
+	            b.append(" and (exp.ExptName like '%");
                 b.append(experiment);
                 b.append("%'");
-                b.append(" or exp._informalName like '%");
+                b.append(" or exp.InformalName like '%");
                 b.append(experiment);
                 b.append("%')");
-	    }
+                b.append(" and exp.PAPER_ID=p.PAPER_ID");
+	        }
             if(date != null){
-	        if(datetype.equals("=")){       
-                    b.append(" and ref._date like '%");
+	            if(datetype.equals("=")){       
+                    b.append(" and ref.Date like '%");
                     b.append(date);
                     b.append("'");}
-		else{
-                    b.append(" and ref._date " + datetype);
-                    b.append(date);
-                    b.append(" and ref._date not like ''");
-		}
-	    }
-     	    if (isp.size() > 1){ 
-	        b.append(" and targ.name=:targpart");  
-		b.append(" and yrbeam = yrtarg");
-	    } 
-            for (int i = 1 ; i <= fsp.size(); i++){ 
-	       b.append(" and fsp"+i+".name like :fsp"+i+"part and fsp"+i+".multiplicity=:fsp"+i+"mult");
-	       b.append(" and yrbeam = yrfsp"+i);
-	    }
-     	    if ( theObs != null && !theObs.equals("") && !theObs.equals("null") ) { b.append(" and yabeam._observable like:observable"); } 
-            if ( theSqrtsLo != null && !theSqrtsLo.equals("") && !theSqrtsLo.equals("null") ){
-		b.append(" and yabeam = yaprop");
-	        b.append(" and prop._name like 'sqrts' and prop._lowValue>:sqrtslo");
-	    }
+		        else{
+                    b.append(" and ref.Date " + datetype+date);
+                    b.append(" and ref.Date not like ''");
+		        }
+	        }
+            b.append(" and ref.PAPER_ID=p.PAPER_ID");
 // sort 
-            b.append(" order by pbeam._spiresId desc");
-//create query
-//make substitutions
-     	    q = _session.createQuery(b.toString());
-     	    q.setString("beampart",isp.get(0));
-     	    q.setString("beammult",misp.get(0));
-     	    if (isp.size() > 1)  {q.setString( "targpart",isp.get(1)); }
-            for (int i = 1 ; i <= fsp.size(); i++){
-	        q.setString( "fsp"+i+"part",fsp.get(i-1));
-		q.setString( "fsp"+i+"mult",mfsp.get(i-1)); 
-	    }
-//            System.out.println(q.toString());
-     	    if ( theObs != null && !theObs.equals("") && !theObs.equals("null") ) {q.setString( "observable",theObs); }
-     	    if ( theSqrtsLo != null && !theSqrtsLo.equals("") && !theSqrtsLo.equals("null") ) {q.setString( "sqrtslo",theSqrtsLo); }
+            b.append(" order by ref.Date desc");
         }
-
-        // no inital state so next assuming we have a fsp
-	else if(fsp.size() > 0) {
-//select(no initialstate)...
-            if (flag.equals("count")){
-        	b.append("select count(distinct pfsp1) from Paper pfsp1");
-	    }
-	    else{
-        	b.append("select distinct pfsp1 from Paper pfsp1");
-            }
-//joins(no initialstate)...
-            if(experiment != null) {b.append(" join pfsp1._experiments exp");}
-            if(date       != null) {b.append(" join pfsp1._references ref");}
-	    b.append(" join pfsp1._datasets dsfsp1");
-	    b.append(" join dsfsp1._yAxes yafsp1");
-	    b.append(" join yafsp1._reactions yrfsp1");
-	    b.append(" join yrfsp1._finalState fsp1"); 
-            for (int i = 2 ; i <= fsp.size(); i++){ 
-	       b.append(",Paper pfsp"+i);
-	       b.append(" join pfsp"+i+"._datasets dsfsp"+i);
-	       b.append(" join dsfsp"+i+"._yAxes yafsp"+i);
-	       b.append(" join yafsp"+i+"._reactions yrfsp"+i);
-	       b.append(" join yrfsp"+i+"._finalState fsp"+i);
-	    }
-            if ( theSqrtsLo != null && !theSqrtsLo.equals("") && !theSqrtsLo.equals("null") ) {
-	       b.append(",Paper pprop");
-	       b.append(" join pprop._datasets dsprop");
-	       b.append(" join dsprop._yAxes yaprop");
-	       b.append(" join yaprop._properties prop");
-	    }  
-//where(no initialstate)...
-     	    b.append(" where fsp1.name like :fsp1part and fsp1.multiplicity=:fsp1mult"); 
-            if(experiment != null){       
-	        b.append(" and (exp._name like '%");
-                b.append(experiment);
-                b.append("%'");
-                b.append(" or exp._informalName like '%");
-                b.append(experiment);
-                b.append("%')");
-	    }
-            if(date != null){       
-	        if(datetype.equals("=")){       
-                    b.append(" and ref._date like '%");
-                    b.append(date);
-                    b.append("'");}
-		else{
-                    b.append(" and ref._date " + datetype);
-                    b.append(date);
-                    b.append(" and ref._date not like ''");
-		}
-	    }
-            for (int i = 2 ; i <= fsp.size(); i++){ 
-	       b.append(" and fsp"+i+".name like :fsp"+i+"part and fsp"+i+".multiplicity=:fsp"+i+"mult");
-	       b.append(" and yrfsp1 = yrfsp"+i);
-	    }
-     	    if ( theObs != null && !theObs.equals("") && !theObs.equals("null") ) { b.append(" and yafsp1._observable like:observable"); } 
-            if ( theSqrtsLo != null && !theSqrtsLo.equals("") && !theSqrtsLo.equals("null") ) {
-		b.append(" and yafsp1 = yaprop");
-	        b.append(" and prop._name like 'sqrts' and prop._lowValue>:sqrtslo");
-	    }
-            b.append(" order by pfsp1._spiresId desc");
-//create query...
-     	    q = _session.createQuery(b.toString());
-//make substitutions...
-            for (int i = 1 ; i <= fsp.size(); i++){
-	      q.setString("fsp"+i+"part",fsp.get(i-1)); 
-	      q.setString("fsp"+i+"mult",mfsp.get(i-1)); 
-	    }
-     	    if ( theObs != null && !theObs.equals("") && !theObs.equals("null") ) {q.setString("observable",theObs);}
-     	    if ( theSqrtsLo != null && !theSqrtsLo.equals("") && !theSqrtsLo.equals("null") ) {q.setString( "sqrtslo",theSqrtsLo); }
-	}
+  
+////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // OK no reaction  .. so do we have an observable?
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
         else if ( theObs != null && !theObs.equals("") && !theObs.equals("null") ) {
 //> here we have no reaction but an observable
-            if (flag.equals("count")){
-    	        b.append("select count(distinct pobs) from Paper pobs");
+            if(experiment != null) { 
+                b.append(",PaperExpts exp");
             }
-	    else{
-     	        b.append("select distinct pobs from Paper pobs");
+            b.append(",PaperRefs ref");
+	        b.append(",Datasets ds");
+	        b.append(", DsObservables do");
+	        if ( sqrts != null && !sqrts.equals("") && !sqrts.equals("null") ) {
+                b.append(",YAxes ya");
+                b.append(",AxisProperties ap");
+                b.append(",BaseProperties bp");
             }
-            if(experiment != null) {b.append(" join pobs._experiments exp");}
-            if(date       != null) {b.append(" join pobs._references ref");}
-            b.append(" join pobs._datasets dsobs join dsobs._yAxes yaobs"); 
-            if ( theSqrtsLo != null && !theSqrtsLo.equals("") && !theSqrtsLo.equals("null") ) {
-	       b.append(",Paper pprop");
-	       b.append(" join pprop._datasets dsprop");
-	       b.append(" join dsprop._yAxes yaprop");
-	       b.append(" join yaprop._properties prop");
-	    }  
-     	    b.append(" where yaobs._observable like:observable");  
+
+//where
+            b.append(" where p.PAPER_ID=ds._paper_PAPER_ID");
+            b.append(" and do.DsObservables like '");
+            b.append(observable);
+            b.append("' and do.DATASET_ID=ds.DATASET_ID");
+	        if ( sqrts != null && !sqrts.equals("") && !sqrts.equals("null") ) {
+                if(sqrtstype.equals(">")){b.append(" and bp.Name like 'sqrts' and bp.LowValue>"+sqrts);} 
+                else if(sqrtstype.equals("<")){b.append(" and bp.Name like 'sqrts' and bp.HighValue<"+sqrts);}
+                else{
+                    b.append(" and bp.Name like 'sqrts' and bp.LowValue>="+sqrts);
+                    b.append(" and bp.HighValue<="+sqrts);
+                }
+                b.append(" and bp.PROPERTY_ID=ap.PROPERTY_ID");
+                b.append(" and ap._yAxis_AXIS_ID=ya.AXIS_ID");
+                b.append(" and ya._dataset_DATASET_ID=ds.DATASET_ID");
+            }
+
             if(experiment != null){       
-	        b.append(" and (exp._name like '%");
+	            b.append(" and (exp.ExptName like '%");
                 b.append(experiment);
                 b.append("%'");
-                b.append(" or exp._informalName like '%");
+                b.append(" or exp.InformalName like '%");
                 b.append(experiment);
                 b.append("%')");
-	    }
-            if(date != null){       
-	        if(datetype.equals("=")){       
-                    b.append(" and ref._date like '%");
+                b.append(" and exp.PAPER_ID=p.PAPER_ID");
+	        }
+            if(date != null){
+	            if(datetype.equals("=")){       
+                    b.append(" and ref.Date like '%");
                     b.append(date);
                     b.append("'");}
-		else{
-                    b.append(" and ref._date " + datetype);
-                    b.append(date);
-                    b.append(" and ref._date not like ''");
-		}
-	    }
-            if ( theSqrtsLo != null && !theSqrtsLo.equals("") && !theSqrtsLo.equals("null") ) {
-		b.append(" and yaobs = yaprop");
-	        b.append(" and prop._name like 'sqrts' and prop._lowValue>:sqrtslo");
+		        else{
+                    b.append(" and ref.Date " + datetype+date);
+                    b.append(" and ref.Date not like ''");
+		        }
+	        }
+            b.append(" and ref.PAPER_ID=p.PAPER_ID");
+// sort 
+            b.append(" order by ref.Date desc");
 	    }
-            b.append(" order by pobs._spiresId desc");
-     	    q = _session.createQuery(b.toString());
-     	    q.setString("observable",theObs);
-     	    if ( theSqrtsLo != null && !theSqrtsLo.equals("") && !theSqrtsLo.equals("null") ) {q.setString( "sqrtslo",theSqrtsLo); }
-	}
-
+///////////////////////////////////////////////////////////////////////////////////////////////////////////
 // here if sqrtslo on its own ! just to test 
         else if ( theSqrtsLo != null && !theSqrtsLo.equals("") && !theSqrtsLo.equals("null") ) {
-            if (flag.equals("count")){
-    	        b.append("select count(distinct pprop) from Paper pprop");
+            if(experiment != null) { b.append(",PaperExpts exp");}
+            b.append(",PaperRefs ref");
+	        b.append(",Datasets ds");
+            b.append(",YAxes ya");
+            b.append(",AxisProperties ap");
+            b.append(",BaseProperties bp");
+//where
+            b.append(" where p.PAPER_ID=ds._paper_PAPER_ID");
+            if(sqrtstype.equals(">"))    { b.append(" and bp.Name like 'sqrts' and bp.LowValue>"+sqrts);} 
+            else if(sqrtstype.equals("<")){b.append(" and bp.Name like 'sqrts' and bp.HighValue<"+sqrts);}
+            else{
+                b.append(" and bp.Name like 'sqrts' and bp.LowValue>="+sqrts);
+                b.append(" and bp.HighValue<="+sqrts);
             }
-	    else{
-    	        b.append("select distinct pprop from Paper pprop");
-            }
-            if(experiment != null) {b.append(" join pprop._experiments exp");}
-            if(date       != null) {b.append(" join pprop._references ref");}
-	    b.append(" join pprop._datasets dsprop");
-	    b.append(" join dsprop._yAxes yaprop");
-	    b.append(" join yaprop._properties prop");
-
-            b.append(" where prop._name like 'sqrts' and prop._lowValue>:sqrtslo");
+            b.append(" and bp.PROPERTY_ID=ap.PROPERTY_ID");
+            b.append(" and ap._yAxis_AXIS_ID=ya.AXIS_ID");
+            b.append(" and ya._dataset_DATASET_ID=ds.DATASET_ID");
             if(experiment != null){       
-	        b.append(" and (exp._name like '%");
+	            b.append(" and (exp.ExptName like '%");
                 b.append(experiment);
                 b.append("%'");
-                b.append(" or exp._informalName like '%");
+                b.append(" or exp.InformalName like '%");
                 b.append(experiment);
                 b.append("%')");
-	    }
-            if(date != null){       
-	        if(datetype.equals("=")){       
-                    b.append(" and ref._date like '%");
+                b.append(" and exp.PAPER_ID=p.PAPER_ID");
+	        }
+            if(date != null){
+	            if(datetype.equals("=")){       
+                    b.append(" and ref.Date like '%");
                     b.append(date);
                     b.append("'");}
-		else{
-                    b.append(" and ref._date " + datetype);
-                    b.append(date);
-                    b.append(" and ref._date not like ''");
-		}
+		        else{
+                    b.append(" and ref.Date " + datetype + date);
+                    b.append(" and ref.Date not like ''");
+		        }
+	        }
+            b.append(" and ref.PAPER_ID=p.PAPER_ID");
+// sort 
+            b.append(" order by ref.Date desc");
 	    }
-            b.append(" order by pprop._spiresId desc");
-    	    q = _session.createQuery(b.toString());
-     	    q.setString("sqrtslo",theSqrtsLo);
-	}
+///////////////////////////////////////////////////////////////////////////////////////////
 // nothing left so must want everything !!
-	else{
-            if (flag.equals("count")){
-	        b.append("select count(distinct pa) from Paper pa");
-            }
 	    else{
-	        b.append("select distinct pa from Paper pa");
-            }
-            b.append(" join pa._references ref");
-            b.append(" order by ref._date desc");
-     	    q = _session.createQuery(b.toString());
-	}
-
-//        System.out.println(q.toString());
+            b.append(",PaperRefs ref");
+            b.append(" where ref.PAPER_ID=p.PAPER_ID");
+// sort 
+            b.append(" order by ref.Date desc");
+        }
+//////////////////////////////////////////////////////////////////////////////////////////////
+//create query
+        Query q = null;
+        if(flag.equals("count")){
+            q = _session.createSQLQuery(b.toString());
+        }
+        else{
+            q = _session.createSQLQuery(b.toString()).addEntity("p",Paper.class);
+            } 
         return q;
-
     }
 
-    private static String getInitialState(String r){
-        String is="";
-	int ipos = r.indexOf("-->");
-	if(ipos > -1 ){ is = r.substring(0,ipos); }
-	else { is = r; }
-        return is.trim();
-    }
-    private static String getFinalState(String r){
-        String fs="";
-	int ipos = r.indexOf("-->");
-	if(ipos > -1) {fs = r.substring(ipos+3);}
-        return fs.trim();
-    }
 }


More information about the HepData-svn mailing list