Skip to content

Commit

Permalink
JENA-1447: Merge commit 'refs/pull/328/head' of github.com:apache/jena
Browse files Browse the repository at this point in the history
This closes apache#328.
  • Loading branch information
afs committed Dec 12, 2017
2 parents eaef9eb + 2db9920 commit 057fc73
Show file tree
Hide file tree
Showing 15 changed files with 868 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Iterator ;
import org.apache.jena.atlas.io.IndentedLineBuffer ;
import org.apache.jena.atlas.iterator.Iter ;
import org.apache.jena.atlas.lib.Lib;
import org.apache.jena.graph.Graph ;
import org.apache.jena.graph.Node ;
import org.apache.jena.shared.Lock ;
Expand Down Expand Up @@ -147,6 +148,10 @@ protected static boolean isWildcard(Node g) {
return g == null || g == Node.ANY;
}

protected static void unsupportedMethod(Object object, String method) {
throw new UnsupportedOperationException(Lib.className(object)+"."+method) ;
}

@Override
public void clear() {
deleteAny(Node.ANY, Node.ANY, Node.ANY, Node.ANY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,58 @@
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.Triple;
import org.apache.jena.query.ReadWrite ;

/**
* DatasetGraph of a single graph as default graph. Fixed as one graph (the
* default) - can not add named graphs.
import org.apache.jena.query.ReadWrite;

/** DatasetGraph of a single graph as default graph.
* <p>
* Fixed as one graph (the default) - can not add named graphs.
* <p>
* Passes transactions down to a nominated backing {@link DatasetGraph}
*
*/
public class DatasetGraphOne extends DatasetGraphBaseFind {
private final Graph graph;
private final DatasetGraph backingDGS;
private final Transactional txn;
private final boolean supportsAbort;

public DatasetGraphOne(Graph graph, DatasetGraph backing) {
this.graph = graph;
backingDGS = backing;
supportsAbort = backing.supportsTransactionAbort();
txn = backing;
}

public DatasetGraphOne(Graph graph) {
this.graph = graph;
if ( graph instanceof GraphView ) {
backingDGS = ((GraphView)graph).getDataset();
txn = backingDGS;
supportsAbort = backingDGS.supportsTransactionAbort();
} else {
txn = TransactionalLock.createMRSW();
backingDGS = null;
supportsAbort = false;
}
}

public DatasetGraphOne(Graph graph, Transactional transactional) {
this.graph = graph;
backingDGS = null;
if ( transactional == null )
txn = TransactionalLock.createMRSW();
else
txn = transactional;
supportsAbort = false;
}

private final Transactional txn = TransactionalLock.createMRSW() ;
@Override public void begin(ReadWrite mode) { txn.begin(mode) ; }
@Override public void commit() { txn.commit() ; }
@Override public void abort() { txn.abort() ; }
@Override public boolean isInTransaction() { return txn.isInTransaction() ; }
@Override public void end() { txn.end(); }
@Override public boolean supportsTransactions() { return true ; }
@Override public boolean supportsTransactionAbort() { return false ; }
@Override public boolean supportsTransactionAbort() { return supportsAbort ; }

@Override
public boolean containsGraph(Node graphNode) {
Expand Down Expand Up @@ -83,46 +114,46 @@ public void add(Node g, Node s, Node p, Node o) {
if ( Quad.isDefaultGraph(g) )
graph.add(new Triple(s, p, o));
else
throw new UnsupportedOperationException("DatasetGraphOne.add/named graph");
unsupportedMethod(this, "add(named graph)");
}

@Override
public void add(Quad quad) {
if ( isDefaultGraph(quad) )
graph.add(quad.asTriple());
else
throw new UnsupportedOperationException("DatasetGraphOne.add/named graph");
unsupportedMethod(this, "add(named graph)");
}

@Override
public void delete(Node g, Node s, Node p, Node o) {
if ( Quad.isDefaultGraph(g) )
graph.delete(new Triple(s, p, o));
else
throw new UnsupportedOperationException("DatasetGraphOne.delete/named graph");
unsupportedMethod(this, "delete(named graph)");
}

@Override
public void delete(Quad quad) {
if ( isDefaultGraph(quad) )
graph.delete(quad.asTriple());
else
throw new UnsupportedOperationException("DatasetGraphOne.delete/named graph");
unsupportedMethod(this, "delete(named graph)");
}

@Override
public void setDefaultGraph(Graph g) {
throw new UnsupportedOperationException("DatasetGraphOne.setDefaultGraph");
unsupportedMethod(this, "setDefaultGraph");
}

@Override
public void addGraph(Node graphName, Graph graph) {
throw new UnsupportedOperationException("DatasetGraphOne.addGraph");
unsupportedMethod(this, "addGraph");
}

@Override
public void removeGraph(Node graphName) {
throw new UnsupportedOperationException("DatasetGraphOne.removeGraph");
unsupportedMethod(this, "removeGraph");
}

// -- Not needed -- implement find(g,s,p,o) directly.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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.core;

import java.util.Iterator;

import org.apache.jena.atlas.iterator.Iter;
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Node;
import org.apache.jena.query.ReadWrite;
import org.apache.jena.sparql.graph.GraphSink;


/**
* An always empty {@link DatasetGraph} that accepts changes but ignores them.
*
* @see DatasetGraphZero
*/
public class DatasetGraphSink extends DatasetGraphBaseFind {

public static DatasetGraph create() { return new DatasetGraphSink(); }

private Graph dftGraph = GraphSink.instance();

public DatasetGraphSink() {}

private TransactionalNull txn = TransactionalNull.create();
@Override public void begin(ReadWrite mode) { txn.begin(mode); }
@Override public void commit() { txn.commit(); }
@Override public void abort() { txn.abort(); }
@Override public boolean isInTransaction() { return txn.isInTransaction(); }
@Override public void end() { txn.end(); }
@Override public boolean supportsTransactions() { return true; }
// Because there are never any changes, abort() means "finish".
@Override public boolean supportsTransactionAbort() { return true; }

@Override
public Iterator<Node> listGraphNodes() {
return Iter.nullIterator();
}

@Override
protected Iterator<Quad> findInDftGraph(Node s, Node p, Node o) {
return Iter.nullIterator();
}

@Override
protected Iterator<Quad> findInSpecificNamedGraph(Node g, Node s, Node p, Node o) {
return Iter.nullIterator();
}

@Override
protected Iterator<Quad> findInAnyNamedGraphs(Node s, Node p, Node o) {
return Iter.nullIterator();
}

@Override
public Graph getDefaultGraph() {
return dftGraph;
}
@Override
public Graph getGraph(Node graphNode) {
return null;
}
@Override
public void add(Quad quad) { /* ignore */ }

@Override
public void delete(Quad quad) { /* ignore */ }

@Override
public void deleteAny(Node g, Node s, Node p, Node o) { /* ignore */ }

@Override
public void setDefaultGraph(Graph g) { /* ignore */ }

@Override
public void addGraph(Node graphName, Graph graph) { /* ignore */ }

@Override
public void removeGraph(Node graphName) { /* ignore */ }

@Override
public void close() {
txn.remove();
txn = null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* 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.core;

import java.util.Iterator;

import org.apache.jena.atlas.iterator.Iter;
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Node;
import org.apache.jena.query.ReadWrite;
import org.apache.jena.sparql.graph.GraphZero;

/** An always empty {@link DatasetGraph}.
* One graph (the default graph) with zero triples.
* No changes allowed - this is not a sink.
* @see DatasetGraphSink
*/
public class DatasetGraphZero extends DatasetGraphBaseFind {

public static DatasetGraph create() { return new DatasetGraphZero(); }

private Graph dftGraph = GraphZero.instance();

public DatasetGraphZero() {}

private TransactionalNull txn = TransactionalNull.create();
@Override public void begin(ReadWrite mode) { txn.begin(mode); }
@Override public void commit() { txn.commit(); }
@Override public void abort() { txn.abort(); }
@Override public boolean isInTransaction() { return txn.isInTransaction(); }
@Override public void end() { txn.end(); }
@Override public boolean supportsTransactions() { return true; }
// Because there are never any changes, abort() means "finish".
@Override public boolean supportsTransactionAbort() { return true; }

@Override
public Iterator<Node> listGraphNodes() {
return Iter.nullIterator();
}

@Override
protected Iterator<Quad> findInDftGraph(Node s, Node p, Node o) {
return Iter.nullIterator();
}

@Override
protected Iterator<Quad> findInSpecificNamedGraph(Node g, Node s, Node p, Node o) {
return Iter.nullIterator();
}

@Override
protected Iterator<Quad> findInAnyNamedGraphs(Node s, Node p, Node o) {
return Iter.nullIterator();
}

@Override
public Graph getDefaultGraph() {
return dftGraph;
}

@Override
public Graph getGraph(Node graphNode) {
return null;
}

@Override
public void add(Quad quad) { unsupportedMethod(this, "add") ; }

@Override
public void delete(Quad quad) { unsupportedMethod(this, "delete") ; }

@Override
public void deleteAny(Node g, Node s, Node p, Node o) {
throw new UnsupportedOperationException("deleteAny");
}

@Override
public void setDefaultGraph(Graph g) {
throw new UnsupportedOperationException("setDefaultGraph");
}

@Override
public void addGraph(Node graphName, Graph graph) {
throw new UnsupportedOperationException("addGraph");
}

@Override
public void removeGraph(Node graphName) {
throw new UnsupportedOperationException("removeGraph");
}
}
Loading

0 comments on commit 057fc73

Please sign in to comment.