[xwiki-users] XWQL issue
Hi, I fail to get a good understandinding of XWiki Query Language (my goal is to transform working HQL to XWQL) This code is working… {{velocity}} #set($classname = "CdLSATEPublic.CdLSATEPublicClass") #set($findWQL = " from doc.object($classname) as qat ") #set($resultDocuments = $services.query.xwql($findWQL).execute()) #foreach($resultDocument in $resultDocuments) $resultDocument #end {{/velocity}} While this code is not working.. {{velocity}} #set($classname = "CdLSATEPublic.CdLSATEPublicClass") #set($findWQL = " from doc.object($classname) as qat where qat.language = 'en' ") #set($resultDocuments = $services.query.xwql($findWQL).execute()) #foreach($resultDocument in $resultDocuments) $resultDocument #end {{/velocity}} Where is my problem? (see error code below…) Caused by: org.xwiki.velocity.XWikiVelocityException: Failed to evaluate content with id [xwiki:CdlsatdCode.try2] at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:247) at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:184) at org.xwiki.rendering.internal.macro.velocity.VelocityMacro.evaluateString(VelocityMacro.java:124) ... 106 more Caused by: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'execute' in class org.xwiki.query.internal.DefaultQuery threw exception org.xwiki.query.QueryException: Exception while translating [ from doc.object(CdLSATEPublic.CdLSATEPublicClass) as qat where qat.language = 'en' ] XWQL query to the [hql] language. Query statement = [ from doc.object(CdLSATEPublic.CdLSATEPublicClass) as qat where qat.language = 'en' ] at xwiki:CdlsatdCode.try2[line 7, column 57] at org.apache.velocity.runtime.parser.node.ASTMethod.handleInvocationException(ASTMethod.java:243) at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:187) at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:280) at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:567) at org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:71) at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:142) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342) at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:228) ... 108 more Caused by: org.xwiki.query.QueryException: Exception while translating [ from doc.object(CdLSATEPublic.CdLSATEPublicClass) as qat where qat.language = 'en' ] XWQL query to the [hql] language. Query statement = [ from doc.object(CdLSATEPublic.CdLSATEPublicClass) as qat where qat.language = 'en' ] at org.xwiki.query.xwql.internal.XWQLQueryExecutor.execute(XWQLQueryExecutor.java:76) at org.xwiki.query.internal.DefaultQueryExecutorManager.execute(DefaultQueryExecutorManager.java:72) at org.xwiki.query.internal.SecureQueryExecutorManager.execute(SecureQueryExecutorManager.java:80) at org.xwiki.query.internal.DefaultQuery.execute(DefaultQuery.java:236) at sun.reflect.GeneratedMethodAccessor413.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:395) at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:384) at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:173) ... 114 more Caused by: org.xwiki.query.jpql.lexer.LexerException: [1,95] Unknown token: at org.xwiki.query.jpql.lexer.Lexer.getToken(Lexer.java:809) at org.xwiki.query.jpql.lexer.Lexer.peek(Lexer.java:36) at org.xwiki.query.jpql.parser.Parser.parse(Parser.java:110) at org.xwiki.query.jpql.internal.JPQLParser.parse(JPQLParser.java:46) at org.xwiki.query.xwql.internal.hql.XWQLtoHQLTranslator.translate(XWQLtoHQLTranslator.java:55) at org.xwiki.query.xwql.internal.XWQLQueryExecutor.execute(XWQLQueryExecutor.java:59) ... 123 more Gerritjan
try ... where qat.language like 'en' ... :) I don't know why -- Best regards Eugen Colesnicov -- View this message in context: http://xwiki.475771.n2.nabble.com/XWQL-issue-tp7532124p7546601.html Sent from the XWiki- Users mailing list archive at Nabble.com.
I think I just found the problem ... Instead of : #set($findWQL = " from doc.object($classname) as qat ") ... Write this : #set($findWQL = " from doc.object($classname) as qat ") It seems the XWQL parser does not like carriage-return in queries at all ... :) Best regards, Jeremie 2012/5/10 Eugen Colesnicov <[email protected]>
try ... where qat.language like 'en' ...
:) I don't know why
-- Best regards Eugen Colesnicov
-- View this message in context: http://xwiki.475771.n2.nabble.com/XWQL-issue-tp7532124p7546601.html Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
If, like me, you want to keep your xwql readable, you can also add this after assigning the xwql string : #set($xwql = " select ... ") #set($Q="\n") #set($xwql = $xwql.replaceAll("$Q", " ")) It will just remove the carriage-return so XWQL parser does not complain, BR, Jeremie 2012/5/14 Jeremie BOUSQUET <[email protected]>
I think I just found the problem ... Instead of :
#set($findWQL = " from doc.object($classname) as qat ")
... Write this :
#set($findWQL = " from doc.object($classname) as qat ")
It seems the XWQL parser does not like carriage-return in queries at all ... :)
Best regards, Jeremie
2012/5/10 Eugen Colesnicov <[email protected]>
try ... where qat.language like 'en' ...
:) I don't know why
-- Best regards Eugen Colesnicov
-- View this message in context: http://xwiki.475771.n2.nabble.com/XWQL-issue-tp7532124p7546601.html Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
On May 14, 2012, at 12:25 PM, Jeremie BOUSQUET wrote:
If, like me, you want to keep your xwql readable, you can also add this after assigning the xwql string :
#set($xwql = " select ...
") #set($Q="\n") #set($xwql = $xwql.replaceAll("$Q", " "))
Personally I find this less readable but that's just me ;) Thanks -Vincent
It will just remove the carriage-return so XWQL parser does not complain,
BR, Jeremie
2012/5/14 Jeremie BOUSQUET <[email protected]>
I think I just found the problem ... Instead of :
#set($findWQL = " from doc.object($classname) as qat ")
... Write this :
#set($findWQL = " from doc.object($classname) as qat ")
It seems the XWQL parser does not like carriage-return in queries at all ... :)
Best regards, Jeremie
2012/5/10 Eugen Colesnicov <[email protected]>
try ... where qat.language like 'en' ...
:) I don't know why
-- Best regards Eugen Colesnicov
-- View this message in context: http://xwiki.475771.n2.nabble.com/XWQL-issue-tp7532124p7546601.html Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
participants (4)
-
Eugen Colesnicov -
Gerritjan Koekkoek -
Jeremie BOUSQUET -
Vincent Massol