7 Replies Latest reply on Oct 26, 2007 1:10 PM by pmuir

    EntityQuery Restrictions

    griffitm

      Hello All,

      I have some components generated by seamgen, specifically the EntityQuery Lists that relate to a list of entity objects. The seam generated search form allows the restrictions to be passed to the query:

      public class StatusList extends EntityQuery {
      
       private static final String[] RESTRICTIONS = {"lower(status.description) like concat('%', concat(lower(#{statusList.status.description}),'%'))",};
      ...
       private Status status = new Status();
      
       @Override
       public String getEjbql() {
       return "select status from Status status order by status.sortOrder";
       }
      ...

      The query works well if no parameters are passed to the restrictions, the list is returned in the correct order, however if I pass a parameter to the restrictions clause the predicates of where/order are mixed up and invalid SQL is executed, which of course produces an error.

      What is the correct way to approach this?

      Thanks in advance!
      MG


        • 1. Re: EntityQuery Restrictions
          pmuir

          Try

          public class StatusList extends EntityQuery {
          
           private static final String[] RESTRICTIONS = {"lower(status.description) like concat('%', concat(lower(#{statusList.status.description}),'%'))",};
          ...
           private Status status = new Status();
          
           @Override
           public String getEjbql() {
           return "select status from Status status";
           }
          
           @Override
           public String getOrder() {
           return "status.sortOrder";
           }
          ...


          • 2. Re: EntityQuery Restrictions
            griffitm

            Doh! Thanks!

            • 3. Re: EntityQuery Restrictions
              griffitm

              Overriding the getOrder method as below then disables the clickable sorting feature of the data tables:

               <h:column>
               <f:facet name="header">
               <s:link styleClass="columnHeader"
               value="Description #{statusList.order=='description asc' ? messages.down : ( statusList.order=='description desc' ? messages.up : '' )}">
               <f:param name="order" value="#{statusList.order=='description asc' ? 'description desc' : 'description asc'}"/>
               </s:link>
               </f:facet>
               #{status.description}
               </h:column>
              

              No longer seems to work, because I suspect the sort order is always returned by the Entity as what is returned by getOrder(). Is there any way for both to happily co-exist?

              Do I need to override setOrder as well, and only return the hard coded value if null?

              Thanks in advance for any help!
              MG

              • 4. Re: EntityQuery Restrictions
                griffitm

                This seems to work:

                 @Override
                 public String getOrder(){
                 if(super.getOrder() == null){
                 return "status.sortOrder";
                 }
                 return super.getOrder();
                
                 }
                


                • 5. Re: EntityQuery Restrictions
                  pmuir

                  Or hold an order field locally and implement both get and setOrder...

                  • 6. Re: EntityQuery Restrictions
                    griffitm

                    It seems that if you specify a query declaratively using the framework entity query, you loose the ability to sort data in a data table, because the data is always returned in the same order by the query. Can you pass the order by clause dynamically by declaring it as something that is a parameter to the query?

                    Thanks in advance,
                    MG

                    • 7. Re: EntityQuery Restrictions
                      pmuir

                      What? you posted the solution above.