jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1306222 - in /jackrabbit/oak/trunk/oak-jcr/src: main/java/org/apache/jackrabbit/oak/jcr/ main/java/org/apache/jackrabbit/oak/jcr/query/ test/java/org/apache/jackrabbit/oak/jcr/ test/java/org/apache/jackrabbit/oak/jcr/query/
Date Wed, 28 Mar 2012 09:11:40 GMT
Author: thomasm
Date: Wed Mar 28 09:11:39 2012
New Revision: 1306222

URL: http://svn.apache.org/viewvc?rev=1306222&view=rev
Log:
OAK-28 Query implementation (initial implementation of the relevant oak-jcr part)

Added:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/RowImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/ValueConverter.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/WorkspaceImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java?rev=1306222&r1=1306221&r2=1306222&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
Wed Mar 28 09:11:39 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
+import org.apache.jackrabbit.oak.jcr.query.QueryManagerImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.ContentHandler;
@@ -45,6 +46,7 @@ public class WorkspaceImpl implements Wo
     private static final Logger log = LoggerFactory.getLogger(WorkspaceImpl.class);
 
     private final SessionContext<SessionImpl> sessionContext;
+    private QueryManagerImpl queryManager;
 
     public WorkspaceImpl(SessionContext<SessionImpl> sessionContext) {
         this.sessionContext = sessionContext;
@@ -113,9 +115,10 @@ public class WorkspaceImpl implements Wo
     @Override
     public QueryManager getQueryManager() throws RepositoryException {
         getSessionImpl().checkIsAlive();
-
-        // TODO
-        return null;
+        if (queryManager == null) {
+            queryManager = new QueryManagerImpl(this, sessionContext);
+        }
+        return queryManager;
     }
 
     @Override

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java?rev=1306222&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
Wed Mar 28 09:11:39 2012
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.query;
+
+import java.util.HashMap;
+import java.util.List;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class QueryImpl implements Query {
+
+    private final QueryManagerImpl manager;
+    private final HashMap<String, Value> bindVariableMap = new HashMap<String, Value>();
+    private final String language;
+    private final String statement;
+    private long limit, offset;
+    private boolean parsed;
+
+    QueryImpl(QueryManagerImpl manager, String statement, String language) {
+        this.manager = manager;
+        this.statement = statement;
+        this.language = language;
+    }
+
+    @Override
+    public void bindValue(String varName, Value value) {
+        bindVariableMap.put(varName, value);
+    }
+
+    private void parse() throws InvalidQueryException {
+        if (parsed) {
+            return;
+        }
+        List<String> names = manager.parse(statement, language);
+        for (String n : names) {
+            bindVariableMap.put(n, null);
+        }
+    }
+
+    @Override
+    public QueryResult execute() throws RepositoryException {
+        return manager.executeQuery(statement, language, bindVariableMap, limit, offset);
+    }
+
+    @Override
+    public String[] getBindVariableNames() throws RepositoryException {
+        parse();
+        String[] names = new String[bindVariableMap.size()];
+        bindVariableMap.keySet().toArray(names);
+        return names;
+    }
+
+    @Override
+    public String getLanguage() {
+        return language;
+    }
+
+    @Override
+    public String getStatement() {
+        return statement;
+    }
+
+    @Override
+    public String getStoredQueryPath() throws RepositoryException {
+        // TODO not implemented yet
+        return null;
+    }
+
+    @Override
+    public void setLimit(long limit) {
+        this.limit = limit;
+    }
+
+    @Override
+    public void setOffset(long offset) {
+        this.offset = offset;
+    }
+
+    @Override
+    public Node storeAsNode(String absPath) throws RepositoryException {
+        // TODO not implemented yet
+        return null;
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java?rev=1306222&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
Wed Mar 28 09:11:39 2012
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.query;
+
+import java.text.ParseException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map.Entry;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.qom.QueryObjectModelFactory;
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.oak.jcr.SessionContext;
+import org.apache.jackrabbit.oak.jcr.SessionImpl;
+import org.apache.jackrabbit.oak.jcr.WorkspaceImpl;
+import org.apache.jackrabbit.oak.jcr.query.qom.QueryObjectModelFactoryImpl;
+import org.apache.jackrabbit.oak.query.CoreValue;
+import org.apache.jackrabbit.oak.query.QueryEngine;
+import org.apache.jackrabbit.oak.query.Result;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class QueryManagerImpl implements QueryManager {
+
+    private final QueryObjectModelFactoryImpl qomFactory = new QueryObjectModelFactoryImpl();
+    private final QueryEngine qe;
+
+    public QueryManagerImpl(WorkspaceImpl workspace, SessionContext<SessionImpl> sessionContext)
{
+        MicroKernel mk = sessionContext.getGlobalContext().getInstance(MicroKernel.class);
+        qe = new QueryEngine(mk);
+    }
+
+    @Override
+    public Query createQuery(String statement, String language) throws RepositoryException
{
+        return new QueryImpl(this, statement, language);
+    }
+
+    @Override
+    public QueryObjectModelFactory getQOMFactory() {
+        return qomFactory;
+    }
+
+    @Override
+    public Query getQuery(Node node) throws RepositoryException {
+        // TODO getQuery(Node node): is it needed?
+        throw new RepositoryException("Feature not implemented");
+    }
+
+    @Override
+    public String[] getSupportedQueryLanguages() throws RepositoryException {
+        @SuppressWarnings("deprecation")
+        // create a new instance each time because the array is mutable
+        // (the caller could modify it)
+        String[] s = {
+            Query.JCR_JQOM,
+            Query.JCR_SQL2,
+            Query.XPATH
+        };
+        return s;
+    }
+
+    public List<String> parse(String statement, String language) throws InvalidQueryException
{
+        try {
+            return qe.parse(statement, convertLanguage(language));
+        } catch (ParseException e) {
+            throw new InvalidQueryException(e);
+        }
+    }
+
+    public QueryResult executeQuery(String statement, String language,
+            HashMap<String, Value> bindVariableMap, long limit, long offset) throws
RepositoryException {
+        try {
+            HashMap<String, CoreValue> bindMap = convertMap(bindVariableMap);
+            Result r = qe.executeQuery(statement, convertLanguage(language), bindMap);
+            return new QueryResultImpl(r);
+        } catch (ParseException e) {
+            throw new InvalidQueryException(e);
+        }
+    }
+
+    @SuppressWarnings("deprecation")
+    private static String convertLanguage(String jcrLanguage) throws InvalidQueryException
{
+        if (jcrLanguage.equals(Query.JCR_SQL2)) {
+            return QueryEngine.SQL2;
+        } else if (jcrLanguage.equals(Query.XPATH)) {
+            return QueryEngine.XPATH;
+        } else {
+            throw new InvalidQueryException("Unsupported language: " + jcrLanguage);
+        }
+    }
+
+    private HashMap<String, CoreValue> convertMap(HashMap<String, Value> bindVariableMap)
throws RepositoryException {
+        HashMap<String, CoreValue> map = new HashMap<String, CoreValue>();
+        for (Entry<String, Value> e : bindVariableMap.entrySet()) {
+            map.put(e.getKey(), ValueConverter.convert(e.getValue()));
+        }
+        return map;
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java?rev=1306222&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java
Wed Mar 28 09:11:39 2012
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.query;
+
+import java.util.Iterator;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.RowIterator;
+import org.apache.jackrabbit.commons.iterator.RowIteratorAdapter;
+import org.apache.jackrabbit.oak.query.Result;
+import org.apache.jackrabbit.oak.query.ResultRow;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class QueryResultImpl implements QueryResult {
+
+    final Result result;
+
+    public QueryResultImpl(Result result) {
+        this.result = result;
+    }
+
+    @Override
+    public String[] getColumnNames() throws RepositoryException {
+        return result.getColumnNames();
+    }
+
+    @Override
+    public String[] getSelectorNames() throws RepositoryException {
+        return result.getSelectorNames();
+    }
+
+    @Override
+    public RowIterator getRows() throws RepositoryException {
+        Iterator<RowImpl> it = new Iterator<RowImpl>() {
+
+            private Iterator<ResultRow> it = result.getRows();
+
+            @Override
+            public boolean hasNext() {
+                return it.hasNext();
+            }
+
+            @Override
+            public RowImpl next() {
+                return new RowImpl(it.next());
+            }
+
+            @Override
+            public void remove() {
+                it.remove();
+            }
+
+        };
+        return new RowIteratorAdapter(it);
+    }
+
+    @Override
+    public NodeIterator getNodes() throws RepositoryException {
+        return null;
+    }
+
+}

Added: 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=1306222&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/RowImpl.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/RowImpl.java
Wed Mar 28 09:11:39 2012
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.query;
+
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.query.Row;
+import org.apache.jackrabbit.oak.query.CoreValue;
+import org.apache.jackrabbit.oak.query.ResultRow;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class RowImpl implements Row {
+
+    private final ResultRow row;
+
+    public RowImpl(ResultRow row) {
+        this.row = row;
+    }
+
+    public Node getNode() throws RepositoryException {
+        // TODO row node
+        return null;
+    }
+
+    public Node getNode(String selectorName) throws RepositoryException {
+        // TODO row node
+        return null;
+    }
+
+    public String getPath() throws RepositoryException {
+        return row.getPath();
+    }
+
+    public String getPath(String selectorName) throws RepositoryException {
+        return row.getPath(selectorName);
+    }
+
+    public double getScore() throws RepositoryException {
+        // TODO row score
+        return 0;
+    }
+
+    public double getScore(String selectorName) throws RepositoryException {
+        // TODO row score
+        return 0;
+    }
+
+    public Value getValue(String columnName) throws ItemNotFoundException, RepositoryException
{
+        return ValueConverter.convert(row.getValue(columnName));
+    }
+
+    public Value[] getValues() throws RepositoryException {
+        CoreValue[] values = row.getValues();
+        int len = values.length;
+        Value[] v2 = new Value[values.length];
+        for (int i = 0; i < len; i++) {
+            v2[i] = ValueConverter.convert(values[i]);
+        }
+        return v2;
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/ValueConverter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/ValueConverter.java?rev=1306222&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/ValueConverter.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/ValueConverter.java
Wed Mar 28 09:11:39 2012
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.query;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.ValueFormatException;
+import org.apache.jackrabbit.commons.SimpleValueFactory;
+import org.apache.jackrabbit.oak.query.CoreValue;
+import org.apache.jackrabbit.oak.query.CoreValueFactory;
+
+/**
+ * Convert values to the jcr-core flavor.
+ */
+public class ValueConverter {
+
+    private static final CoreValueFactory coreValueFactory = new CoreValueFactory();
+    private static final ValueFactory jcrValueFactory = new SimpleValueFactory();
+
+    public static CoreValue convert(Value v) throws RepositoryException {
+        switch (v.getType()) {
+        case PropertyType.BINARY:
+            // TODO convert binary to data store entry
+            throw new UnsupportedOperationException();
+        case PropertyType.BOOLEAN:
+            return coreValueFactory.createValue(v.getBoolean());
+        case PropertyType.DATE:
+            // TODO convert date
+            throw new UnsupportedOperationException();
+        case PropertyType.DECIMAL:
+            return coreValueFactory.createValue(v.getDecimal());
+        case PropertyType.DOUBLE:
+            return coreValueFactory.createValue(v.getDouble());
+        case PropertyType.LONG:
+            return coreValueFactory.createValue(v.getLong());
+        case PropertyType.NAME:
+            // TODO possibly do name space mapping here
+            return coreValueFactory.createValue(v.getString(), CoreValue.NAME);
+        case PropertyType.PATH:
+            // TODO possibly do name space mapping here
+            return coreValueFactory.createValue(v.getString(), CoreValue.PATH);
+        case PropertyType.REFERENCE:
+            // TODO possibly do name space mapping here
+            return coreValueFactory.createValue(v.getString(), CoreValue.REFERENCE);
+        case PropertyType.STRING:
+            return coreValueFactory.createValue(v.getString());
+        default:
+            throw new IllegalArgumentException("Unsupported property type " + v.getType());
+        }
+    }
+
+    public static Value convert(CoreValue v) throws ValueFormatException {
+        switch (v.getType()) {
+        case CoreValue.BINARY:
+            // TODO convert binary to data store entry
+            throw new UnsupportedOperationException();
+        case CoreValue.BOOLEAN:
+            return jcrValueFactory.createValue(v.getBoolean());
+        case CoreValue.DATE:
+            // TODO convert date
+            throw new UnsupportedOperationException();
+        case CoreValue.DECIMAL:
+            return jcrValueFactory.createValue(v.getDecimal());
+        case CoreValue.DOUBLE:
+            return jcrValueFactory.createValue(v.getDouble());
+        case CoreValue.LONG:
+            return jcrValueFactory.createValue(v.getLong());
+        case CoreValue.NAME:
+            // TODO possibly do name space mapping here
+            return jcrValueFactory.createValue(v.getString(), CoreValue.NAME);
+        case CoreValue.PATH:
+            // TODO possibly do name space mapping here
+            return jcrValueFactory.createValue(v.getString(), CoreValue.PATH);
+        case CoreValue.REFERENCE:
+            // TODO possibly do name space mapping here
+            return jcrValueFactory.createValue(v.getString(), CoreValue.REFERENCE);
+        case CoreValue.STRING:
+            return jcrValueFactory.createValue(v.getString());
+        default:
+            throw new IllegalArgumentException("Unsupported property type " + v.getType());
+        }
+    }
+
+}

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java?rev=1306222&r1=1306221&r2=1306222&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
Wed Mar 28 09:11:39 2012
@@ -17,10 +17,10 @@ import javax.jcr.Session;
  * Users of this class must call clear to close the session associated with
  * this instance and clean up the repository when done.
  */
-abstract class AbstractRepositoryTest {
+public abstract class AbstractRepositoryTest {
     private Repository repository;
     private Session session;
-    
+
     public void logout() throws RepositoryException {
         Session session = getRepository().login();
         try {

Added: 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=1306222&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
Wed Mar 28 09:11:39 2012
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.query;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.ValueFactory;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.Row;
+import javax.jcr.query.RowIterator;
+import org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest;
+import org.junit.After;
+import org.junit.Test;
+
+/**
+ * Tests the query feature.
+ */
+public class QueryTest extends AbstractRepositoryTest {
+
+    @After
+    public void tearDown() throws RepositoryException {
+        logout();
+    }
+
+    @Test
+    public void simple() throws RepositoryException {
+        Repository repository = getRepository();
+        Session session = repository.login();
+        try {
+            Node hello = session.getRootNode().addNode("hello");
+            hello.setProperty("id",  "1");
+            hello.setProperty("text",  "hello world");
+            session.save();
+
+            ValueFactory vf = session.getValueFactory();
+
+            QueryManager qm = session.getWorkspace().getQueryManager();
+            Query q = qm.createQuery("select text from [nt:base] where id = $id", Query.JCR_SQL2);
+            q.bindValue("id", vf.createValue("1"));
+            QueryResult r = q.execute();
+            RowIterator it = r.getRows();
+            assertTrue(it.hasNext());
+            Row row = it.nextRow();
+            assertEquals("hello world", row.getValue("text").getString());
+            assertFalse(it.hasNext());
+
+        } finally {
+            session.logout();
+        }
+    }
+
+}



Mime
View raw message