You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by ha...@apache.org on 2013/09/14 21:26:16 UTC
svn commit: r1523298 - in /clerezza/trunk/rdf.core/src:
main/java/org/apache/clerezza/rdf/core/sparql/update/impl/
main/javacc/org/apache/clerezza/rdf/core/sparql/
test/java/org/apache/clerezza/rdf/core/sparql/
Author: hasan
Date: Sat Sep 14 19:26:16 2013
New Revision: 1523298
URL: http://svn.apache.org/r1523298
Log:
CLEREZZA-761: Added support of DROP, MOVE, ADD, COPY, and CREATE update operation in SparqlPreParser
Added:
clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/AddOperation.java
clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/BaseUpdateOperation.java
clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOrDropOperation.java
clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/CopyOperation.java
clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/CreateOperation.java
clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DropOperation.java
clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/MoveOperation.java
Modified:
clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOperation.java
clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/LoadOperation.java
clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdateOperation.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
Added: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/AddOperation.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/AddOperation.java?rev=1523298&view=auto
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/AddOperation.java (added)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/AddOperation.java Sat Sep 14 19:26:16 2013
@@ -0,0 +1,29 @@
+/*
+ * 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.clerezza.rdf.core.sparql.update.impl;
+
+/**
+ * The ADD operation is a shortcut for inserting all data from an input graph into a destination graph.
+ * Data from the input graph is not affected, and initial data from the destination graph, if any, is kept intact.
+ * @see <a href="http://www.w3.org/TR/2013/REC-sparql11-update-20130321/#add">SPARQL 1.1 Update: 3.2.5 ADD</a>
+ *
+ * @author hasan
+ */
+public class AddOperation extends SimpleUpdateOperation {
+}
Added: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/BaseUpdateOperation.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/BaseUpdateOperation.java?rev=1523298&view=auto
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/BaseUpdateOperation.java (added)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/BaseUpdateOperation.java Sat Sep 14 19:26:16 2013
@@ -0,0 +1,85 @@
+/*
+ * 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.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.access.TcProvider;
+import org.apache.clerezza.rdf.core.sparql.update.UpdateOperation;
+
+/**
+ *
+ * @author hasan
+ */
+public abstract class BaseUpdateOperation 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> 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/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOperation.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOperation.java?rev=1523298&r1=1523297&r2=1523298&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOperation.java (original)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOperation.java Sat Sep 14 19:26:16 2013
@@ -18,42 +18,9 @@
*/
package org.apache.clerezza.rdf.core.sparql.update.impl;
-import java.util.Set;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.TcProvider;
-
/**
*
* @author hasan
*/
-public class ClearOperation extends SimpleUpdateOperation {
- private boolean silent;
-
- 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();
- }
- }
+public class ClearOperation extends ClearOrDropOperation {
}
Added: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOrDropOperation.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOrDropOperation.java?rev=1523298&view=auto
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOrDropOperation.java (added)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ClearOrDropOperation.java Sat Sep 14 19:26:16 2013
@@ -0,0 +1,60 @@
+/*
+ * 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.clerezza.rdf.core.sparql.update.impl;
+
+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.UpdateOperation;
+
+/**
+ *
+ * @author hasan
+ */
+public class ClearOrDropOperation extends BaseUpdateOperation {
+ private boolean silent;
+
+ public ClearOrDropOperation() {
+ this.silent = false;
+ destinationGraphSpec = UpdateOperation.GraphSpec.DEFAULT;
+ }
+
+ public void setSilent(boolean silent) {
+ this.silent = silent;
+ }
+
+ public boolean isSilent() {
+ return silent;
+ }
+
+ public void setDestinationGraph(UriRef destination) {
+ destinationGraphSpec = UpdateOperation.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();
+ }
+ }
+}
Added: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/CopyOperation.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/CopyOperation.java?rev=1523298&view=auto
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/CopyOperation.java (added)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/CopyOperation.java Sat Sep 14 19:26:16 2013
@@ -0,0 +1,26 @@
+/*
+ * 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.clerezza.rdf.core.sparql.update.impl;
+
+/**
+ *
+ * @author hasan
+ */
+public class CopyOperation extends SimpleUpdateOperation {
+}
Added: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/CreateOperation.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/CreateOperation.java?rev=1523298&view=auto
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/CreateOperation.java (added)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/CreateOperation.java Sat Sep 14 19:26:16 2013
@@ -0,0 +1,55 @@
+/*
+ * 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.clerezza.rdf.core.sparql.update.impl;
+
+import org.apache.clerezza.rdf.core.UriRef;
+
+/**
+ *
+ * @author hasan
+ */
+public class CreateOperation extends BaseUpdateOperation {
+
+ private boolean silent;
+
+ public CreateOperation() {
+ this.silent = false;
+ }
+
+ public void setSilent(boolean silent) {
+ this.silent = silent;
+ }
+
+ public boolean isSilent() {
+ return silent;
+ }
+
+ public void setDestinationGraph(UriRef destination) {
+ destinationGraphs.clear();
+ destinationGraphs.add(destination);
+ }
+
+ public UriRef getDestinationGraph() {
+ if (destinationGraphs.isEmpty()) {
+ return null;
+ } else {
+ return destinationGraphs.iterator().next();
+ }
+ }
+}
Added: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DropOperation.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DropOperation.java?rev=1523298&view=auto
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DropOperation.java (added)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DropOperation.java Sat Sep 14 19:26:16 2013
@@ -0,0 +1,26 @@
+/*
+ * 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.clerezza.rdf.core.sparql.update.impl;
+
+/**
+ *
+ * @author hasan
+ */
+public class DropOperation extends ClearOrDropOperation {
+}
Modified: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/LoadOperation.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/LoadOperation.java?rev=1523298&r1=1523297&r2=1523298&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/LoadOperation.java (original)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/LoadOperation.java Sat Sep 14 19:26:16 2013
@@ -20,53 +20,22 @@ 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;
+import org.apache.clerezza.rdf.core.sparql.update.UpdateOperation;
/**
- *
+ * The LOAD operation reads an RDF document from a IRI and inserts its triples into the specified graph in the Graph Store.
+ * If the destination graph already exists, then no data in that graph will be removed.
+ * If no destination graph IRI is provided to load the triples into, then the data will be loaded into the default graph.
+ * @see <a href="http://www.w3.org/TR/2013/REC-sparql11-update-20130321/#load">SPARQL 1.1 Update: 3.1.4 LOAD</a>
* @author hasan
*/
public class LoadOperation extends SimpleUpdateOperation {
- private boolean silent;
-
- 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);
+ setInputGraph(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();
- }
+ return getInputGraph(null);
}
}
Added: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/MoveOperation.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/MoveOperation.java?rev=1523298&view=auto
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/MoveOperation.java (added)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/MoveOperation.java Sat Sep 14 19:26:16 2013
@@ -0,0 +1,26 @@
+/*
+ * 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.clerezza.rdf.core.sparql.update.impl;
+
+/**
+ *
+ * @author hasan
+ */
+public class MoveOperation extends SimpleUpdateOperation {
+}
Modified: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdateOperation.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdateOperation.java?rev=1523298&r1=1523297&r2=1523298&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdateOperation.java (original)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdateOperation.java Sat Sep 14 19:26:16 2013
@@ -18,68 +18,59 @@
*/
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.access.TcProvider;
import org.apache.clerezza.rdf.core.sparql.update.UpdateOperation;
/**
*
* @author hasan
*/
-public abstract class SimpleUpdateOperation implements UpdateOperation {
+public class SimpleUpdateOperation extends BaseUpdateOperation {
- protected Set<UriRef> inputGraphs = new HashSet<UriRef>();
- protected Set<UriRef> destinationGraphs = new HashSet<UriRef>();
- protected GraphSpec inputGraphSpec = GraphSpec.GRAPH;
- protected GraphSpec destinationGraphSpec = GraphSpec.GRAPH;
+ private boolean silent;
- public void setInputGraphSpec(GraphSpec inputGraphSpec) {
- this.inputGraphSpec = inputGraphSpec;
+ public SimpleUpdateOperation() {
+ this.silent = false;
+ inputGraphSpec = UpdateOperation.GraphSpec.DEFAULT;
+ destinationGraphSpec = UpdateOperation.GraphSpec.DEFAULT;
}
- public GraphSpec getInputGraphSpec() {
- return inputGraphSpec;
+ public void setSilent(boolean silent) {
+ this.silent = silent;
}
- public void setDestinationGraphSpec(GraphSpec destinationGraphSpec) {
- this.destinationGraphSpec = destinationGraphSpec;
+ public boolean isSilent() {
+ return silent;
}
- public GraphSpec getDestinationGraphSpec() {
- return destinationGraphSpec;
+ public void setInputGraph(UriRef source) {
+ inputGraphSpec = UpdateOperation.GraphSpec.GRAPH;
+ inputGraphs.clear();
+ inputGraphs.add(source);
}
- @Override
- 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;
+ public UriRef getInputGraph(UriRef defaultGraph) {
+ Set<UriRef> result = getInputGraphs(defaultGraph, null);
+ if (result.isEmpty()) {
+ return null;
+ } else {
+ return result.iterator().next();
}
}
- @Override
- public Set<UriRef> getDestinationGraphs(UriRef defaultGraph, TcProvider tcProvider) {
- return getGraphs(defaultGraph, tcProvider, destinationGraphSpec, destinationGraphs);
+ public void setDestinationGraph(UriRef destination) {
+ destinationGraphSpec = UpdateOperation.GraphSpec.GRAPH;
+ destinationGraphs.clear();
+ destinationGraphs.add(destination);
}
- public void addInputGraph(UriRef graph) {
- inputGraphs.add(graph);
- }
-
- public void addDestinationGraph(UriRef graph) {
- destinationGraphs.add(graph);
+ public UriRef getDestinationGraph(UriRef defaultGraph) {
+ Set<UriRef> result = getDestinationGraphs(defaultGraph, null);
+ if (result.isEmpty()) {
+ return null;
+ } else {
+ return result.iterator().next();
+ }
}
}
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=1523298&r1=1523297&r2=1523298&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 Sat Sep 14 19:26:16 2013
@@ -90,9 +90,16 @@ import org.apache.clerezza.rdf.core.spar
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.AddOperation;
import org.apache.clerezza.rdf.core.sparql.update.impl.ClearOperation;
+import org.apache.clerezza.rdf.core.sparql.update.impl.ClearOrDropOperation;
+import org.apache.clerezza.rdf.core.sparql.update.impl.CopyOperation;
+import org.apache.clerezza.rdf.core.sparql.update.impl.CreateOperation;
+import org.apache.clerezza.rdf.core.sparql.update.impl.DropOperation;
import org.apache.clerezza.rdf.core.sparql.update.impl.LoadOperation;
+import org.apache.clerezza.rdf.core.sparql.update.impl.MoveOperation;
import org.apache.clerezza.rdf.core.sparql.update.impl.SimpleUpdate;
+import org.apache.clerezza.rdf.core.sparql.update.impl.SimpleUpdateOperation;
/**
*
@@ -738,6 +745,16 @@ private void Update1(Update update) : {
updateOperation = Load()
|
updateOperation = Clear()
+ |
+ updateOperation = Drop()
+ |
+ updateOperation = Add()
+ |
+ updateOperation = Move()
+ |
+ updateOperation = Copy()
+ |
+ updateOperation = Create()
) {
if (updateOperation != null) {
update.addOperation(updateOperation);
@@ -766,11 +783,16 @@ private UpdateOperation Load() : {
/* [32] Clear ::= 'CLEAR' 'SILENT'? GraphRefAll */
private UpdateOperation Clear() : {
- GraphRefAllSpec graphRefAllSpec;
- GraphSpec graphSpec;
ClearOperation operation; } {
<CLEAR> {
operation = new ClearOperation(); }
+ ProcessParametersOfClearOrDropOperation(operation) {
+ return operation; }
+}
+
+private void ProcessParametersOfClearOrDropOperation(ClearOrDropOperation operation) : {
+ GraphRefAllSpec graphRefAllSpec;
+ GraphSpec graphSpec; } {
(
<SILENT> {
operation.setSilent(true); }
@@ -780,15 +802,84 @@ private UpdateOperation Clear() : {
operation.setDestinationGraphSpec(graphSpec);
if (graphSpec == GraphSpec.GRAPH) {
operation.setDestinationGraph(graphRefAllSpec.getGraph());
- }
- return operation; }
+ } }
}
/* [33] Drop ::= 'DROP' 'SILENT'? GraphRefAll */
+private UpdateOperation Drop() : {
+ DropOperation operation; } {
+ <DROP> {
+ operation = new DropOperation(); }
+ ProcessParametersOfClearOrDropOperation(operation) {
+ return operation; }
+}
+
/* [34] Create ::= 'CREATE' 'SILENT'? GraphRef */
+private UpdateOperation Create() : {
+ UriRef uriRef;
+ CreateOperation operation; } {
+ <CREATE> {
+ operation = new CreateOperation(); }
+ (
+ <SILENT> {
+ operation.setSilent(true); }
+ )?
+ uriRef = GraphRef() {
+ operation.setDestinationGraph(uriRef);
+ return operation; }
+}
+
/* [35] Add ::= 'ADD' 'SILENT'? GraphOrDefault 'TO' GraphOrDefault */
+private UpdateOperation Add() : {
+ AddOperation operation; } {
+ <ADD> {
+ operation = new AddOperation(); }
+ ProcessParametersOfAddMoveOrCopyOperation(operation) {
+ return operation; }
+}
+
+private void ProcessParametersOfAddMoveOrCopyOperation(SimpleUpdateOperation operation) : {
+ GraphRefAllSpec graphRefAllSpec;
+ GraphSpec graphSpec; } {
+ (
+ <SILENT> {
+ operation.setSilent(true); }
+ )?
+ graphRefAllSpec = GraphOrDefault() {
+ graphSpec = graphRefAllSpec.getGraphSpec();
+ if (graphSpec == GraphSpec.GRAPH) {
+ operation.setInputGraph(graphRefAllSpec.getGraph());
+ } else {
+ operation.setInputGraphSpec(graphSpec);
+ } }
+ <TO>
+ graphRefAllSpec = GraphOrDefault() {
+ graphSpec = graphRefAllSpec.getGraphSpec();
+ if (graphSpec == GraphSpec.GRAPH) {
+ operation.setDestinationGraph(graphRefAllSpec.getGraph());
+ } else {
+ operation.setDestinationGraphSpec(graphSpec);
+ } }
+}
+
/* [36] Move ::= 'MOVE' 'SILENT'? GraphOrDefault 'TO' GraphOrDefault */
+private UpdateOperation Move() : {
+ MoveOperation operation; } {
+ <MOVE> {
+ operation = new MoveOperation(); }
+ ProcessParametersOfAddMoveOrCopyOperation(operation) {
+ return operation; }
+}
+
/* [37] Copy ::= 'COPY' 'SILENT'? GraphOrDefault 'TO' GraphOrDefault */
+private UpdateOperation Copy() : {
+ CopyOperation operation; } {
+ <COPY> {
+ operation = new CopyOperation(); }
+ ProcessParametersOfAddMoveOrCopyOperation(operation) {
+ return operation; }
+}
+
/* [38] InsertData ::= 'INSERT DATA' QuadData */
/* [39] DeleteData ::= 'DELETE DATA' QuadData */
/* [40] DeleteWhere ::= 'DELETE WHERE' QuadPattern */
@@ -796,7 +887,24 @@ private UpdateOperation Clear() : {
/* [42] DeleteClause ::= 'DELETE' QuadPattern */
/* [43] InsertClause ::= 'INSERT' QuadPattern */
/* [44] UsingClause ::= 'USING' ( iri | 'NAMED' iri ) */
+
/* [45] GraphOrDefault ::= 'DEFAULT_T' | 'GRAPH'? iri */
+private GraphRefAllSpec GraphOrDefault() : {
+ UriRef uriRef;
+ GraphRefAllSpec graphRefAllSpec = new GraphRefAllSpec(); } {
+ (
+ <DEFAULT_T> {
+ graphRefAllSpec.setGraphSpec(GraphSpec.DEFAULT); }
+ |
+ (
+ <GRAPH>
+ )?
+ uriRef = Iri() {
+ graphRefAllSpec.setGraph(uriRef);
+ graphRefAllSpec.setGraphSpec(GraphSpec.GRAPH); }
+ ) {
+ return graphRefAllSpec; }
+}
/* [46] GraphRef ::= 'GRAPH' iri */
private UriRef GraphRef() : {
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=1523298&r1=1523297&r2=1523298&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 Sat Sep 14 19:26:16 2013
@@ -145,4 +145,132 @@ public class SparqlPreParserTest {
Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
Assert.assertTrue(referredGraphs.toArray()[0].equals(TEST_GRAPH));
}
+
+ @Test
+ public void testDroppingDefaultGraph() throws ParseException {
+
+ String queryStr = "DROP 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 testDroppingNamedGraph() throws ParseException {
+
+ String queryStr = "DROP 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 testDroppingGraph() throws ParseException {
+
+ String queryStr = "DROP 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));
+ }
+
+ @Test
+ public void testCreatingGraph() throws ParseException {
+
+ String queryStr = "CREATE 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));
+ }
+
+ @Test
+ public void testAddingTriplesFromDefaultGraphToNamedGraph() throws ParseException {
+
+ String queryStr = "ADD SILENT DEFAULT TO GRAPH " + TEST_GRAPH.toString();
+
+ SparqlPreParser parser;
+ parser = new SparqlPreParser(TcManager.getInstance());
+ Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+ Set<UriRef> expected = new HashSet<UriRef>();
+ expected.add(DEFAULT_GRAPH);
+ expected.add(TEST_GRAPH);
+ Assert.assertTrue(referredGraphs.containsAll(expected));
+ }
+
+ @Test
+ public void testAddingTriplesFromNamedGraphToDefaultGraph() throws ParseException {
+
+ String queryStr = "ADD SILENT GRAPH " + TEST_GRAPH.toString() + " TO DEFAULT";
+
+ SparqlPreParser parser;
+ parser = new SparqlPreParser(TcManager.getInstance());
+ Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+ Set<UriRef> expected = new HashSet<UriRef>();
+ expected.add(DEFAULT_GRAPH);
+ expected.add(TEST_GRAPH);
+ Assert.assertTrue(referredGraphs.containsAll(expected));
+ }
+
+ @Test
+ public void testMovingTriplesFromDefaultGraphToNamedGraph() throws ParseException {
+
+ String queryStr = "MOVE SILENT DEFAULT TO GRAPH " + TEST_GRAPH.toString();
+
+ SparqlPreParser parser;
+ parser = new SparqlPreParser(TcManager.getInstance());
+ Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+ Set<UriRef> expected = new HashSet<UriRef>();
+ expected.add(DEFAULT_GRAPH);
+ expected.add(TEST_GRAPH);
+ Assert.assertTrue(referredGraphs.containsAll(expected));
+ }
+
+ @Test
+ public void testMovingTriplesFromNamedGraphToDefaultGraph() throws ParseException {
+
+ String queryStr = "MOVE SILENT GRAPH " + TEST_GRAPH.toString() + " TO DEFAULT";
+
+ SparqlPreParser parser;
+ parser = new SparqlPreParser(TcManager.getInstance());
+ Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+ Set<UriRef> expected = new HashSet<UriRef>();
+ expected.add(DEFAULT_GRAPH);
+ expected.add(TEST_GRAPH);
+ Assert.assertTrue(referredGraphs.containsAll(expected));
+ }
+
+ @Test
+ public void testCopyingTriplesFromDefaultGraphToNamedGraph() throws ParseException {
+
+ String queryStr = "COPY SILENT DEFAULT TO GRAPH " + TEST_GRAPH.toString();
+
+ SparqlPreParser parser;
+ parser = new SparqlPreParser(TcManager.getInstance());
+ Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+ Set<UriRef> expected = new HashSet<UriRef>();
+ expected.add(DEFAULT_GRAPH);
+ expected.add(TEST_GRAPH);
+ Assert.assertTrue(referredGraphs.containsAll(expected));
+ }
+
+ @Test
+ public void testCopyingTriplesFromNamedGraphToDefaultGraph() throws ParseException {
+
+ String queryStr = "COPY SILENT GRAPH " + TEST_GRAPH.toString() + " TO DEFAULT";
+
+ SparqlPreParser parser;
+ parser = new SparqlPreParser(TcManager.getInstance());
+ Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+ Set<UriRef> expected = new HashSet<UriRef>();
+ expected.add(DEFAULT_GRAPH);
+ expected.add(TEST_GRAPH);
+ Assert.assertTrue(referredGraphs.containsAll(expected));
+ }
}