1 2 Previous Next 17 Replies Latest reply on Dec 2, 2003 5:01 AM by ongtw

    New EJB-QL compiler (ORDER BY and DynamicQL)

    dsundstrom

      The new EJB-QL compiler is finished and checked in tip. The new compiler is a complete rewrite in JavaCC, and is much faster, easier to maintain, and has error messages. I was surprised by the number of errors I found in the old parser. You guys haven't been pushing the engine enough, so to give you incentive to test the new engine I've added several new features.


      Error messages:
      This is not really a feature but as we didn't have them before it feels like a feature.

      JBossQL:
      I actually wrote two compilers a spec compliant EJB-QL compiler and JBossQL compiler. JBossQL is a superset of EJB-QL which adds support for ORDER BY. To use JBossQL you override ejb-ql declaration in your jbosscmp-jdbc.xml file with a jboss-ql element (i.e. just copy the query element from your ejb-jar.xml file, change ejb-ql to jboss-ql and add the order by clause. The BNF for order by follows:

       JBossQL := select_clause from_clause [where_clause] [order_by_clause]
       order_by_clause := ORDER BY order_by_path_expression (, order_by_path_expression)*
       order_by_path_expression := ( numeric_valued_path | string_valued_path | datetime_valued_path ) [ASC | DESC]
      

      dynamic-ql:
      The new compiler is eye-blink fast, so I added a new query type dynamic-ql. With dynamic-ql you can generate a JBossQL query and pass it along with the parameters to the engine to be compiled and execute at runtime. To use this query you add an ejbSelect method to your bean with the following signature:
       <return-type> ejbSelect<some-name>(String jbossQL, Object[] args)
      

      You must declare the query type in your ejb-jar.xml (required by the spec; just leave the ejb-ql element empty) and in your jbosscmp-jdbc.xml file override the impl with an empty <dynamic-ql/> element.

      For more info specifying the queries, see the jbosscmp-jdbc_3_0.dtd

        • 1. Re: New EJB-QL compiler (ORDER BY and DynamicQL)
          hunterhillegas

          So far the new stuff is working great for me. Thanks Dain.

          • 2. Re: New EJB-QL compiler (ORDER BY and DynamicQL)
            sheepe

            Hmm.. it must be my code, but anyway. These EJB-QL queries used to work before, and they stopped doing so:

            SELECT OBJECT(c) FROM Category C WHERE C = ?1
            SELECT OBJECT(p) FROM Product AS p WHERE ?1 MEMBER OF p.categories

            The new parser says it was expecting something other than '?1'.. What's the problem here?

            tia,
            Christopher

            • 3. Re: New EJB-QL compiler (ORDER BY and DynamicQL)
              dsundstrom

              Can you give the exact error message (not the stack trace) and the parameter types?

              • 4. Re: New EJB-QL compiler (ORDER BY and DynamicQL)
                sheepe

                Query:
                SELECT OBJECT(p) FROM Product AS p WHERE ?1 MEMBER OF p.categories

                Parameter: new Integer(1) - for example

                Error message:
                org.jboss.deployment.DeploymentException: Error compiling ejbql; - nested throwable is: org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "1" at line 1, column 42.
                Was expecting one of:
                "NOT" ...
                <IDENTIFICATION_VARIABLE> ...
                <ENTITY_VALUED_PARAMETER> ...
                <ENTITY_VALUED_PATH> ...
                <COLLECTION_VALUED_PATH> ...
                "(" ...
                <STRING_VALUED_PATH> ...
                "CONCAT" ...
                "SUBSTRING" ...
                <BOOLEAN_VALUED_PATH> ...
                <DATETIME_VALUED_PATH> ...
                <NUMERIC_VALUED_PATH> ...
                "LENGTH" ...
                "LOCATE" ...
                "ABS" ...
                "SQRT" ...
                "+" ...
                "-" ...
                <INTEGER_LITERAL> ...
                <FLOATING_POINT_LITERAL> ...
                <NUMERIC_VALUED_PARAMETER> ...

                • 5. Re: New EJB-QL compiler (ORDER BY and DynamicQL)
                  dsundstrom

                  The problem is you are trying to determine if an NumericValuedParameter is a member of an EntityCollection. Change your parameter type to Category.

                  I tested the following query:

                  SELECT OBJECT(p)
                  FROM Product AS p
                  WHERE ?1 NOT MEMBER OF p.productCategories
                  


                  BTW, you helped me find a different bug with parameter indexes in MEMBER OF were being pased a base-one (the system expects base-zero internally).

                  • 6. Re: New EJB-QL compiler (ORDER BY and DynamicQL)
                    pazu

                    Would you please, pleas add the possibility to use parameters in LIKE clauses to JBoss-QL? So we can do something like

                    SELECT OBJECT(o) From Entity o WHERE o.field LIKE ?1
                    

                    and ?1 would contain % and the like (pun intended).

                    • 7. Re: New EJB-QL compiler (ORDER BY and DynamicQL)
                      dsundstrom

                      Please, post this undet the "JBossQL feature requests" topic.

                      • 8. Re: New EJB-QL compiler (ORDER BY and DynamicQL)
                        henniges

                        Regarding the J2EE tutorial at sun (http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/EJBQL4.html) the following EJB-QL should work:

                        SELECT DISTINCT OBJECT(p)
                        FROM Player p, IN (p.teams) AS t
                        WHERE t.league = ?1

                        So why does the following EJB-QL not work?

                        SELECT OBJECT(b) FROM Ber b, IN (b.pers) AS p
                        WHERE p.name = ?1

                        server.log:
                        2002-02-27 23:18:34,193 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.Ber.findByName] EJB-QL: SELECT OBJECT(b) FROM Ber b, IN (b.pers) AS p WHERE p.name = ?1
                        2002-02-27 23:18:34,603 ERROR [org.jboss.ejb.EntityContainer] Exception in service lifecyle operation: start
                        org.jboss.deployment.DeploymentException: Error compiling ejbql; - nested throwable is: org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "b.pers" at line 1, column 36.
                        Was expecting:
                        <COLLECTION_VALUED_PATH> ...

                        org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "b.pers" at line 1, column 36.
                        Was expecting:
                        <COLLECTION_VALUED_PATH> ...


                        Thanks for help!

                        • 9. Re: New EJB-QL compiler (ORDER BY and DynamicQL)
                          dsundstrom

                          Read the error message again.

                          Encountered "b.pers" at line 1, column 36. Was expecting:
                          <COLLECTION_VALUED_PATH> ...

                          It means that b.pers is not a collection valued path.

                          • 10. Re: New EJB-QL compiler (ORDER BY and DynamicQL)
                            jasonuithol

                            Hello !

                            I downloaded the Jboss3.0beta and then saw a post regarding the new EJB-QL parser, which I would love to have !!

                            Is there an easy "patch" method to the beta so that I can just pop in the new parser ? NOTE: I don't have the source for the beta.

                            • 11. Re: New EJB-QL compiler (ORDER BY and DynamicQL)
                              jasonuithol

                              I might just add that if getting the source and rebuilding from it would make life easier, I will endeavour to do so.

                              Some instructions for getting the source for the beta would be greatly appreciated if that is the case...

                              Jason Uithol.

                              P.S. Great system guys !

                              • 12. Casting INTEGER_VALUED_PATH to String ???
                                jasonuithol

                                Hello Dain,

                                I CVSed the latest source and built it. It contains the new EJB-QL parser. I am now having string/integer casting problems.

                                - - - - - - - - - - - - - - - - - - - - - - - - - - -

                                I have an EJB-QL expression:

                                STRING_VALUED_PATH = INTEGER_VALUED_PATH

                                Now, so far - I have not been able to get any variants to match any productions, e.g. CONCAT etc.

                                Is is possible to compare a string to an integer ????


                                Jason.

                                • 13. Re: Casting INTEGER_VALUED_PATH to String ???
                                  dsundstrom

                                  Just for the archives, this was answered on the jboss-user list. EJB-QL only allows the comparison of like types.

                                  • 14. Re: Casting INTEGER_VALUED_PATH to String ???
                                    liuqiang_home

                                    Hi! I am using the dynamic-QL plus Order By, I want to do the following:

                                    SELECT OBJECT(g) FROM UserInfo g ORDER BY ?1

                                    I pass the argument as:

                                    Object[] args= new Object[1];
                                    args[0]= "g." + Order; //Order is Column name I pass in

                                    But I got the following error message:

                                    [junit] There was 1 error:
                                    [junit] 1) testIVSSDataLayer_none(com.numeritech.ivss.dataLayer.ivstest)
                                    [junit] javax.ejb.FinderException: Error compiling ejbql: org.jboss.ejb.plugins.cmp.ejbql.ParseE
                                    tion: Encountered "1" at line 1, column 44.
                                    [junit] Was expecting one of:
                                    [junit] <NUMERIC_VALUED_PATH> ...
                                    [junit] <STRING_VALUED_PATH> ...
                                    [junit] <DATETIME_VALUED_PATH> ...
                                    [junit]
                                    [junit] at org.jboss.ejb.plugins.cmp.jdbc.JDBCDynamicQLQuery.execute(JDBCDynamicQLQuery.java

                                    [junit] at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCSelectorBridge.execute(JDBCSelectorBrid
                                    ava:64)
                                    [junit] at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke(EntityBridg
                                    ocationHandler.java:95)
                                    [junit] at org.jboss.proxy.compiler.Runtime.invoke(Runtime.java:59)
                                    _______________________________

                                    it seems Dynamic-QL doesnot support this, am I right? or I did something wrong.

                                    Thanks for reply !


                                    1 2 Previous Next