jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Mueller (JIRA)" <j...@apache.org>
Subject [jira] Updated: (JCR-2282) SQL2 parser must not infer type for UncastLiteral from static analysis
Date Thu, 27 Aug 2009 14:08:59 GMT

     [ https://issues.apache.org/jira/browse/JCR-2282?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Thomas Mueller updated JCR-2282:
--------------------------------

    Status: Patch Available  (was: Open)

Index: src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeNameTest.java
===================================================================
--- src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeNameTest.java	(revision 808318)
+++ src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeNameTest.java	(working copy)
@@ -144,7 +144,7 @@
         }
         try {
             String stmt = "SELECT * FROM [" + testNodeType + "] AS s " +
-                    "WHERE NAME(s) = " + literal.getString();
+                    "WHERE NAME(s) = CAST(" + literal.getString() + " AS LONG)";
             qm.createQuery(stmt, Query.JCR_SQL2).execute();
             fail("NAME() comparison with LONG must fail with InvalidQueryException");
         } catch (InvalidQueryException e) {
@@ -162,10 +162,11 @@
         }
         try {
             String stmt = "SELECT * FROM [" + testNodeType + "] AS s " +
-                    "WHERE NAME(s) = " + literal.getString();
+                    "WHERE NAME(s) = CAST(" + literal.getString() + " AS BOOLEAN)";
             qm.createQuery(stmt, Query.JCR_SQL2).execute();
             fail("NAME() comparison with BOOLEAN must fail with InvalidQueryException");
         } catch (InvalidQueryException e) {
+            e.printStackTrace();
             // expected
         }
     }


Index: src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java
===================================================================
--- src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java	(revision 808318)
+++ src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java	(working copy)
@@ -19,7 +19,6 @@
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
-
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
@@ -39,7 +38,6 @@
 import javax.jcr.query.qom.Selector;
 import javax.jcr.query.qom.Source;
 import javax.jcr.query.qom.StaticOperand;
-
 import org.apache.jackrabbit.spi.commons.query.qom.JoinType;
 import org.apache.jackrabbit.spi.commons.query.qom.Operator;
 
@@ -455,7 +453,7 @@
             }
         }
         if (currentTokenType == VALUE) {
-            Literal literal = factory.literal(currentValue);
+            Literal literal = getUncastLiteral(currentValue);
             read();
             return literal;
         } else if (currentTokenType == PARAMETER) {
@@ -471,10 +469,10 @@
             }
             return var;
         } else if (readIf("TRUE")) {
-            Literal literal = factory.literal(valueFactory.createValue(true));
+            Literal literal = getUncastLiteral(valueFactory.createValue(true));
             return literal;
         } else if (readIf("FALSE")) {
-            Literal literal = factory.literal(valueFactory.createValue(false));
+            Literal literal = getUncastLiteral(valueFactory.createValue(false));
             return literal;
         } else if (readIf("CAST")) {
             read("(");
@@ -487,6 +485,7 @@
             read("AS");
             value = parseCastAs(value);
             read(")");
+            // CastLiteral
             literal = factory.literal(value);
             return literal;
         } else {
@@ -494,6 +493,19 @@
         }
     }
 
+    /**
+     * Create uncast literal from a value. According to the JCR specification,
+     * "an UncastLiteral is always interpreted as a Value of property type STRING"
+     * (JCR 2.0 Core Specification, 6.7.34 Literal, page 124).
+     * That means the value is converted to a String first.
+     *
+     * @param value the original value
+     * @return the literal
+     */
+    private Literal getUncastLiteral(Value value) throws RepositoryException {
+        return factory.literal(valueFactory.createValue(value.getString()));
+    }
+
     private Value parseCastAs(Value value) throws RepositoryException {
         if (readIf("STRING")) {
             return valueFactory.createValue(value.getString());


> SQL2 parser must not infer type for UncastLiteral from static analysis
> ----------------------------------------------------------------------
>
>                 Key: JCR-2282
>                 URL: https://issues.apache.org/jira/browse/JCR-2282
>             Project: Jackrabbit Content Repository
>          Issue Type: Bug
>          Components: jackrabbit-jcr-tests, jackrabbit-spi-commons
>            Reporter: Marcel Reutegger
>            Priority: Minor
>
> The spec says:
> "An UncastLiteral is always interpreted as a Value of property type STRING. A CastLiteral,
on the other hand, is interpreted as the string form of a Value of the PropertyType indicated."
> There are also two test cases in NodeNameTest that need to be fixed accordingly: testLongLiteral
and testBooleanLiteral

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message