1 Reply Latest reply on Jul 7, 2011 2:52 AM by omid pourhadi

    different Query, different users

    omid pourhadi Apprentice

      Hi,


      I have an EntityQuery Class as below and i want to have different restriction based on different roles


      How can i do that ? any idea ?




      @Name("madeLicenseQuery")
      public class MadeLicenseQuery extends EntityQuery<MadeLicense> {
           
           private static final long serialVersionUID = 1L;
      
           private static final String EJBQL = "select ml from MadeLicense ml ";
           
           //when role is admin
           private static final String[] RESTRICTIONS = { "lower(ml.number) like concat(lower(#{madeLicenseQuery.madeLicense.number}),'%')",
                          "ml.member.id = #{gameMember.id}"                                             };
      
      //when role is not admin ???
      private String another restriction;
           
           public MadeLicenseQuery() {
                setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
      
                     
                setEjbql(EJBQL);
                
                setMaxResults(20);
                setOrderDirection("desc");
                setOrderColumn("id");
           }
           
           MadeLicense madeLicense = new MadeLicense();
      
           public MadeLicense getMadeLicense() {
                return madeLicense;
           }
           
           
      
           
      }
      



        • 1. Re: different Query, different users
          omid pourhadi Apprentice

          Hi,


          I've already found a solution but i'm looking for a better alternative if there is any





          Identity identity = Identity.instance();
          
          if(identity.hasRole("admin"))
          {
               setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS[0]));
          }
          else
          {
               setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS[1]));
          }







          thanx in advanced