clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject svn commit: r1486082 - in /clerezza/trunk/rdf.core/src: main/java/org/apache/clerezza/rdf/core/sparql/ main/java/org/apache/clerezza/rdf/core/sparql/update/ main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ main/javacc/org/apache/clerezza/rdf/...
Date Fri, 24 May 2013 14:55:18 GMT
Author: hasan
Date: Fri May 24 14:55:18 2013
New Revision: 1486082

URL: http://svn.apache.org/r1486082
Log:
CLEREZZA-761: Added support of LOAD and CLEAR in SparqlPreParser

Added:
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOperation.java
      - copied, changed from r1478807, clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleGraphUpdateOperation.java
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/LoadOperation.java
      - copied, changed from r1478807, clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleGraphUpdateOperation.java
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdateOperation.java
      - copied, changed from r1478807, clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleGraphUpdateOperation.java
Removed:
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/GraphManagementOperation.java
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/GraphUpdateOperation.java
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleGraphUpdateOperation.java
Modified:
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParser.java
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/Update.java
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/UpdateOperation.java
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdate.java
    clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj
    clerezza/trunk/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java

Modified: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParser.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParser.java?rev=1486082&r1=1486081&r2=1486082&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParser.java
(original)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParser.java
Fri May 24 14:55:18 2013
@@ -22,11 +22,13 @@ import java.io.StringReader;
 import java.util.HashSet;
 import java.util.Set;
 import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.TcManager;
 import org.apache.clerezza.rdf.core.sparql.query.DataSet;
 import org.apache.clerezza.rdf.core.sparql.query.Query;
 import org.apache.clerezza.rdf.core.sparql.query.SparqlUnit;
 import org.apache.clerezza.rdf.core.sparql.update.Update;
 import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 
 /**
@@ -39,8 +41,18 @@ import org.apache.felix.scr.annotations.
 @Service(SparqlPreParser.class)
 public class SparqlPreParser {
 
+    @Reference
+    TcManager tcManager;
+
+    public SparqlPreParser() {
+    }
+
+    public SparqlPreParser(TcManager tcManager) {
+        this.tcManager = tcManager;
+    }
+
     public Set<UriRef> getReferredGraphs(String queryString, UriRef defaultGraph) throws
ParseException {
-        Set<UriRef> referredGraphs = null;
+        Set<UriRef> referredGraphs;
         JavaCCGeneratedSparqlPreParser parser = new JavaCCGeneratedSparqlPreParser(new StringReader(queryString));
         SparqlUnit sparqlUnit;
         sparqlUnit = parser.parse();
@@ -55,7 +67,7 @@ public class SparqlPreParser {
             }
         } else {
             Update u = sparqlUnit.getUpdate();
-            referredGraphs = u.getReferredGraphs();
+            referredGraphs = u.getReferredGraphs(defaultGraph, tcManager);
         }
         if (referredGraphs.isEmpty()) {
             return null;

Modified: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/Update.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/Update.java?rev=1486082&r1=1486081&r2=1486082&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/Update.java
(original)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/Update.java
Fri May 24 14:55:18 2013
@@ -20,6 +20,7 @@ package org.apache.clerezza.rdf.core.spa
 
 import java.util.Set;
 import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.TcProvider;
 
 /**
  * <p>This interface represents a SPARQL Update.</p>
@@ -28,17 +29,23 @@ import org.apache.clerezza.rdf.core.UriR
  */
 public interface Update {
 
-	/**
-	 * 
-	 * @return
-	 *		a set of graphs referred in the {@link Update}
-	 */
-	public Set<UriRef> getReferredGraphs();
+    /**
+     * 
+     * @param defaultGraph
+     *      if default graph is referred either implicitly or explicitly in a SPARQL {@link
Update}
+     *      the specified defaultGraph should be returned in the resulting set.
+     * @param tcProvider
+     *      the specified tcProvider is used to get the named graphs referred in the SPARQL
{@link Update}.
+     * @return a set of graphs referred in the {@link Update}.
+     */
+    public Set<UriRef> getReferredGraphs(UriRef defaultGraph, TcProvider tcProvider);
+
+    public void addOperation(UpdateOperation updateOperation);
 
     /**
-	 * 
-	 * @return A valid String representation of the {@link Update}.
-	 */
-	@Override
-	public abstract String toString();
+     *
+     * @return A valid String representation of the {@link Update}.
+     */
+    @Override
+    public abstract String toString();
 }

