Return-Path: X-Original-To: apmail-clerezza-commits-archive@www.apache.org Delivered-To: apmail-clerezza-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8AB7910AD4 for ; Thu, 3 Oct 2013 03:59:11 +0000 (UTC) Received: (qmail 65537 invoked by uid 500); 3 Oct 2013 03:59:00 -0000 Delivered-To: apmail-clerezza-commits-archive@clerezza.apache.org Received: (qmail 65512 invoked by uid 500); 3 Oct 2013 03:58:52 -0000 Mailing-List: contact commits-help@clerezza.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@clerezza.apache.org Delivered-To: mailing list commits@clerezza.apache.org Received: (qmail 65473 invoked by uid 99); 3 Oct 2013 03:58:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Oct 2013 03:58:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Oct 2013 03:58:38 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 54D452388980; Thu, 3 Oct 2013 03:58:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1528709 - 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/ Date: Thu, 03 Oct 2013 03:58:18 -0000 To: commits@clerezza.apache.org From: hasan@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131003035818.54D452388980@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: hasan Date: Thu Oct 3 03:58:17 2013 New Revision: 1528709 URL: http://svn.apache.org/r1528709 Log: CLEREZZA-761: Fixed parsing of Quads that may contain more than one named graph, added support of DELETE WHERE update operation in SparqlPreParser, rearranged parsing of Prologue in update Added: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteWhereOperation.java clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/Quad.java Modified: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.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/update/impl/DeleteDataOperation.java URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java?rev=1528709&r1=1528708&r2=1528709&view=diff ============================================================================== --- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java (original) +++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java Thu Oct 3 03:58:17 2013 @@ -18,20 +18,9 @@ */ package org.apache.clerezza.rdf.core.sparql.update.impl; -import java.util.Set; -import org.apache.clerezza.rdf.core.sparql.query.TriplePattern; - /** * * @author hasan */ public class DeleteDataOperation extends UpdateOperationWithQuads { - - public DeleteDataOperation() { - super(null); - } - - public DeleteDataOperation(Set triplePatterns) { - super(triplePatterns); - } } Added: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteWhereOperation.java URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteWhereOperation.java?rev=1528709&view=auto ============================================================================== --- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteWhereOperation.java (added) +++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteWhereOperation.java Thu Oct 3 03:58:17 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 DeleteWhereOperation extends UpdateOperationWithQuads { +} Modified: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java?rev=1528709&r1=1528708&r2=1528709&view=diff ============================================================================== --- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java (original) +++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java Thu Oct 3 03:58:17 2013 @@ -18,20 +18,9 @@ */ package org.apache.clerezza.rdf.core.sparql.update.impl; -import java.util.Set; -import org.apache.clerezza.rdf.core.sparql.query.TriplePattern; - /** * * @author hasan */ public class InsertDataOperation extends UpdateOperationWithQuads { - - public InsertDataOperation() { - super(null); - } - - public InsertDataOperation(Set triplePatterns) { - super(triplePatterns); - } } Added: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/Quad.java URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/Quad.java?rev=1528709&view=auto ============================================================================== --- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/Quad.java (added) +++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/Quad.java Thu Oct 3 03:58:17 2013 @@ -0,0 +1,42 @@ +/* + * 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.sparql.query.TriplePattern; +import org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable; +import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleBasicGraphPattern; + +/** + * + * @author hasan + */ +public class Quad extends SimpleBasicGraphPattern { + + private UriRefOrVariable graph = null; + + public Quad(UriRefOrVariable graph, Set triplePatterns) { + super(triplePatterns); + this.graph = graph; + } + + public UriRefOrVariable getGraph() { + return this.graph; + } +} Modified: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java?rev=1528709&r1=1528708&r2=1528709&view=diff ============================================================================== --- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java (original) +++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java Thu Oct 3 03:58:17 2013 @@ -18,29 +18,42 @@ */ 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.query.TriplePattern; import org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable; -import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleBasicGraphPattern; import org.apache.clerezza.rdf.core.sparql.update.UpdateOperation; /** * * @author hasan */ -public class UpdateOperationWithQuads extends SimpleBasicGraphPattern implements UpdateOperation { +public class UpdateOperationWithQuads implements UpdateOperation { - private UriRefOrVariable destinationGraph = null; + private Quad defaultQuad = null; + private List quads = new ArrayList(); - public UpdateOperationWithQuads(Set triplePatterns) { - super(triplePatterns); + public UpdateOperationWithQuads() { } - public void setDestinationGraph(UriRefOrVariable destinationGraph) { - this.destinationGraph = destinationGraph; + public void addQuad(Set triplePatterns) { + if (defaultQuad == null) { + defaultQuad = new Quad(null, triplePatterns); + } else { + defaultQuad.addTriplePatterns(triplePatterns); + } + } + + public void addQuad(UriRefOrVariable graph, Set triplePatterns) { + if (graph == null) { + addQuad(triplePatterns); + } else { + quads.add(new Quad(graph, triplePatterns)); + } } @Override @@ -51,10 +64,14 @@ public class UpdateOperationWithQuads ex @Override public Set getDestinationGraphs(UriRef defaultGraph, TcProvider tcProvider) { Set graphs = new HashSet(); - if (destinationGraph == null) { + if (defaultQuad != null) { graphs.add(defaultGraph); - } else if (!destinationGraph.isVariable()) { - graphs.add(destinationGraph.getResource()); + } + for (Quad quad : quads) { + UriRefOrVariable graph = quad.getGraph(); + if (!graph.isVariable()) { + graphs.add(graph.getResource()); + } } return graphs; } 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=1528709&r1=1528708&r2=1528709&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 Thu Oct 3 03:58:17 2013 @@ -96,6 +96,7 @@ import org.apache.clerezza.rdf.core.spar 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.DeleteDataOperation; +import org.apache.clerezza.rdf.core.sparql.update.impl.DeleteWhereOperation; import org.apache.clerezza.rdf.core.sparql.update.impl.DropOperation; import org.apache.clerezza.rdf.core.sparql.update.impl.InsertDataOperation; import org.apache.clerezza.rdf.core.sparql.update.impl.LoadOperation; @@ -728,12 +729,13 @@ private void ValuesClause(Query query) : } /* [29] Update ::= Prologue ( Update1 ( ';' Update )? )? */ +/* [29] Update ::= ( Update1 ( ';' Prologue Update )? )? */ private void Update(Update update) : {} { - Prologue() ( Update1(update) ( ";" + Prologue() Update(update) )? )? @@ -760,7 +762,10 @@ private void Update1(Update update) : { | updateOperation = InsertData() | + LOOKAHEAD(2) updateOperation = DeleteData() + | + updateOperation = DeleteWhere() ) { if (updateOperation != null) { update.addOperation(updateOperation); @@ -905,6 +910,14 @@ private UpdateOperation DeleteData() : { } /* [40] DeleteWhere ::= 'DELETE WHERE' QuadPattern */ +private UpdateOperation DeleteWhere() : { + DeleteWhereOperation operation; } { + { + operation = new DeleteWhereOperation(); } + QuadPattern(operation) { + return operation; } +} + /* [41] Modify ::= ( 'WITH' iri )? ( DeleteClause InsertClause? | InsertClause ) UsingClause* 'WHERE' GroupGraphPattern */ /* [42] DeleteClause ::= 'DELETE' QuadPattern */ /* [43] InsertClause ::= 'INSERT' QuadPattern */ @@ -958,6 +971,12 @@ private GraphRefAllSpec GraphRefAll() : } /* [48] QuadPattern ::= '{' Quads '}' */ +private void QuadPattern(UpdateOperationWithQuads operation) : {} { + "{" + Quads(operation) + "}" +} + /* [49] QuadData ::= '{' Quads '}' */ private void QuadData(UpdateOperationWithQuads operation) : {} { "{" @@ -970,14 +989,14 @@ private void Quads(UpdateOperationWithQu Set triplePatterns; } { ( triplePatterns=TriplesTemplate() { - operation.addTriplePatterns(triplePatterns); } + operation.addQuad(triplePatterns); } )? ( QuadsNotTriples(operation) ( "." )? ( triplePatterns=TriplesTemplate() { - operation.addTriplePatterns(triplePatterns); } + operation.addQuad(triplePatterns); } )? )* } @@ -985,17 +1004,16 @@ private void Quads(UpdateOperationWithQu /* [51] QuadsNotTriples ::= 'GRAPH' VarOrIri '{' TriplesTemplate? '}' */ private void QuadsNotTriples(UpdateOperationWithQuads operation) : { UriRefOrVariable graph; - Set triplePatterns; } { + Set triplePatterns = null; } { - graph=VarOrIri() { - operation.setDestinationGraph(graph); } + graph=VarOrIri() "{" ( - triplePatterns=TriplesTemplate() { - operation.addTriplePatterns(triplePatterns); } + triplePatterns=TriplesTemplate() )? - "}" + "}" { + operation.addQuad(graph, triplePatterns); } } /* [52] TriplesTemplate ::= TriplesSameSubject ( '.' 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=1528709&r1=1528708&r2=1528709&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 Thu Oct 3 03:58:17 2013 @@ -335,4 +335,34 @@ public class SparqlPreParserTest { expected.add(TEST_GRAPH); Assert.assertTrue(referredGraphs.containsAll(expected)); } + + @Test + public void testDeleteWhereInDefaultGraph() throws ParseException { + + String queryStr = "PREFIX foaf: " + + "DELETE WHERE { ?person foaf:givenName 'Fred'; ?property ?value }"; + + SparqlPreParser parser; + parser = new SparqlPreParser(TcManager.getInstance()); + Set referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); + + Assert.assertTrue(referredGraphs.toArray()[0].equals(DEFAULT_GRAPH)); + } + + @Test + public void testDeleteWhereInNamedGraphs() throws ParseException { + + String queryStr = "PREFIX foaf: DELETE WHERE " + + "{ GRAPH { ?person foaf:givenName 'Fred' ; ?property1 ?value1 } " + + " GRAPH { ?person ?property2 ?value2 } }"; + + SparqlPreParser parser; + parser = new SparqlPreParser(TcManager.getInstance()); + Set referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); + + Set expected = new HashSet(); + expected.add(new UriRef("http://example.com/names")); + expected.add(new UriRef("http://example.com/addresses")); + Assert.assertTrue(referredGraphs.containsAll(expected)); + } }