2 Replies Latest reply on Jul 28, 2004 5:03 AM by Nathalie M.

    Dynamic query in ejb (cmp)

    Nathalie M. Newbie

      Hello,

      What I'm trying to do is :

      1) Create my query in my "action class" (String query = "SELECT * from t_myTable") // Ok

      2) And then pass this query to the finder //Cannot figure out how to do that...

      I've tried this in my ejbe :

      @ejb.finder
       * signature = "Collection findDyna(java.lang.String param)"
       * query= ""
       * @jboss.query
       * signature = "Collection findDyna(java.lang.String param)"
       * query = "?1" //what to put here ??
       * dynamic="true"
      

      I also have tried to implement a method in my ejbe, but cannot figure out how to put that all together :
      /**
      * @jboss.dynamic-ql
       * /
      public Collection findDyna(String param){
       StringBuffer jbossQl = new StringBuffer(param);
      
       return findDyna(jbossQl.toString());
      }
      

      Could you tell me the steps to follow ?

      Thanks
      Nath.

        • 1. Re: Dynamic query in ejb (cmp)
          Frank Langelage Master

          This works for me:
          define a jboss-query for the EB with args query String and Object array for the parameters:
          /**
          * @jboss.query dynamic="true" signature="java.util.Collection ejbSelectGeneric(java.lang.String query, java.lang.Object[] params)"
          */

          create a method for the home interface which takes the same args as the defined query and calls the query method:
          /**
          * @ejb.home-method
          */
          public java.util.Collection ejbHomeDynamicQuery( String query, Object[] params ) throws javax.ejb.FinderException
          {
          return ejbSelectGeneric( query, params );
          }

          This method you call from you app-code:
          Collection c = home.dynamicQuery(query.toString(), new Object[] {});

          • 2. Re: Dynamic query in ejb (cmp)
            Nathalie M. Newbie

            Youhouhouh it seems to be working.

            Thanks really a lot because I didn't find the exact answer on any other website/forum.

            Thanks :)

            Nath.