jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1531880 - in /jackrabbit/oak/trunk/oak-jcr/src: main/java/org/apache/jackrabbit/oak/jcr/query/RowImpl.java test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
Date Mon, 14 Oct 2013 13:02:24 GMT
Author: alexparvulescu
Date: Mon Oct 14 13:02:24 2013
New Revision: 1531880

URL: http://svn.apache.org/r1531880
Log:
OAK-1093 IllegalArgumentException on Row.getValues()

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/RowImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/RowImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/RowImpl.java?rev=1531880&r1=1531879&r2=1531880&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/RowImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/RowImpl.java
Mon Oct 14 13:02:24 2013
@@ -25,6 +25,10 @@ import javax.jcr.query.Row;
 
 import org.apache.jackrabbit.oak.api.PropertyValue;
 import org.apache.jackrabbit.oak.api.ResultRow;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.spi.query.PropertyValues;
+
+import com.google.common.base.Joiner;
 
 /**
  * The implementation of the corresponding JCR interface.
@@ -96,9 +100,20 @@ public class RowImpl implements Row {
         int len = values.length;
         Value[] v2 = new Value[values.length];
         for (int i = 0; i < len; i++) {
-            v2[i] = result.createValue(values[i]);
+            if(values[i].isArray()){
+                v2[i] = result.createValue(mvpToString(values[i]));
+            }else{
+                v2[i] = result.createValue(values[i]);
+            }
         }
         return v2;
     }
 
+    private static PropertyValue mvpToString(PropertyValue pv) {
+        String v = Joiner.on(' ')
+                .appendTo(new StringBuilder(), pv.getValue(Type.STRINGS))
+                .toString();
+        return PropertyValues.newString(v);
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java?rev=1531880&r1=1531879&r2=1531880&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
Mon Oct 14 13:02:24 2013
@@ -349,4 +349,25 @@ public class QueryTest extends AbstractR
         assertEquals("", getPaths(q));
     }
 
+    /**
+     * OAK-1093
+     */
+    @Test
+    public void getValuesOnMvp() throws RepositoryException {
+        Session session = getAdminSession();
+        Node hello = session.getRootNode().addNode("hello");
+        hello.setProperty("id", "1");
+        hello.setProperty("properties", new String[] { "p1", "p2" });
+        session.save();
+
+        QueryManager qm = session.getWorkspace().getQueryManager();
+        Query q = qm.createQuery("select properties from [nt:base] where id = 1",
+                Query.JCR_SQL2);
+
+        QueryResult r = q.execute();
+        RowIterator it = r.getRows();
+        assertTrue(it.hasNext());
+        Row row = it.nextRow();
+        assertEquals("p1 p2", row.getValues()[0].getString());
+    }
 }



Mime
View raw message