From 90698b24de18060c291a66267c509a16e90a33ac Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Tue, 30 Jan 2018 11:53:29 +0000 Subject: [PATCH 1/2] Cleanup comments and code around txn --- .../sparql/graph/TransactionHandlerNull.java | 2 +- .../jena/tdb2/store/GraphViewSwitchable.java | 5 -- .../jena/tdb/graph/TransactionHandlerTDB.java | 62 ------------------- .../apache/jena/tdb/store/GraphNonTxnTDB.java | 57 +++++++++++++---- 4 files changed, 47 insertions(+), 79 deletions(-) delete mode 100644 jena-tdb/src/main/java/org/apache/jena/tdb/graph/TransactionHandlerTDB.java diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/graph/TransactionHandlerNull.java b/jena-arq/src/main/java/org/apache/jena/sparql/graph/TransactionHandlerNull.java index 82456953db8..5a6fd887233 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/graph/TransactionHandlerNull.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/graph/TransactionHandlerNull.java @@ -22,7 +22,7 @@ import org.apache.jena.graph.impl.TransactionHandlerBase; import org.apache.jena.sparql.JenaTransactionException; -/** Implementation of {@link TransactionHandler} that does nothing but track the transction state. */ +/** Implementation of {@link TransactionHandler} that does nothing but track the transaction state. */ public class TransactionHandlerNull extends TransactionHandlerBase { private ThreadLocal inTransaction = ThreadLocal.withInitial(()->Boolean.FALSE); diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/GraphViewSwitchable.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/GraphViewSwitchable.java index deeb788c982..c82af4f5d72 100644 --- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/GraphViewSwitchable.java +++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/GraphViewSwitchable.java @@ -33,11 +33,6 @@ * A GraphView that is sensitive to {@link DatasetGraphSwitchable} switching. */ public class GraphViewSwitchable extends GraphView { - // Fixups for GraphView - // Prefixes. - // Transaction handler. - // Long term - ensure that GraphView uses get() always, inc prefixes, transaction handlers - // Factory style. public static GraphViewSwitchable createDefaultGraph(DatasetGraphSwitchable dsg) { return new GraphViewSwitchable(dsg, Quad.defaultGraphNodeGenerated) ; } diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/graph/TransactionHandlerTDB.java b/jena-tdb/src/main/java/org/apache/jena/tdb/graph/TransactionHandlerTDB.java deleted file mode 100644 index 1af7c3f8b8a..00000000000 --- a/jena-tdb/src/main/java/org/apache/jena/tdb/graph/TransactionHandlerTDB.java +++ /dev/null @@ -1,62 +0,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.tdb.graph; - -import org.apache.jena.graph.Graph ; -import org.apache.jena.graph.impl.TransactionHandlerBase ; -import org.apache.jena.tdb.TDB ; -import org.apache.jena.tdb.store.GraphTDB ; - -/** Support for when TDB is used non-transactionally. Does not support ACID transactions. - * Flushes if commit is called although it denies supporting transactions - */ - -public class TransactionHandlerTDB extends TransactionHandlerBase //implements TransactionHandler -{ - private final Graph graph ; - - public TransactionHandlerTDB(GraphTDB graph) - { - this.graph = graph ; - } - - @Override - public void abort() - { - // Not the Jena old-style transaction interface - throw new UnsupportedOperationException("TDB: 'abort' of a transaction not supported") ; - //log.warn("'Abort' of a transaction not supported - ignored") ; - } - - @Override - public void begin() - {} - - @Override - public void commit() - { - TDB.sync(graph) ; - } - - @Override - public boolean transactionsSupported() - { - return false ; - } -} diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphNonTxnTDB.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphNonTxnTDB.java index 55d06775de3..3cc35dcbb17 100644 --- a/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphNonTxnTDB.java +++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphNonTxnTDB.java @@ -16,13 +16,15 @@ * limitations under the License. */ -package org.apache.jena.tdb.store ; +package org.apache.jena.tdb.store; -import org.apache.jena.atlas.lib.Closeable ; -import org.apache.jena.atlas.lib.Sync ; -import org.apache.jena.graph.Node ; +import org.apache.jena.atlas.lib.Closeable; +import org.apache.jena.atlas.lib.Sync; +import org.apache.jena.graph.Graph; +import org.apache.jena.graph.Node; import org.apache.jena.graph.TransactionHandler; -import org.apache.jena.tdb.graph.TransactionHandlerTDB; +import org.apache.jena.graph.impl.TransactionHandlerBase; +import org.apache.jena.tdb.TDB; /** * Non-transactional version of {@link GraphTDB}. Handed out by DatasetGraphTDB when used @@ -32,25 +34,58 @@ * @see GraphTxnTDB */ public class GraphNonTxnTDB extends GraphTDB implements Closeable, Sync { - private final DatasetGraphTDB dataset ; + private final DatasetGraphTDB dataset; public GraphNonTxnTDB(DatasetGraphTDB dataset, Node graphName) { - super(dataset, graphName) ; - this.dataset = dataset ; + super(dataset, graphName); + this.dataset = dataset; } @Override public DatasetGraphTDB getDatasetGraphTDB() { - return dataset ; + return dataset; } @Override protected DatasetGraphTDB getBaseDatasetGraphTDB() { - return dataset ; + return dataset; } @Override public TransactionHandler getTransactionHandler() { - return new TransactionHandlerTDB(this) ; + return new TransactionHandlerTDB(this); + } + + // Transaction handler for non-transactional use. + // Does not support transactions, but syncs on commit which is the best it + // can do without being transactional, which is striongly preferrerd. + // For backwards compatibility only. + private static class TransactionHandlerTDB extends TransactionHandlerBase //implements TransactionHandler + { + private final Graph graph; + + public TransactionHandlerTDB(GraphTDB graph) { + this.graph = graph ; + } + + @Override + public void abort() { + // Not the Jena old-style transaction interface + throw new UnsupportedOperationException("TDB: 'abort' of a transaction not supported") ; + // log.warn("'Abort' of a transaction not supported - ignored"); + } + + @Override + public void begin() {} + + @Override + public void commit() { + TDB.sync(graph) ; + } + + @Override + public boolean transactionsSupported() { + return false ; + } } } From 81b303661dda71749696e09373e0e16e5745fcaa Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Wed, 31 Jan 2018 10:38:01 +0000 Subject: [PATCH 2/2] Remove stray comment --- .../src/main/java/org/apache/jena/tdb/store/GraphNonTxnTDB.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphNonTxnTDB.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphNonTxnTDB.java index 3cc35dcbb17..8fa33129394 100644 --- a/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphNonTxnTDB.java +++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphNonTxnTDB.java @@ -70,7 +70,6 @@ public TransactionHandlerTDB(GraphTDB graph) { @Override public void abort() { - // Not the Jena old-style transaction interface throw new UnsupportedOperationException("TDB: 'abort' of a transaction not supported") ; // log.warn("'Abort' of a transaction not supported - ignored"); }