Modified: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/UpdateOperation.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/UpdateOperation.java?rev=1486082&r1=1486081&r2=1486082&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/UpdateOperation.java
(original)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/UpdateOperation.java
Fri May 24 14:55:18 2013
@@ -18,10 +18,39 @@
  */
 package org.apache.clerezza.rdf.core.sparql.update;
 
+import java.util.Set;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.TcProvider;
+
 /**
  * SPARQL Update Operation
  *
  * @author hasan
  */
 public interface UpdateOperation {
+    public enum GraphSpec {
+        GRAPH, DEFAULT, NAMED, ALL
+    }
+
+    /**
+     * 
+     * @param defaultGraph
+     *      if default graph is referred either implicitly or explicitly as an input graph
in this operation
+     *      the specified defaultGraph should be returned in the resulting set.
+     * @param tcProvider
+     *      the specified tcProvider is used to get the named graphs referred as input graphs
in this operation.
+     * @return a set of graphs referred as input graphs in this operation.
+     */
+    public Set<UriRef> getInputGraphs(UriRef defaultGraph, TcProvider tcProvider);
+
+    /**
+     * 
+     * @param defaultGraph
+     *      if default graph is referred either implicitly or explicitly as a destination
graph in this operation
+     *      the specified defaultGraph should be returned in the resulting set.
+     * @param tcProvider
+     *      the specified tcProvider is used to get the named graphs referred as destination
graphs in this operation.
+     * @return a set of graphs referred as destination graphs in this operation.
+     */
+    public Set<UriRef> getDestinationGraphs(UriRef defaultGraph, TcProvider tcProvider);
 }

Copied: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOperation.java
(from r1478807, clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleGraphUpdateOperation.java)
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOperation.java?p2=clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOperation.java&p1=clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleGraphUpdateOperation.java&r1=1478807&r2=1486082&rev=1486082&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleGraphUpdateOperation.java
(original)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOperation.java
Fri May 24 14:55:18 2013
@@ -18,20 +18,42 @@
  */
 package org.apache.clerezza.rdf.core.sparql.update.impl;
 
-import java.util.HashSet;
 import java.util.Set;
 import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.sparql.update.GraphUpdateOperation;
+import org.apache.clerezza.rdf.core.access.TcProvider;
 
 /**
  *
  * @author hasan
  */
