1 Reply Latest reply on Nov 24, 2004 2:44 PM by jobor

    how to validate the EJB QL

      I got JBoss DynamicQL working with Xdoclet!!

      Here are changes (from my original posts) I had to do....

      1) Change the declaration of 'searchProducts()' in my ProductBean to 'ejbHomeSearchProducts()'.
      Note case sensitivity. This causes a 'searchProducts()' method to be put in the ProductLocalHome interface
      (er, the @ejb.home-interface tag does).

      That got rid of the 'Warning: Each local home method must match a method...' error msg at deployment.

      2) Change the declaration and use of 'findGeneral()' to 'ejbSelectGeneral()'. Xdoclet appears to be looking for specific
      function name prefixes and handles them accordingly. 'ejbSelect...()' is one of them.

      3) Removed the @ejb.finder signature="java.util.Collection ejbSelectGeneral...' tag in ProductBean.java.
      But I had to leave the @jboss.query signature="java.util.Collection ejbSelectGeneral...' tag in there.

      For some reason, Xdoclet was putting two

       <query>
       <query-method>
       <method-name>ejbSelectGeneral</method-name>
      

      nodes in the ejb-jar.xml file (but only one in the jbosscmp-jdbc.xml file. Just declaring the
      'public abstract Collection ejbSelectGeneral(...)' method in the bean file was enough for Xdoclet to add a single <query...>
      node to ejb-jar.xml.

      Done!

      Well, not quite. I reeeeeally want to use the SQL LIKE operator with parameters. Guess I need to upgrade to 3.2.6 or 4.0.....


        • 1. Re: how to validate the EJB QL
          jobor

          I'm using DynamicQL with a SearchObject (Value Object for searching) the following way. Maybe it gives you a hint for the LIKE. This is working on 3.2.x.

          public abstract Collection ejbSelectGeneric(String jbossQl, Object[] args) throws FinderException;
          
          /**
           * @ejb.home-method
           */
          public Collection ejbHomeGetBySearch(SearchObject so) throws FinderException {
           ArrayList argsList = new ArrayList();
           StringBuffer jbossQl = new StringBuffer();
           jbossQl.append("SELECT OBJECT(t) ");
           jbossQl.append("FROM Table_x t ");
           int bindCount = 0;
           if (so.getNumberCriterion()) {
           bindCount++;
           jbossQl.append((bindCount == 1 ? "WHERE" : "AND") + " t.column1 LIKE ?" + bindCount + " ");
           argsList.add(so.getColumn1());
           }
           if (so.getTitleCriterion()) {
           bindCount++;
           jbossQl.append((bindCount == 1 ? "WHERE" : "AND") + " t.column2 LIKE ?" + bindCount + " ");
           argsList.add(so.getColumn2());
           }
           jbossQl.append("ORDER BY t.column1 ASC");
           Object[] args = argsList.toArray();
           return ejbSelectGeneric(jbossQl.toString(), args);
          }
          


          Johan