http://git-wip-us.apache.org/repos/asf/jena/blob/3d70d735/jena-arq/src/main/java/org/apache/jena/sparql/engine/index/LinearIndex.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/index/LinearIndex.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/index/LinearIndex.java index 56267bb..c49ddaf 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/index/LinearIndex.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/index/LinearIndex.java @@ -1,112 +1,112 @@ -/** - * 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.jena.sparql.engine.index; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.jena.graph.Node ; -import org.apache.jena.sparql.algebra.Algebra ; -import org.apache.jena.sparql.core.Var ; -import org.apache.jena.sparql.engine.QueryIterator ; -import org.apache.jena.sparql.engine.binding.Binding ; -import org.apache.jena.sparql.engine.binding.BindingHashMap ; - -/** - * A slow "index" that looks for data by searching linearly through a set. - * Only used when the indexed data contains fewer bound variables than expected. - * Note that this class is only used for a MINUS operation that is removing data - * with potentially unbound values, and is therefore rarely used. - * - * TODO: If this index starts to be used more often then consider various options for - * indexing on the known bound variables. - * One possibility is for each variable (found in commonVars) to take - * the value of a var/value pair and TreeMap this to a set of Bindings that it occurs in. - * This would offer a reduced set to search, and set intersections may also work - * (intersections like this could be done on Binding reference equality rather than value). - * TreeMap is suggested here, since there would be commonVars.size() maps, which would take - * a lot of heap, particularly since performance of this class is only an issue when the - * data to search is significant. - */ - -public class LinearIndex implements IndexTable { - // Contribution from P Gearon (@quoll) - final Set<Var> commonVars ; - List<Binding> table = new ArrayList<>() ; - - public LinearIndex(Set<Var> commonVars, QueryIterator data) - { - this.commonVars = commonVars ; - while ( data.hasNext() ) - table.add(data.next()) ; - data.close() ; - } - - public LinearIndex(Set<Var> commonVars, QueryIterator data, Set<HashIndexTable.Key> loadedData, Map<Var,Integer> mappings) - { - this.commonVars = commonVars ; - for ( HashIndexTable.Key key: loadedData ) - table.add(toBinding(key, mappings)) ; - - while ( data.hasNext() ) - table.add(data.next()) ; - data.close() ; - } - - @Override - public boolean containsCompatibleWithSharedDomain(Binding bindingLeft) - { - if ( commonVars.size() == 0 ) - return false ; - - for ( Binding bindingRight: table ) - { - if ( hasCommonVars(bindingLeft, bindingRight) - && Algebra.compatible(bindingLeft, bindingRight) ) - return true ; - } - return false ; - } - - private boolean hasCommonVars(Binding left, Binding right) - { - for ( Var v: commonVars ) - { - if ( left.contains(v) && right.contains(v) ) - return true ; - } - return false; - } - - static Binding toBinding(HashIndexTable.Key key, Map<Var,Integer> mappings) - { - Node[] values = key.getNodes() ; - BindingHashMap b = new BindingHashMap() ; - for (Map.Entry<Var,Integer> mapping: mappings.entrySet()) - { - Node value = values[mapping.getValue()] ; - if ( value != null ) - b.add(mapping.getKey(), value) ; - } - return b ; - } -} - +/** + * 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.jena.sparql.engine.index; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.jena.graph.Node ; +import org.apache.jena.sparql.algebra.Algebra ; +import org.apache.jena.sparql.core.Var ; +import org.apache.jena.sparql.engine.QueryIterator ; +import org.apache.jena.sparql.engine.binding.Binding ; +import org.apache.jena.sparql.engine.binding.BindingHashMap ; + +/** + * A slow "index" that looks for data by searching linearly through a set. + * Only used when the indexed data contains fewer bound variables than expected. + * Note that this class is only used for a MINUS operation that is removing data + * with potentially unbound values, and is therefore rarely used. + * + * TODO: If this index starts to be used more often then consider various options for + * indexing on the known bound variables. + * One possibility is for each variable (found in commonVars) to take + * the value of a var/value pair and TreeMap this to a set of Bindings that it occurs in. + * This would offer a reduced set to search, and set intersections may also work + * (intersections like this could be done on Binding reference equality rather than value). + * TreeMap is suggested here, since there would be commonVars.size() maps, which would take + * a lot of heap, particularly since performance of this class is only an issue when the + * data to search is significant. + */ + +public class LinearIndex implements IndexTable { + // Contribution from P Gearon (@quoll) + final Set<Var> commonVars ; + List<Binding> table = new ArrayList<>() ; + + public LinearIndex(Set<Var> commonVars, QueryIterator data) + { + this.commonVars = commonVars ; + while ( data.hasNext() ) + table.add(data.next()) ; + data.close() ; + } + + public LinearIndex(Set<Var> commonVars, QueryIterator data, Set<HashIndexTable.Key> loadedData, Map<Var,Integer> mappings) + { + this.commonVars = commonVars ; + for ( HashIndexTable.Key key: loadedData ) + table.add(toBinding(key, mappings)) ; + + while ( data.hasNext() ) + table.add(data.next()) ; + data.close() ; + } + + @Override + public boolean containsCompatibleWithSharedDomain(Binding bindingLeft) + { + if ( commonVars.size() == 0 ) + return false ; + + for ( Binding bindingRight: table ) + { + if ( hasCommonVars(bindingLeft, bindingRight) + && Algebra.compatible(bindingLeft, bindingRight) ) + return true ; + } + return false ; + } + + private boolean hasCommonVars(Binding left, Binding right) + { + for ( Var v: commonVars ) + { + if ( left.contains(v) && right.contains(v) ) + return true ; + } + return false; + } + + static Binding toBinding(HashIndexTable.Key key, Map<Var,Integer> mappings) + { + Node[] values = key.getNodes() ; + BindingHashMap b = new BindingHashMap() ; + for (Map.Entry<Var,Integer> mapping: mappings.entrySet()) + { + Node value = values[mapping.getValue()] ; + if ( value != null ) + b.add(mapping.getKey(), value) ; + } + return b ; + } +} +
http://git-wip-us.apache.org/repos/asf/jena/blob/3d70d735/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngine.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngine.java b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngine.java index d8ef828..464f1c6 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngine.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngine.java @@ -1,43 +1,43 @@ -/* - * 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.jena.sparql.modify; - - -/** - * An UpdateEngine provides an interface to execute a SPARQL update request. - * An update engine is use-once; that is, it executes a single SPARQL Update request - * (there may be multiple operations in one request). - */ -public interface UpdateEngine -{ - /** - * Signal start of a request being executed - */ - public void startRequest(); - - /** - * Signal end of a request being executed - */ - public void finishRequest(); - - /** - * Returns an {@link UpdateSink} that accepts Update operations - */ - public UpdateSink getUpdateSink(); -} +/* + * 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.jena.sparql.modify; + + +/** + * An UpdateEngine provides an interface to execute a SPARQL update request. + * An update engine is use-once; that is, it executes a single SPARQL Update request + * (there may be multiple operations in one request). + */ +public interface UpdateEngine +{ + /** + * Signal start of a request being executed + */ + public void startRequest(); + + /** + * Signal end of a request being executed + */ + public void finishRequest(); + + /** + * Returns an {@link UpdateSink} that accepts Update operations + */ + public UpdateSink getUpdateSink(); +} http://git-wip-us.apache.org/repos/asf/jena/blob/3d70d735/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateRequestSink.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateRequestSink.java b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateRequestSink.java index 76f520e..51fbe45 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateRequestSink.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateRequestSink.java @@ -1,75 +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.jena.sparql.modify; - -import org.apache.jena.sparql.core.Prologue ; -import org.apache.jena.sparql.modify.request.QuadDataAcc ; -import org.apache.jena.sparql.modify.request.QuadDataAccSink ; -import org.apache.jena.sparql.modify.request.UpdateDataDelete ; -import org.apache.jena.sparql.modify.request.UpdateDataInsert ; -import org.apache.jena.update.Update ; -import org.apache.jena.update.UpdateRequest ; - -public class UpdateRequestSink implements UpdateSink -{ - final UpdateRequest updateRequest; - - public UpdateRequestSink(UpdateRequest updateRequest) - { - this.updateRequest = updateRequest; - } - - @Override - public void send(Update update) - { - updateRequest.add(update); - } - - @Override - public void flush() - { } - - @Override - public void close() - { } - - @Override - public Prologue getPrologue() - { - return updateRequest; - } - - @Override - public QuadDataAccSink createInsertDataSink() - { - QuadDataAcc quads = new QuadDataAcc(); - send(new UpdateDataInsert(quads)); - - return quads; - } - - @Override - public QuadDataAccSink createDeleteDataSink() - { - QuadDataAcc quads = new QuadDataAcc(); - send(new UpdateDataDelete(quads)); - - return quads; - } -} +/* + * 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.jena.sparql.modify; + +import org.apache.jena.sparql.core.Prologue ; +import org.apache.jena.sparql.modify.request.QuadDataAcc ; +import org.apache.jena.sparql.modify.request.QuadDataAccSink ; +import org.apache.jena.sparql.modify.request.UpdateDataDelete ; +import org.apache.jena.sparql.modify.request.UpdateDataInsert ; +import org.apache.jena.update.Update ; +import org.apache.jena.update.UpdateRequest ; + +public class UpdateRequestSink implements UpdateSink +{ + final UpdateRequest updateRequest; + + public UpdateRequestSink(UpdateRequest updateRequest) + { + this.updateRequest = updateRequest; + } + + @Override + public void send(Update update) + { + updateRequest.add(update); + } + + @Override + public void flush() + { } + + @Override + public void close() + { } + + @Override + public Prologue getPrologue() + { + return updateRequest; + } + + @Override + public QuadDataAccSink createInsertDataSink() + { + QuadDataAcc quads = new QuadDataAcc(); + send(new UpdateDataInsert(quads)); + + return quads; + } + + @Override + public QuadDataAccSink createDeleteDataSink() + { + QuadDataAcc quads = new QuadDataAcc(); + send(new UpdateDataDelete(quads)); + + return quads; + } +} http://git-wip-us.apache.org/repos/asf/jena/blob/3d70d735/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateSink.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateSink.java b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateSink.java index 41530b2..3a36825 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateSink.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateSink.java @@ -1,41 +1,41 @@ -/* - * 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.jena.sparql.modify; - -import org.apache.jena.atlas.lib.Sink ; -import org.apache.jena.sparql.core.Prologue ; -import org.apache.jena.sparql.modify.request.QuadDataAccSink ; -import org.apache.jena.update.Update ; - -/** - * An {@link UpdateSink} is an object usually created by a container (such as a storage engine - * or an {@link org.apache.jena.update.UpdateRequest}) that can process or store a single SPARQL Update - * request which consists of one or more SPARQL Update operations. - */ -// TODO More documentation! -public interface UpdateSink extends Sink<Update> -{ - public Prologue getPrologue(); - - // TODO make an interface for the quad sinks - public QuadDataAccSink createInsertDataSink(); - - public QuadDataAccSink createDeleteDataSink(); - +/* + * 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.jena.sparql.modify; + +import org.apache.jena.atlas.lib.Sink ; +import org.apache.jena.sparql.core.Prologue ; +import org.apache.jena.sparql.modify.request.QuadDataAccSink ; +import org.apache.jena.update.Update ; + +/** + * An {@link UpdateSink} is an object usually created by a container (such as a storage engine + * or an {@link org.apache.jena.update.UpdateRequest}) that can process or store a single SPARQL Update + * request which consists of one or more SPARQL Update operations. + */ +// TODO More documentation! +public interface UpdateSink extends Sink<Update> +{ + public Prologue getPrologue(); + + // TODO make an interface for the quad sinks + public QuadDataAccSink createInsertDataSink(); + + public QuadDataAccSink createDeleteDataSink(); + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jena/blob/3d70d735/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateVisitorSink.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateVisitorSink.java b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateVisitorSink.java index 5b1a143..24a52bd 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateVisitorSink.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateVisitorSink.java @@ -1,68 +1,68 @@ -/* - * 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.jena.sparql.modify; - -import org.apache.jena.sparql.core.Prologue ; -import org.apache.jena.sparql.modify.request.QuadDataAccSink ; -import org.apache.jena.sparql.modify.request.UpdateVisitor ; -import org.apache.jena.update.Update ; - -public class UpdateVisitorSink implements UpdateSink -{ - private final Prologue prologue; - private final UpdateVisitor worker; - - public UpdateVisitorSink(UpdateVisitor worker) - { - this.prologue = new Prologue(); - this.worker = worker; - } - - @Override - public Prologue getPrologue() - { - return prologue; - } - - @Override - public void send(Update update) - { - update.visit(worker); - } - - @Override - public QuadDataAccSink createInsertDataSink() - { - return new QuadDataAccSink(worker.createInsertDataSink()); - } - - @Override - public QuadDataAccSink createDeleteDataSink() - { - return new QuadDataAccSink(worker.createDeleteDataSink()); - } - - @Override - public void flush() - { } - - @Override - public void close() - { } -} +/* + * 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.jena.sparql.modify; + +import org.apache.jena.sparql.core.Prologue ; +import org.apache.jena.sparql.modify.request.QuadDataAccSink ; +import org.apache.jena.sparql.modify.request.UpdateVisitor ; +import org.apache.jena.update.Update ; + +public class UpdateVisitorSink implements UpdateSink +{ + private final Prologue prologue; + private final UpdateVisitor worker; + + public UpdateVisitorSink(UpdateVisitor worker) + { + this.prologue = new Prologue(); + this.worker = worker; + } + + @Override + public Prologue getPrologue() + { + return prologue; + } + + @Override + public void send(Update update) + { + update.visit(worker); + } + + @Override + public QuadDataAccSink createInsertDataSink() + { + return new QuadDataAccSink(worker.createInsertDataSink()); + } + + @Override + public QuadDataAccSink createDeleteDataSink() + { + return new QuadDataAccSink(worker.createDeleteDataSink()); + } + + @Override + public void flush() + { } + + @Override + public void close() + { } +} http://git-wip-us.apache.org/repos/asf/jena/blob/3d70d735/jena-arq/src/main/java/org/apache/jena/sparql/modify/UsingList.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UsingList.java b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UsingList.java index 05ef41d..c036685 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UsingList.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UsingList.java @@ -1,44 +1,44 @@ -/* - * 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.jena.sparql.modify; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.apache.jena.graph.Node ; - -public class UsingList -{ - public UsingList() { } - - private List<Node> using = new ArrayList<>() ; - private List<Node> usingNamed = new ArrayList<>() ; - - public void addUsing(Node node) { using.add(node) ; } - public void addAllUsing(Collection<Node> nodes) { using.addAll(nodes); } - public void addUsingNamed(Node node) { usingNamed.add(node) ; } - public void addAllUsingNamed(Collection<Node> nodes) { usingNamed.addAll(nodes); } - - public List<Node> getUsing() { return Collections.unmodifiableList(using) ; } - public List<Node> getUsingNamed() { return Collections.unmodifiableList(usingNamed) ; } - - public boolean usingIsPresent() { return using.size() > 0 || usingNamed.size() > 0 ; } -} +/* + * 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.jena.sparql.modify; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.apache.jena.graph.Node ; + +public class UsingList +{ + public UsingList() { } + + private List<Node> using = new ArrayList<>() ; + private List<Node> usingNamed = new ArrayList<>() ; + + public void addUsing(Node node) { using.add(node) ; } + public void addAllUsing(Collection<Node> nodes) { using.addAll(nodes); } + public void addUsingNamed(Node node) { usingNamed.add(node) ; } + public void addAllUsingNamed(Collection<Node> nodes) { usingNamed.addAll(nodes); } + + public List<Node> getUsing() { return Collections.unmodifiableList(using) ; } + public List<Node> getUsingNamed() { return Collections.unmodifiableList(usingNamed) ; } + + public boolean usingIsPresent() { return using.size() > 0 || usingNamed.size() > 0 ; } +} http://git-wip-us.apache.org/repos/asf/jena/blob/3d70d735/jena-arq/src/main/java/org/apache/jena/sparql/modify/UsingUpdateSink.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UsingUpdateSink.java b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UsingUpdateSink.java index 9562f1e..4e9d8c5 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UsingUpdateSink.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UsingUpdateSink.java @@ -1,93 +1,93 @@ -/* - * 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.jena.sparql.modify; - -import org.apache.jena.graph.Node ; -import org.apache.jena.sparql.core.Prologue ; -import org.apache.jena.sparql.modify.request.QuadDataAccSink ; -import org.apache.jena.sparql.modify.request.UpdateWithUsing ; -import org.apache.jena.update.Update ; -import org.apache.jena.update.UpdateException ; - -/** - * Adds using clauses from the UsingList to UpdateWithUsing operations; will throw an UpdateException if the modify operation already contains a using clause. - */ -public class UsingUpdateSink implements UpdateSink -{ - private final UpdateSink sink; - private final UsingList usingList; - - public UsingUpdateSink(UpdateSink sink, UsingList usingList) - { - this.sink = sink; - this.usingList = usingList; - } - - @Override - public void send(Update update) - { - // ---- check USING/USING NAMED/WITH not used. - // ---- update request to have USING/USING NAMED - if ( null != usingList && usingList.usingIsPresent() ) - { - if ( update instanceof UpdateWithUsing ) - { - UpdateWithUsing upu = (UpdateWithUsing)update ; - if ( upu.getUsing().size() != 0 || upu.getUsingNamed().size() != 0 || upu.getWithIRI() != null ) - throw new UpdateException("SPARQL Update: Protocol using-graph-uri or using-named-graph-uri present where update request has USING, USING NAMED or WITH") ; - for ( Node node : usingList.getUsing() ) - upu.addUsing(node) ; - for ( Node node : usingList.getUsingNamed() ) - upu.addUsingNamed(node) ; - } - } - - sink.send(update); - } - - @Override - public QuadDataAccSink createInsertDataSink() - { - return sink.createInsertDataSink(); - } - - @Override - public QuadDataAccSink createDeleteDataSink() - { - return sink.createDeleteDataSink(); - } - - @Override - public void flush() - { - sink.flush(); - } - - @Override - public void close() - { - sink.close(); - } - - @Override - public Prologue getPrologue() - { - return sink.getPrologue(); - } -} +/* + * 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.jena.sparql.modify; + +import org.apache.jena.graph.Node ; +import org.apache.jena.sparql.core.Prologue ; +import org.apache.jena.sparql.modify.request.QuadDataAccSink ; +import org.apache.jena.sparql.modify.request.UpdateWithUsing ; +import org.apache.jena.update.Update ; +import org.apache.jena.update.UpdateException ; + +/** + * Adds using clauses from the UsingList to UpdateWithUsing operations; will throw an UpdateException if the modify operation already contains a using clause. + */ +public class UsingUpdateSink implements UpdateSink +{ + private final UpdateSink sink; + private final UsingList usingList; + + public UsingUpdateSink(UpdateSink sink, UsingList usingList) + { + this.sink = sink; + this.usingList = usingList; + } + + @Override + public void send(Update update) + { + // ---- check USING/USING NAMED/WITH not used. + // ---- update request to have USING/USING NAMED + if ( null != usingList && usingList.usingIsPresent() ) + { + if ( update instanceof UpdateWithUsing ) + { + UpdateWithUsing upu = (UpdateWithUsing)update ; + if ( upu.getUsing().size() != 0 || upu.getUsingNamed().size() != 0 || upu.getWithIRI() != null ) + throw new UpdateException("SPARQL Update: Protocol using-graph-uri or using-named-graph-uri present where update request has USING, USING NAMED or WITH") ; + for ( Node node : usingList.getUsing() ) + upu.addUsing(node) ; + for ( Node node : usingList.getUsingNamed() ) + upu.addUsingNamed(node) ; + } + } + + sink.send(update); + } + + @Override + public QuadDataAccSink createInsertDataSink() + { + return sink.createInsertDataSink(); + } + + @Override + public QuadDataAccSink createDeleteDataSink() + { + return sink.createDeleteDataSink(); + } + + @Override + public void flush() + { + sink.flush(); + } + + @Override + public void close() + { + sink.close(); + } + + @Override + public Prologue getPrologue() + { + return sink.getPrologue(); + } +} http://git-wip-us.apache.org/repos/asf/jena/blob/3d70d735/jena-arq/src/main/java/org/apache/jena/sparql/modify/request/UpdateDataWriter.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/modify/request/UpdateDataWriter.java b/jena-arq/src/main/java/org/apache/jena/sparql/modify/request/UpdateDataWriter.java index 99a6119..379b5ca 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/modify/request/UpdateDataWriter.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/modify/request/UpdateDataWriter.java @@ -1,57 +1,57 @@ -/* - * 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.jena.sparql.modify.request; - -import org.apache.jena.atlas.io.IndentedWriter ; -import org.apache.jena.riot.out.SinkQuadBracedOutput ; -import org.apache.jena.sparql.serializer.SerializationContext ; - -public class UpdateDataWriter extends SinkQuadBracedOutput -{ - /** - * The mode an UpdateDataWriter is in. - */ - public enum UpdateMode - { - INSERT, - DELETE, - } - - private final UpdateMode mode; - - public UpdateDataWriter(UpdateMode mode, IndentedWriter out, SerializationContext sCxt) - { - super(out, sCxt); - this.mode = mode; - } - - public UpdateMode getMode() - { - return mode; - } - - @Override - public void open() - { - out.ensureStartOfLine(); - out.print(mode.toString()); - out.print(" DATA "); - super.open(); - } -} +/* + * 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.jena.sparql.modify.request; + +import org.apache.jena.atlas.io.IndentedWriter ; +import org.apache.jena.riot.out.SinkQuadBracedOutput ; +import org.apache.jena.sparql.serializer.SerializationContext ; + +public class UpdateDataWriter extends SinkQuadBracedOutput +{ + /** + * The mode an UpdateDataWriter is in. + */ + public enum UpdateMode + { + INSERT, + DELETE, + } + + private final UpdateMode mode; + + public UpdateDataWriter(UpdateMode mode, IndentedWriter out, SerializationContext sCxt) + { + super(out, sCxt); + this.mode = mode; + } + + public UpdateMode getMode() + { + return mode; + } + + @Override + public void open() + { + out.ensureStartOfLine(); + out.print(mode.toString()); + out.print(" DATA "); + super.open(); + } +} http://git-wip-us.apache.org/repos/asf/jena/blob/3d70d735/jena-arq/src/main/java/org/apache/jena/web/DatasetGraphAccessor.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/web/DatasetGraphAccessor.java b/jena-arq/src/main/java/org/apache/jena/web/DatasetGraphAccessor.java index 74cbf4e..c027318 100644 --- a/jena-arq/src/main/java/org/apache/jena/web/DatasetGraphAccessor.java +++ b/jena-arq/src/main/java/org/apache/jena/web/DatasetGraphAccessor.java @@ -16,32 +16,32 @@ * limitations under the License. */ -package org.apache.jena.web; - +package org.apache.jena.web; + import org.apache.jena.graph.Graph ; import org.apache.jena.graph.Node ; - -public interface DatasetGraphAccessor -{ - public Graph httpGet() ; - public Graph httpGet(Node graphName) ; - - public boolean httpHead() ; - public boolean httpHead(Node graphName) ; - - // Replace/create graph - public void httpPut(Graph data) ; - public void httpPut(Node graphName, Graph data) ; - - // Remove graph - public void httpDelete() ; - public void httpDelete(Node graphName) ; - - // Update graph - public void httpPost(Graph data) ; - public void httpPost(Node graphName, Graph data) ; - - // Update graph - public void httpPatch(Graph data) ; - public void httpPatch(Node graphName, Graph data) ; + +public interface DatasetGraphAccessor +{ + public Graph httpGet() ; + public Graph httpGet(Node graphName) ; + + public boolean httpHead() ; + public boolean httpHead(Node graphName) ; + + // Replace/create graph + public void httpPut(Graph data) ; + public void httpPut(Node graphName, Graph data) ; + + // Remove graph + public void httpDelete() ; + public void httpDelete(Node graphName) ; + + // Update graph + public void httpPost(Graph data) ; + public void httpPost(Node graphName, Graph data) ; + + // Update graph + public void httpPatch(Graph data) ; + public void httpPatch(Node graphName, Graph data) ; } http://git-wip-us.apache.org/repos/asf/jena/blob/3d70d735/jena-arq/src/main/java/org/apache/jena/web/DatasetGraphAccessorBasic.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/web/DatasetGraphAccessorBasic.java b/jena-arq/src/main/java/org/apache/jena/web/DatasetGraphAccessorBasic.java index 2acf277..ecba83e 100644 --- a/jena-arq/src/main/java/org/apache/jena/web/DatasetGraphAccessorBasic.java +++ b/jena-arq/src/main/java/org/apache/jena/web/DatasetGraphAccessorBasic.java @@ -16,39 +16,39 @@ * limitations under the License. */ -package org.apache.jena.web; - - +package org.apache.jena.web; + + import org.apache.jena.graph.Graph ; import org.apache.jena.graph.GraphUtil ; import org.apache.jena.graph.Node ; import org.apache.jena.sparql.core.DatasetGraph ; - -/** - * General implementation of operations for the SPARQL HTTP Update protocol - * over a DatasetGraph. - */ -public class DatasetGraphAccessorBasic implements DatasetGraphAccessor -{ - private DatasetGraph dataset ; - - public DatasetGraphAccessorBasic(DatasetGraph dataset) - { - this.dataset = dataset ; - } - - @Override - public Graph httpGet() { return dataset.getDefaultGraph() ; } - - @Override - public Graph httpGet(Node graphName) { return dataset.getGraph(graphName) ; } - - @Override - public boolean httpHead() { return true ; } - - @Override - public boolean httpHead(Node graphName) { return dataset.containsGraph(graphName) ; } - + +/** + * General implementation of operations for the SPARQL HTTP Update protocol + * over a DatasetGraph. + */ +public class DatasetGraphAccessorBasic implements DatasetGraphAccessor +{ + private DatasetGraph dataset ; + + public DatasetGraphAccessorBasic(DatasetGraph dataset) + { + this.dataset = dataset ; + } + + @Override + public Graph httpGet() { return dataset.getDefaultGraph() ; } + + @Override + public Graph httpGet(Node graphName) { return dataset.getGraph(graphName) ; } + + @Override + public boolean httpHead() { return true ; } + + @Override + public boolean httpHead(Node graphName) { return dataset.containsGraph(graphName) ; } + @Override public void httpPut(Graph data) { putGraph(dataset.getDefaultGraph(), data) ; @@ -91,13 +91,13 @@ public class DatasetGraphAccessorBasic implements DatasetGraphAccessor } mergeGraph(ng, data) ; } - - @Override - public void httpPatch(Graph data) { httpPost(data) ; } - - @Override - public void httpPatch(Node graphName, Graph data) { httpPost(graphName, data) ;} - + + @Override + public void httpPatch(Graph data) { httpPost(data) ; } + + @Override + public void httpPatch(Node graphName, Graph data) { httpPost(graphName, data) ;} + private void putGraph(Graph destGraph, Graph data) { clearGraph(destGraph) ; mergeGraph(destGraph, data) ; @@ -110,6 +110,6 @@ public class DatasetGraphAccessorBasic implements DatasetGraphAccessor private void mergeGraph(Graph graph, Graph data) { GraphUtil.addInto(graph, data) ; - } - + } + } http://git-wip-us.apache.org/repos/asf/jena/blob/3d70d735/jena-arq/src/test/java/org/apache/jena/query/TS_ParamString.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/test/java/org/apache/jena/query/TS_ParamString.java b/jena-arq/src/test/java/org/apache/jena/query/TS_ParamString.java index 866d066..bba2a1a 100644 --- a/jena-arq/src/test/java/org/apache/jena/query/TS_ParamString.java +++ b/jena-arq/src/test/java/org/apache/jena/query/TS_ParamString.java @@ -1,31 +1,31 @@ -/** - * 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.jena.query; - -import org.junit.runner.RunWith ; -import org.junit.runners.Suite ; - -@RunWith(Suite.class) [email protected]( { - TestParameterizedSparqlString.class -}) - -public class TS_ParamString -{ } - +/** + * 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.jena.query; + +import org.junit.runner.RunWith ; +import org.junit.runners.Suite ; + +@RunWith(Suite.class) [email protected]( { + TestParameterizedSparqlString.class +}) + +public class TS_ParamString +{ } +