-public abstract class SimpleGraphUpdateOperation implements GraphUpdateOperation {
-	private Set<UriRef> graphs = new HashSet<UriRef>();
+public class ClearOperation extends SimpleUpdateOperation {
+    private boolean silent;
 
-    @Override
-    public Set<UriRef> getGraphs() {
-        return graphs;
+    public ClearOperation() {
+        this.silent = false;
+        destinationGraphSpec = GraphSpec.DEFAULT;
+    }
+
+    public void setSilent(boolean silent) {
+        this.silent = silent;
+    }
+
+    public boolean isSilent() {
+        return silent;
+    }
+
+    public void setDestinationGraph(UriRef destination) {
+        destinationGraphSpec = GraphSpec.GRAPH;
+        destinationGraphs.clear();
+        destinationGraphs.add(destination);
+    }
+
+    public UriRef getDestinationGraph(UriRef defaultGraph, TcProvider tcProvider) {
+        Set<UriRef> result = getDestinationGraphs(defaultGraph, tcProvider);
+        if (result.isEmpty()) {
+            return null;
+        } else {
+            return result.iterator().next();
+        }
     }
 }

Copied: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/LoadOperation.java
(from r1478807, clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleGraphUpdateOperation.java)
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/LoadOperation.java?p2=clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/LoadOperation.java&p1=clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleGraphUpdateOperation.java&r1=1478807&r2=1486082&rev=1486082&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleGraphUpdateOperation.java
(original)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/LoadOperation.java
Fri May 24 14:55:18 2013
@@ -18,20 +18,55 @@
  */
 package org.apache.clerezza.rdf.core.sparql.update.impl;
 
-import java.util.HashSet;
 import java.util.Set;
 import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.sparql.update.GraphUpdateOperation;
+import org.apache.clerezza.rdf.core.access.TcProvider;
 
 /**
  *
  * @author hasan
  */
-public abstract class SimpleGraphUpdateOperation implements GraphUpdateOperation {
-	private Set<UriRef> graphs = new HashSet<UriRef>();
+public class LoadOperation extends SimpleUpdateOperation {
+    private boolean silent;
 
-    @Override
-    public Set<UriRef> getGraphs() {
-        return graphs;
+    public LoadOperation() {
+        this.silent = false;
+        destinationGraphSpec = GraphSpec.DEFAULT;
+    }
+
+    public void setSilent(boolean silent) {
+        this.silent = silent;
+    }
+
+    public boolean isSilent() {
+        return silent;
+    }
+
+    public void setSource(UriRef source) {
+        inputGraphSpec = GraphSpec.GRAPH;
+        inputGraphs.clear();
+        inputGraphs.add(source);
+    }
+
+    public UriRef getSource() {
+        if (inputGraphs.isEmpty()) {
+            return null;
+        }
+        return inputGraphs.iterator().next();
+    }
+
+    public void setDestinationGraph(UriRef destination) {
+        destinationGraphSpec = GraphSpec.GRAPH;
+        destinationGraphs.clear();
+        destinationGraphs.add(destination);
+    }
+
+    public UriRef getDestinationGraph(UriRef defaultGraph, TcProvider tcProvider) {
+        Set<UriRef> result = getDestinationGraphs(defaultGraph, tcProvider);
+        if (result.isEmpty()) {
+            return null;
+        } else {
+            return result.iterator().next();
+        }
     }
 }

Modified: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdate.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdate.java?rev=1486082&r1=1486081&r2=1486082&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdate.java
(original)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdate.java
Fri May 24 14:55:18 2013
@@ -18,20 +18,34 @@
  */
 package org.apache.clerezza.rdf.core.sparql.update.impl;
 
+import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.TcProvider;
 import org.apache.clerezza.rdf.core.sparql.update.Update;
+import org.apache.clerezza.rdf.core.sparql.update.UpdateOperation;
 
 /**
  *
  * @author hasan
  */
-public abstract class SimpleUpdate implements Update {
-	private Set<UriRef> referredGraphs = new HashSet<UriRef>();
+public class SimpleUpdate implements Update {
+    protected List<UpdateOperation> operations = new ArrayList<UpdateOperation>();
 
-    void addReferredGraph(UriRef referredGraph) {
-		referredGraphs.add(referredGraph);
-	}
+    @Override
+    public Set<UriRef> getReferredGraphs(UriRef defaultGraph, TcProvider tcProvider)
{
+        Set<UriRef> referredGraphs = new HashSet<UriRef>();
+        for (UpdateOperation operation : operations) {
+            referredGraphs.addAll(operation.getInputGraphs(defaultGraph, tcProvider));
+            referredGraphs.addAll(operation.getDestinationGraphs(defaultGraph, tcProvider));
+        }
+        return referredGraphs;
+    }
 
+    @Override
+    public void addOperation(UpdateOperation updateOperation) {
+        operations.add(updateOperation);
+    }
 }

Copied: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdateOperation.java
(from r1478807, clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleGraphUpdateOperation.java)
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdateOperation.java?p2=clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdateOperation.java&p1=clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleGraphUpdateOperation.java&r1=1478807&r2=1486082&rev=1486082&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleGraphUpdateOperation.java
(original)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdateOperation.java
Fri May 24 14:55:18 2013
@@ -21,17 +21,65 @@ package org.apache.clerezza.rdf.core.spa
 import java.util.HashSet;
 import java.util.Set;
 import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.sparql.update.GraphUpdateOperation;
+import org.apache.clerezza.rdf.core.access.TcProvider;
+import org.apache.clerezza.rdf.core.sparql.update.UpdateOperation;
 
 /**
  *
  * @author hasan
  */
-public abstract class SimpleGraphUpdateOperation implements GraphUpdateOperation {
-	private Set<UriRef> graphs = new HashSet<UriRef>();
+public abstract class SimpleUpdateOperation implements UpdateOperation {
+
+    protected Set<UriRef> inputGraphs = new HashSet<UriRef>();
+    protected Set<UriRef> destinationGraphs = new HashSet<UriRef>();
+    protected GraphSpec inputGraphSpec = GraphSpec.GRAPH;
+    protected GraphSpec destinationGraphSpec = GraphSpec.GRAPH;
+
+    public void setInputGraphSpec(GraphSpec inputGraphSpec) {
+        this.inputGraphSpec = inputGraphSpec;
+    }
+
+    public GraphSpec getInputGraphSpec() {
+        return inputGraphSpec;
+    }
+
+    public void setDestinationGraphSpec(GraphSpec destinationGraphSpec) {
+        this.destinationGraphSpec = destinationGraphSpec;
+    }
+
+    public GraphSpec getDestinationGraphSpec() {
+        return destinationGraphSpec;
+    }
 
     @Override
-    public Set<UriRef> getGraphs() {
-        return graphs;
+    public Set<UriRef> getInputGraphs(UriRef defaultGraph, TcProvider tcProvider) {
+        return getGraphs(defaultGraph, tcProvider, inputGraphSpec, inputGraphs);
+    }
+
+    private Set<UriRef> getGraphs(UriRef defaultGraph, TcProvider tcProvider, GraphSpec
graphSpec, Set<UriRef> graphs) {
+        switch (graphSpec) {
+            case DEFAULT:
+                Set<UriRef> result = new HashSet<UriRef>();
+                result.add(defaultGraph);
+                return result;
+            case NAMED:
+            case ALL:
+                return tcProvider.listTripleCollections();
+            default:
+                return graphs;
+        }
+    }
+
+    @Override
+    public Set<UriRef> getDestinationGraphs(UriRef defaultGraph, TcProvider tcProvider)
{
+        return getGraphs(defaultGraph, tcProvider, destinationGraphSpec, destinationGraphs);
+    }
+
+    public void addInputGraph(UriRef graph) {
+        inputGraphs.add(graph);
+    }
+
+    public void addDestinationGraph(UriRef graph) {
+        destinationGraphs.add(graph);
     }
 }

Modified: clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj?rev=1486082&r1=1486081&r2=1486082&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj
(original)
+++ clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj
Fri May 24 14:55:18 2013
@@ -78,6 +78,11 @@ import org.apache.clerezza.rdf.core.spar
 import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleSparqlUnit;
 import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleTriplePattern;
 import org.apache.clerezza.rdf.core.sparql.update.Update;
+import org.apache.clerezza.rdf.core.sparql.update.UpdateOperation;
+import org.apache.clerezza.rdf.core.sparql.update.UpdateOperation.GraphSpec;
+import org.apache.clerezza.rdf.core.sparql.update.impl.ClearOperation;
+import org.apache.clerezza.rdf.core.sparql.update.impl.LoadOperation;
+import org.apache.clerezza.rdf.core.sparql.update.impl.SimpleUpdate;
 
 /**
  *
@@ -104,6 +109,23 @@ class JavaCCGeneratedSparqlPreParser {
     private Map<String, ResourceOrVariable> bNodes;
     private int count;
 
+    private class GraphRefAllSpec {
+        GraphSpec graphSpec;
+        UriRef graph;
+        public void setGraphSpec(GraphSpec graphSpec) {
+            this.graphSpec = graphSpec;
+        }
+        public GraphSpec getGraphSpec() {
+            return this.graphSpec;
+        }
+        public void setGraph(UriRef graph){
+            this.graph = graph;
+        }
+        public UriRef getGraph() {
+            return this.graph;
+        }
+    }
+
     void initialize() {
         base = null;
         prefixes = new HashMap<String, String>();
@@ -320,12 +342,11 @@ TOKEN [IGNORE_CASE] :
 private SparqlUnit SparqlUnit() : {
     Query query;
     Update update; } {
-    Prologue()
     (
-        query=Query() {
+        query=QueryUnit() {
         return new SimpleSparqlUnit(query); }
     |
-        update=Update() {
+        update=UpdateUnit() {
         return new SimpleSparqlUnit(update); }
     )
 }
@@ -357,11 +378,9 @@ private Query Query() : {
 }
 
 /* [3]    UpdateUnit ::= Update */
-/* [3]    UpdateUnit ::= Prologue Update */
 private Update UpdateUnit() : {
-    Update update; } {
-    Prologue()
-    update=Update() {
+    Update update = new SimpleUpdate(); } {
+    Update(update) {
     return update; }
 }
 
@@ -524,16 +543,73 @@ private UriRef SourceSelector() : {
 */
 
 /* [29]    Update ::= Prologue ( Update1 ( ';' Update )? )? */
-/* [29]    Update ::= ( Update1 ( ';' UpdateUnit )? )? */
-private Update Update() : {
-    Update update; } {
-    <LOAD> {
-    return null; }
+private void Update(Update update) : {} {
+    Prologue()
+    (
+        Update1(update)
+        (
+            ";"
+            Update(update)
+        )?
+    )?
 }
 
 /* [30]    Update1 ::= Load | Clear | Drop | Add | Move | Copy | Create | InsertData | DeleteData
| DeleteWhere | Modify */
+private void Update1(Update update) : {
+    UpdateOperation updateOperation = null; } {
+
+    (
+        updateOperation = Load()
+    |
+        updateOperation = Clear()
+    ) {
+    if (updateOperation != null) {
+        update.addOperation(updateOperation);
+    }
+    }
+}
+
 /* [31]    Load ::= 'LOAD' 'SILENT'? iri ( 'INTO' GraphRef )? */
+private UpdateOperation Load() : {
+    UriRef uriRef;
+    LoadOperation operation; } {
+    <LOAD> {
+    operation = new LoadOperation(); }
+    (
+        <SILENT> {
+        operation.setSilent(true); }
+    )?
+    uriRef = Iri() {
+        operation.setSource(uriRef);
+    }
+    (
+        <INTO>
+        uriRef = GraphRef() {
+        operation.setDestinationGraph(uriRef); }
+    )? {
+    return operation; }
+}
+
 /* [32]    Clear ::= 'CLEAR' 'SILENT'? GraphRefAll */
+private UpdateOperation Clear() : {
+    GraphRefAllSpec graphRefAllSpec;
+    GraphSpec graphSpec;
+    ClearOperation operation; } {
+    <CLEAR> {
+    operation = new ClearOperation(); }
+    (
+        <SILENT> {
+        operation.setSilent(true); }
+    )?
+    graphRefAllSpec = GraphRefAll() {
+    graphSpec = graphRefAllSpec.getGraphSpec();
+    operation.setDestinationGraphSpec(graphSpec);
+    if (graphSpec == GraphSpec.GRAPH) {
+        operation.setDestinationGraph(graphRefAllSpec.getGraph());
+    }
+    return operation; }
+}
+
 /* [33]    Drop ::= 'DROP' 'SILENT'? GraphRefAll */
 /* [34]    Create ::= 'CREATE' 'SILENT'? GraphRef */
 /* [35]    Add ::= 'ADD' 'SILENT'? GraphOrDefault 'TO' GraphOrDefault */
@@ -547,8 +623,36 @@ private Update Update() : {
 /* [43]    InsertClause ::= 'INSERT' QuadPattern */
 /* [44]    UsingClause ::= 'USING' ( iri | 'NAMED' iri ) */
 /* [45]    GraphOrDefault ::= 'DEFAULT_T' | 'GRAPH'? iri */
+
 /* [46]    GraphRef ::= 'GRAPH' iri */
+private UriRef GraphRef() : {
+    UriRef uriRef; } {
+    <GRAPH>
+    uriRef = Iri() {
+    return uriRef; }
+}
+
 /* [47]    GraphRefAll ::= GraphRef | 'DEFAULT_T' | 'NAMED' | 'ALL' */
+private GraphRefAllSpec GraphRefAll() : {
+    UriRef uriRef;
+    GraphRefAllSpec graphRefAllSpec = new GraphRefAllSpec(); } {
+    (
+        uriRef = GraphRef() {
+        graphRefAllSpec.setGraph(uriRef);
+        graphRefAllSpec.setGraphSpec(GraphSpec.GRAPH); }
+    |
+        <DEFAULT_T> {
+        graphRefAllSpec.setGraphSpec(GraphSpec.DEFAULT); }
+    |
+        <NAMED> {
+        graphRefAllSpec.setGraphSpec(GraphSpec.NAMED); }
+    |
+        <ALL> {
+        graphRefAllSpec.setGraphSpec(GraphSpec.ALL); }
+    ) {
+    return graphRefAllSpec; }
+}
+
 /* [48]    QuadPattern ::= '{' Quads '}' */
 /* [49]    QuadData ::= '{' Quads '}' */
 /* [50]    Quads ::= TriplesTemplate? ( QuadsNotTriples '.'? TriplesTemplate? )* */

Modified: clerezza/trunk/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java?rev=1486082&r1=1486081&r2=1486082&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java
(original)
+++ clerezza/trunk/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java
Fri May 24 14:55:18 2013
@@ -18,9 +18,10 @@
  */
 package org.apache.clerezza.rdf.core.sparql;
 
+import java.util.HashSet;
 import java.util.Set;
 import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.sparql.update.Update;
+import org.apache.clerezza.rdf.core.access.TcManager;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -30,20 +31,33 @@ import org.junit.Test;
  */
 public class SparqlPreParserTest {
 
+    private final static UriRef DEFAULT_GRAPH = new UriRef("http://example.org/default.graph");

+    private final static UriRef NAMED_GRAPH = new UriRef("http://example.org/dummy.graph");

+    private final static UriRef TEST_GRAPH = new UriRef("http://example.org/test.graph");

+
+    class MyTcManager extends TcManager {
+        @Override
+        public Set<UriRef> listTripleCollections() {
+            Set<UriRef> result = new HashSet<UriRef>();
+            result.add(NAMED_GRAPH);
+            return result;
+        }
+    }
+
     @Test
     public void testDefaultGraphInSelectQuery() throws ParseException {
 
         StringBuilder queryStrBuilder = new StringBuilder();
         queryStrBuilder.append(
-                "PREFIX : <http://example/>\n" +
+                "PREFIX : <http://example.org/>\n" +
                 "SELECT ?x \n" +
                 "{\n" +
                 ":order :item/:price ?x\n" +
                 "}\n");
 
-        UriRef defaultGraph = new UriRef("http://example.org/default");
-        SparqlPreParser parser = new SparqlPreParser();
-        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStrBuilder.toString(),
defaultGraph);
+        SparqlPreParser parser;
+        parser = new SparqlPreParser(TcManager.getInstance());
+        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStrBuilder.toString(),
DEFAULT_GRAPH);
         Assert.assertTrue(referredGraphs == null);
     }
 
@@ -52,16 +66,71 @@ public class SparqlPreParserTest {
 
         StringBuilder queryStrBuilder = new StringBuilder();
         queryStrBuilder.append(
-                "PREFIX : <http://example/>\n" +
+                "PREFIX : <http://example.org/>\n" +
                 "SELECT ?x (foo(2*3, ?x < ?y) AS ?f) (GROUP_CONCAT(?x ; separator=\"|\")
AS ?gc) (sum(distinct *) AS ?total)\n" +
-                "FROM <http://example.org/test>\n" +
+                "FROM " + TEST_GRAPH.toString() + "\n" +
                 "{\n" +
                 ":order :item/:price ?x\n" +
                 "}\n");
 
-        UriRef defaultGraph = new UriRef("http://example.org/default");
-        SparqlPreParser parser = new SparqlPreParser();
-        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStrBuilder.toString(),
defaultGraph);
-        Assert.assertTrue(referredGraphs.toArray()[0].equals(new UriRef("http://example.org/test")));
+        SparqlPreParser parser;
+        parser = new SparqlPreParser(TcManager.getInstance());
+        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStrBuilder.toString(),
DEFAULT_GRAPH);
+        Assert.assertTrue(referredGraphs.toArray()[0].equals(TEST_GRAPH));
+    }
+
+    @Test
+    public void testLoadingToDefaultGraph() throws ParseException {
+
+        String queryStr = "LOAD SILENT <http://example.org/mydata>";
+
+        SparqlPreParser parser;
+        parser = new SparqlPreParser(TcManager.getInstance());
+        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+        Assert.assertTrue(referredGraphs.toArray()[0].equals(DEFAULT_GRAPH));
+    }
+
+    @Test
+    public void testLoadingToGraph() throws ParseException {
+
+        String queryStr = "LOAD SILENT <http://example.org/mydata> INTO GRAPH " + TEST_GRAPH.toString();
+
+        SparqlPreParser parser;
+        parser = new SparqlPreParser(TcManager.getInstance());
+        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+        Assert.assertTrue(referredGraphs.toArray()[0].equals(TEST_GRAPH));
+    }
+
+    @Test
+    public void testClearingDefaultGraph() throws ParseException {
+
+        String queryStr = "CLEAR SILENT DEFAULT";
+
+        SparqlPreParser parser;
+        parser = new SparqlPreParser(TcManager.getInstance());
+        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+        Assert.assertTrue(referredGraphs.toArray()[0].equals(DEFAULT_GRAPH));
+    }
+
+    @Test
+    public void testClearingNamedGraph() throws ParseException {
+
+        String queryStr = "CLEAR SILENT NAMED";
+
+        SparqlPreParser parser;
+        parser = new SparqlPreParser(new MyTcManager());
+        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+        Assert.assertTrue(referredGraphs.toArray()[0].equals(NAMED_GRAPH));
+    }
+
+    @Test
+    public void testClearingGraph() throws ParseException {
+
+        String queryStr = "CLEAR SILENT GRAPH " + TEST_GRAPH.toString();
+
+        SparqlPreParser parser;
+        parser = new SparqlPreParser(TcManager.getInstance());
+        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+        Assert.assertTrue(referredGraphs.toArray()[0].equals(TEST_GRAPH));
     }
 }



Mime
View raw message