4 Replies Latest reply on Nov 25, 2008 6:37 PM by cyberanto

    OR-Relationship in EntityQuery

    michaelschuetz

      Hi,


      my Class TestList extends EntityQuery. I have defined restrictions into my class. Using this restrictions works fine. The search is always performed with an logical AND. That happens in th Query.class:


        

         protected String getRenderedEjbql()
         {
            StringBuilder builder = new StringBuilder().append(parsedEjbql);
            
            for (int i=0; i<getRestrictions().size(); i++)
            {
               Object parameterValue = restrictionParameters.get(i).getValue();
               if ( isRestrictionParameterSet(parameterValue) )
               {
                  if ( WHERE_PATTERN.matcher(builder).find() )
                  {
                     builder.append(" and ");
                  }
                  else
                  {
                     builder.append(" where ");
                  }
                  builder.append( parsedRestrictions.get(i) );
               }
            }
               
            if ( getOrder()!=null ) builder.append(" order by ").append( getOrder() );
            
            return builder.toString();
         }
         



      I would like to be able to perform a logical OR as well.
      Do I need to override this method or is there a more charming way to do that.


      Thank you very much
      Michael


        • 1. Re: OR-Relationship in EntityQuery
          michaelschuetz

          OK - maybe I did not point out my issue exactly enough.
          What ist the recommend way to manipulate how the ejbql is performed? So how to use restrictions with an logical OR??


          thanks a lot
          Michael

          • 2. Re: OR-Relationship in EntityQuery
            serkan.s.eskici.online.nl

            I need this feature too.


            In my jsf page, I've an inputText where one can enter search terms for filtering all the data of my dataTable.


            And unfortunatelly, I couldn't make this work.


            I guess that my last option is to use HibernateSearch, but then I won't be able to make use of the paging feature of EntityQueries.





            • 3. Re: OR-Relationship in EntityQuery

              I have the same problem.


              I would like to put my ORs inside an AND restriction, but EntityQuery currently does not support more than one value binding in a restriction
              (https://jira.jboss.org/jira/browse/JBSEAM-1065).


              With that issue resolved, you could do something like:


              xx = #{yy} OR xx = #{zz} 
              



              right ?


              Another related problem is that EntityQuery requires one value binding per restriction, so you cannot use is null nor is not null in a restriction..




              • 4. Re: OR-Relationship in EntityQuery
                cyberanto

                In my current project Seam is not allowed yet (I have been using it before, what a step backwards!). We still hope in a future phase to change our technology stack (and include SEAM), so I decided to write some framework classes which copy certain parts of SEAMs API and allow the develoeprs to code as if they had seam available, and make our code immediatley usable once we switch to SEAM.


                One of the APIs I have created is EntityQuery (light :). Like in SEAM, the user can specify restrictions, and I had the same issues mentioned above:


                (1) developers want more than one value binding: while I allow this, it comes with a big caveat: The restriction is usually removed from the query when the value binding returns null - i.e. no value for this e.g. search parameter is available, we do not want to include this feature. This is very different from specifically querying for a null value. If you have more than one value expression, what behaviour do you expect? Should the whole restriction disappear if just one value binding returns null (this is how my implementation works, but it is clearly an issue).


                (2) I was considering adding expansions (as apposed to restrictions), which are OR-ed. After realizing that the order in which the ANDs and ORs are combined influences the outcome (e.g. http://oreilly.com/catalog/mastorasql/chapter/ch07.html), I decided not to do that. One still can use OR in subclauses within a restriction if necessary.


                This second point goes all the way back to the end-users: they had not thought about the effect the ordering of the filters has once one combines AND and OR clauses.