You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2024/11/10 11:59:05 UTC
(jena) branch main updated (2fe30ed9b5 -> 30a2d21d91)
This is an automated email from the ASF dual-hosted git repository.
andy pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
from 2fe30ed9b5 Javadoc fixes
new 0f33b3fe8b Reformat in jena-text
new 24a767551f SPARQL_QueryGeneral: Convert dataset description handling to work on graphs
new 922372d72e ActionPrefixes: Use HttpAction.endWrite. Call HttpAction.endRead once
new dbc0a6061f GH-2755: DatasetGraphText call operations in correct order
new 47b1a574a0 GH-2755: Refactor to make finalization clearer
new 30a2d21d91 Explicit abort on query read exceptions
The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../jena/fuseki/servlets/ActionPrefixesR.java | 1 -
.../jena/fuseki/servlets/ActionPrefixesRW.java | 4 +-
.../apache/jena/fuseki/servlets/HttpAction.java | 94 +++++----
.../jena/fuseki/servlets/SPARQLQueryProcessor.java | 6 +
.../jena/fuseki/servlets/SPARQL_QueryGeneral.java | 116 +++++------
.../apache/jena/fuseki/system/GraphLoadUtils.java | 15 --
.../apache/jena/query/text/DatasetGraphText.java | 188 +++++++++--------
.../text/changes/DatasetGraphTextMonitor.java | 223 ++++++++++-----------
8 files changed, 331 insertions(+), 316 deletions(-)
(jena) 01/06: Reformat in jena-text
Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
commit 0f33b3fe8b8c13b28c0f5634c63ec27d13f4353b
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Wed Nov 6 21:51:13 2024 +0000
Reformat in jena-text
---
.../apache/jena/query/text/DatasetGraphText.java | 174 ++++++++--------
.../text/changes/DatasetGraphTextMonitor.java | 223 ++++++++++-----------
2 files changed, 202 insertions(+), 195 deletions(-)
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java b/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java
index 3363226e37..8a6276ff4e 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java
@@ -16,58 +16,58 @@
* limitations under the License.
*/
-package org.apache.jena.query.text ;
+package org.apache.jena.query.text;
-import java.util.Iterator ;
-import java.util.List ;
+import java.util.Iterator;
+import java.util.List;
import org.apache.jena.dboe.transaction.txn.ComponentId;
import org.apache.jena.dboe.transaction.txn.TransactionCoordinator;
import org.apache.jena.dboe.transaction.txn.TransactionalComponent;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.graph.Graph;
+import org.apache.jena.graph.Node;
+import org.apache.jena.query.ReadWrite;
import org.apache.jena.query.TxnType;
import org.apache.jena.query.text.changes.DatasetGraphTextMonitor;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.core.GraphView;
import org.apache.jena.sparql.core.Transactional;
import org.apache.jena.tdb1.transaction.TransactionManager;
-import org.apache.lucene.queryparser.classic.QueryParserBase ;
-import org.slf4j.Logger ;
-import org.slf4j.LoggerFactory ;
-
-public class DatasetGraphText extends DatasetGraphTextMonitor implements Transactional
-{
- private static Logger log = LoggerFactory.getLogger(DatasetGraphText.class) ;
- private final TextIndex textIndex ;
- private final Graph dftGraph ;
- private final boolean closeIndexOnClose;
- // Lock needed for commit/abort that perform an index operation and a dataset operation
- // when the underlying datsetGraph does not coordinate the commit.
- private final Object txnExitLock = new Object();
-
- // If we are going to implement Transactional, then we are going to have to do as DatasetGraphWithLock and
- // TDB's DatasetGraphTransaction do and track transaction state in a ThreadLocal
+import org.apache.lucene.queryparser.classic.QueryParserBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DatasetGraphText extends DatasetGraphTextMonitor implements Transactional {
+ private static Logger log = LoggerFactory.getLogger(DatasetGraphText.class);
+ private final TextIndex textIndex;
+ private final Graph dftGraph;
+ private final boolean closeIndexOnClose;
+ // Lock needed for commit/abort that perform an index operation and a dataset
+ // operation when the underlying datsetGraph does not coordinate the commit.
+ private final Object txnExitLock = new Object();
+
+ // If we are going to implement Transactional, and not delegate to a completely
+ // transaction dataset graph (e.g. TDB) then we are going to have to do as
+ // DatasetGraphWithLock.
private final ThreadLocal<ReadWrite> readWriteMode = new ThreadLocal<>();
- private Runnable delegateCommit = ()-> {
+ private Runnable delegateCommit = () -> {
super.commit();
};
- private Runnable delegateAbort = ()-> {
+ private Runnable delegateAbort = () -> {
super.abort();
};
- private Runnable nonDelegatedCommit = ()-> {
- if (readWriteMode.get() == ReadWrite.WRITE)
+ private Runnable nonDelegatedCommit = () -> {
+ if ( readWriteMode.get() == ReadWrite.WRITE )
commit_W();
else
commit_R();
};
- private Runnable nonDelegatedAbort = ()-> {
- if (readWriteMode.get() == ReadWrite.WRITE)
+ private Runnable nonDelegatedAbort = () -> {
+ if ( readWriteMode.get() == ReadWrite.WRITE )
abort_W();
else
abort_R();
@@ -81,9 +81,9 @@ public class DatasetGraphText extends DatasetGraphTextMonitor implements Transac
}
public DatasetGraphText(DatasetGraph dsg, TextIndex index, TextDocProducer producer, boolean closeIndexOnClose) {
- super(dsg, producer) ;
- this.textIndex = index ;
- dftGraph = GraphView.createDefaultGraph(this) ;
+ super(dsg, producer);
+ this.textIndex = index;
+ dftGraph = GraphView.createDefaultGraph(this);
this.closeIndexOnClose = closeIndexOnClose;
if ( org.apache.jena.tdb1.sys.TDBInternal.isTDB1(dsg) ) {
@@ -92,11 +92,10 @@ public class DatasetGraphText extends DatasetGraphTextMonitor implements Transac
commitAction = delegateCommit;
abortAction = delegateAbort;
} else if ( org.apache.jena.tdb2.sys.TDBInternal.isTDB2(dsg) ) {
- // This moves!
TransactionCoordinator coord = org.apache.jena.tdb2.sys.TDBInternal.getTransactionCoordinator(dsg);
- byte[] componentID = { 2, 4, 6, 10 };
+ byte[] componentID = {2, 4, 6, 10};
TransactionalComponent tc = new TextIndexDB(ComponentId.create(null, componentID), textIndex);
- coord.modifyConfig(()->coord.addExternal(tc));
+ coord.modifyConfig(() -> coord.addExternal(tc));
commitAction = delegateCommit;
abortAction = delegateAbort;
} else {
@@ -108,58 +107,61 @@ public class DatasetGraphText extends DatasetGraphTextMonitor implements Transac
// ---- Intercept these and force the use of views.
@Override
public Graph getDefaultGraph() {
- return dftGraph ;
+ return dftGraph;
}
@Override
public Graph getGraph(Node graphNode) {
- return GraphView.createNamedGraph(this, graphNode) ;
+ return GraphView.createNamedGraph(this, graphNode);
}
// ----
public TextIndex getTextIndex() {
- return textIndex ;
+ return textIndex;
}
/** Search the text index on the default text field */
public Iterator<TextHit> search(String queryString) {
- return search(queryString, null) ;
+ return search(queryString, null);
}
/** Search the text index on the text field associated with the predicate */
public Iterator<TextHit> search(String queryString, Node predicate) {
- return search(queryString, predicate, -1) ;
+ return search(queryString, predicate, -1);
}
/** Search the text index on the default text field */
public Iterator<TextHit> search(String queryString, int limit) {
- return search(queryString, null, limit) ;
+ return search(queryString, null, limit);
}
/** Search the text index on the text field associated with the predicate */
public Iterator<TextHit> search(String queryString, Node predicate, int limit) {
- return search(queryString, predicate, null, null, limit) ;
+ return search(queryString, predicate, null, null, limit);
}
- /** Search the text index on the text field associated with the predicate within graph */
+ /**
+ * Search the text index on the text field associated with the predicate within
+ * graph
+ */
public Iterator<TextHit> search(String queryString, Node predicate, String graphURI, String lang, int limit) {
- queryString = QueryParserBase.escape(queryString) ;
+ queryString = QueryParserBase.escape(queryString);
if ( predicate != null ) {
- String f = textIndex.getDocDef().getField(predicate) ;
- queryString = f + ":" + queryString ;
+ String f = textIndex.getDocDef().getField(predicate);
+ queryString = f + ":" + queryString;
}
- List<TextHit> results = textIndex.query(predicate, queryString, graphURI, lang, limit) ;
- return results.iterator() ;
+ List<TextHit> results = textIndex.query(predicate, queryString, graphURI, lang, limit);
+ return results.iterator();
}
@Override
public void begin(TxnType txnType) {
- switch(txnType) {
- case READ_PROMOTE:
- case READ_COMMITTED_PROMOTE:
- throw new UnsupportedOperationException("begin("+txnType+")");
- default:
+ switch (txnType) {
+ case READ_PROMOTE :
+ case READ_COMMITTED_PROMOTE :
+ throw new UnsupportedOperationException("begin(" + txnType + ")");
+ default :
}
begin(TxnType.convert(txnType));
}
@@ -167,13 +169,13 @@ public class DatasetGraphText extends DatasetGraphTextMonitor implements Transac
@Override
public void begin(ReadWrite readWrite) {
readWriteMode.set(readWrite);
- super.begin(readWrite) ;
- super.getMonitor().start() ;
+ super.begin(readWrite);
+ super.getMonitor().start();
}
@Override
public void commit() {
- super.getMonitor().finish() ;
+ super.getMonitor().finish();
commitAction.run();
readWriteMode.set(null);
}
@@ -183,7 +185,7 @@ public class DatasetGraphText extends DatasetGraphTextMonitor implements Transac
*/
@Override
public void abort() {
- super.getMonitor().finish() ;
+ super.getMonitor().finish();
abortAction.run();
readWriteMode.set(null);
}
@@ -194,12 +196,13 @@ public class DatasetGraphText extends DatasetGraphTextMonitor implements Transac
}
private void commit_W() {
- synchronized(txnExitLock) {
- super.getMonitor().finish() ;
+ synchronized (txnExitLock) {
+ super.getMonitor().finish();
// Phase 1
- try { textIndex.prepareCommit(); }
- catch (Throwable t) {
- log.error("Exception in prepareCommit: " + t.getMessage(), t) ;
+ try {
+ textIndex.prepareCommit();
+ } catch (Throwable t) {
+ log.error("Exception in prepareCommit: " + t.getMessage(), t);
abort();
throw new TextIndexException(t);
}
@@ -209,9 +212,8 @@ public class DatasetGraphText extends DatasetGraphTextMonitor implements Transac
// Hard to do atomically.
super.commit();
textIndex.commit();
- }
- catch (Throwable t) {
- log.error("Exception in commit: " + t.getMessage(), t) ;
+ } catch (Throwable t) {
+ log.error("Exception in commit: " + t.getMessage(), t);
abort();
throw new TextIndexException(t);
}
@@ -219,15 +221,26 @@ public class DatasetGraphText extends DatasetGraphTextMonitor implements Transac
}
private void abort_R() {
- try { super.abort() ; }
- catch (Throwable t) { log.warn("Exception in abort: " + t.getMessage(), t); }
+ try {
+ super.abort();
+ } catch (Throwable t) {
+ log.warn("Exception in abort: " + t.getMessage(), t);
+ }
}
private void abort_W() {
- synchronized(txnExitLock) {
+ synchronized (txnExitLock) {
// Roll back on both objects, discarding any exceptions that occur
- try { super.abort(); } catch (Throwable t) { log.warn("Exception in abort: " + t.getMessage(), t); }
- try { textIndex.rollback(); } catch (Throwable t) { log.warn("Exception in abort: " + t.getMessage(), t); }
+ try {
+ super.abort();
+ } catch (Throwable t) {
+ log.warn("Exception in abort: " + t.getMessage(), t);
+ }
+ try {
+ textIndex.rollback();
+ } catch (Throwable t) {
+ log.warn("Exception in abort: " + t.getMessage(), t);
+ }
}
}
@@ -238,37 +251,38 @@ public class DatasetGraphText extends DatasetGraphTextMonitor implements Transac
@Override
public void end() {
- if ( ! isInTransaction() ) {
- super.end() ;
+ if ( !isInTransaction() ) {
+ super.end();
return;
}
- if (readWriteMode.get() == ReadWrite.WRITE) {
+ if ( readWriteMode.get() == ReadWrite.WRITE ) {
// If we are still in a write transaction at this point, then commit
// was never called, so rollback the TextIndex and the dataset.
abortAction.run();
}
- super.end() ;
- super.getMonitor().finish() ;
- readWriteMode.set(null) ;
+ super.end();
+ super.getMonitor().finish();
+ readWriteMode.set(null);
}
@Override
public boolean supportsTransactions() {
- return super.supportsTransactions() ;
+ return super.supportsTransactions();
}
- /** Declare whether {@link #abort} is supported.
- * This goes along with clearing up after exceptions inside application transaction code.
+ /**
+ * Declare whether {@link #abort} is supported. This goes along with clearing up
+ * after exceptions inside application transaction code.
*/
@Override
public boolean supportsTransactionAbort() {
- return super.supportsTransactionAbort() ;
+ return super.supportsTransactionAbort();
}
@Override
public void close() {
super.close();
- if (closeIndexOnClose) {
+ if ( closeIndexOnClose ) {
textIndex.close();
}
}
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/changes/DatasetGraphTextMonitor.java b/jena-text/src/main/java/org/apache/jena/query/text/changes/DatasetGraphTextMonitor.java
index 942ab8c946..37ecaebbd6 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/changes/DatasetGraphTextMonitor.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/changes/DatasetGraphTextMonitor.java
@@ -16,192 +16,186 @@
* limitations under the License.
*/
-package org.apache.jena.query.text.changes ;
+package org.apache.jena.query.text.changes;
-import static org.apache.jena.atlas.iterator.Iter.take ;
+import static org.apache.jena.atlas.iterator.Iter.take;
import static org.apache.jena.sparql.core.GraphView.createDefaultGraph;
import static org.apache.jena.sparql.core.GraphView.createNamedGraph;
-import java.util.Iterator ;
-import java.util.List ;
+import java.util.Iterator;
+import java.util.List;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.sparql.SystemARQ ;
+import org.apache.jena.graph.Graph;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.Triple;
+import org.apache.jena.sparql.SystemARQ;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.core.DatasetGraphWrapper;
import org.apache.jena.sparql.core.Quad;
-import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.ExtendedIterator;
-/** Connect a DatasetGraph to a DatasetChanges monitor.
- * Any add or delete to the DatasetGraph is notified to the
- * monitoring object with a {@link TextQuadAction} to indicate
- * the change made.
+/**
+ * Connect a DatasetGraph to a DatasetChanges monitor. Any add or delete to the
+ * DatasetGraph is notified to the monitoring object with a {@link TextQuadAction} to
+ * indicate the change made.
*/
-public class DatasetGraphTextMonitor extends DatasetGraphWrapper
-{
- /** Whether to see if a quad action will change the dataset - test before add for existence, test before delete for absence */
- private boolean CheckFirst = true ;
+public class DatasetGraphTextMonitor extends DatasetGraphWrapper {
+ /**
+ * Whether to see if a quad action will change the dataset - test before add for
+ * existence, test before delete for absence
+ */
+ private boolean CheckFirst = true;
/** Whether to record a no-op (maybe as a comment) */
- private boolean RecordNoAction = true ;
+ private boolean RecordNoAction = true;
/** Where to send the notifications */
- private final TextDatasetChanges monitor ;
+ private final TextDatasetChanges monitor;
/**
- * Create a DatasetGraph wrapper that monitors the dataset for changes (add or delete quads).
- * Use this DatasetGraph for all operations in order to record changes.
- * Note whether additions of deletions cause an actual change to the dataset or not.
- * @param dsg The DatasetGraph to monitor
- * @param monitor The handler for a change
+ * Create a DatasetGraph wrapper that monitors the dataset for changes (add or
+ * delete quads). Use this DatasetGraph for all operations in order to record
+ * changes. Note whether additions of deletions cause an actual change to the
+ * dataset or not.
*
+ * @param dsg The DatasetGraph to monitor
+ * @param monitor The handler for a change
* @see TextDatasetChanges
* @see TextQuadAction
*/
- public DatasetGraphTextMonitor(DatasetGraph dsg, TextDatasetChanges monitor)
- {
- super(dsg) ;
- this.monitor = monitor ;
+ public DatasetGraphTextMonitor(DatasetGraph dsg, TextDatasetChanges monitor) {
+ super(dsg);
+ this.monitor = monitor;
}
/**
- * Create a DatasetGraph wrapper that monitors the dataset for changes (add or delete quads).
- * Use this DatasetGraph for all operations in order to record changes.
- * @param dsg The DatasetGraph to monitor
- * @param monitor The handler for a change
- * @param recordOnlyIfRealChange
- * If true, check to see if the change would have an effect (e.g. add is a new quad).
- * If false, log changes as ADD/DELETE regardless of whether the dataset actually changes.
+ * Create a DatasetGraph wrapper that monitors the dataset for changes (add or
+ * delete quads). Use this DatasetGraph for all operations in order to record
+ * changes.
*
+ * @param dsg The DatasetGraph to monitor
+ * @param monitor The handler for a change
+ * @param recordOnlyIfRealChange If true, check to see if the change would have
+ * an effect (e.g. add is a new quad). If false, log changes as ADD/DELETE
+ * regardless of whether the dataset actually changes.
* @see TextDatasetChanges
* @see TextQuadAction
*/
- public DatasetGraphTextMonitor(DatasetGraph dsg, TextDatasetChanges monitor, boolean recordOnlyIfRealChange)
- {
- super(dsg) ;
- CheckFirst = recordOnlyIfRealChange ;
- this.monitor = monitor ;
+ public DatasetGraphTextMonitor(DatasetGraph dsg, TextDatasetChanges monitor, boolean recordOnlyIfRealChange) {
+ super(dsg);
+ CheckFirst = recordOnlyIfRealChange;
+ this.monitor = monitor;
}
/** Return the monitor */
- public TextDatasetChanges getMonitor() { return monitor ; }
+ public TextDatasetChanges getMonitor() {
+ return monitor;
+ }
/** Return the monitored DatasetGraph */
- public DatasetGraph monitored() { return getWrapped() ; }
+ public DatasetGraph monitored() {
+ return getWrapped();
+ }
- @Override public void add(Quad quad)
- {
- if ( CheckFirst && contains(quad) )
- {
+ @Override
+ public void add(Quad quad) {
+ if ( CheckFirst && contains(quad) ) {
if ( RecordNoAction )
- record(TextQuadAction.NO_ADD, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ;
- return ;
+ record(TextQuadAction.NO_ADD, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject());
+ return;
}
- add$(quad) ;
+ add$(quad);
}
- @Override public void add(Node g, Node s, Node p, Node o)
- {
- if ( CheckFirst && contains(g,s,p,o) )
- {
+ @Override
+ public void add(Node g, Node s, Node p, Node o) {
+ if ( CheckFirst && contains(g, s, p, o) ) {
if ( RecordNoAction )
- record(TextQuadAction.NO_ADD,g,s,p,o) ;
- return ;
+ record(TextQuadAction.NO_ADD, g, s, p, o);
+ return;
}
- add$(g,s,p,o) ;
+ add$(g, s, p, o);
}
- private void add$(Node g, Node s, Node p, Node o)
- {
- super.add(g,s,p,o) ;
- record(TextQuadAction.ADD,g,s,p,o) ;
+ private void add$(Node g, Node s, Node p, Node o) {
+ super.add(g, s, p, o);
+ record(TextQuadAction.ADD, g, s, p, o);
}
- private void add$(Quad quad)
- {
- super.add(quad) ;
- record(TextQuadAction.ADD, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ;
+ private void add$(Quad quad) {
+ super.add(quad);
+ record(TextQuadAction.ADD, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject());
}
- @Override public void delete(Quad quad)
- {
- if ( CheckFirst && ! contains(quad) )
- {
+ @Override
+ public void delete(Quad quad) {
+ if ( CheckFirst && !contains(quad) ) {
if ( RecordNoAction )
- record(TextQuadAction.NO_DELETE, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ;
- return ;
+ record(TextQuadAction.NO_DELETE, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject());
+ return;
}
- delete$(quad) ;
+ delete$(quad);
}
- @Override public void delete(Node g, Node s, Node p, Node o)
- {
- if ( CheckFirst && ! contains(g,s,p,o) )
- {
+ @Override
+ public void delete(Node g, Node s, Node p, Node o) {
+ if ( CheckFirst && !contains(g, s, p, o) ) {
if ( RecordNoAction )
- record(TextQuadAction.NO_DELETE, g,s,p,o) ;
- return ;
+ record(TextQuadAction.NO_DELETE, g, s, p, o);
+ return;
}
- delete$(g,s,p,o) ;
+ delete$(g, s, p, o);
}
- private void delete$(Quad quad)
- {
- super.delete(quad) ;
- record(TextQuadAction.DELETE, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ;
+ private void delete$(Quad quad) {
+ super.delete(quad);
+ record(TextQuadAction.DELETE, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject());
}
- private void delete$(Node g, Node s, Node p, Node o)
- {
- super.delete(g,s,p,o) ;
- record(TextQuadAction.DELETE,g,s,p,o) ;
+ private void delete$(Node g, Node s, Node p, Node o) {
+ super.delete(g, s, p, o);
+ record(TextQuadAction.DELETE, g, s, p, o);
}
-
- private static int SLICE = 1000 ;
+ private static int SLICE = 1000;
@Override
- public void deleteAny(Node g, Node s, Node p, Node o)
- {
- while (true)
- {
- Iterator<Quad> iter = find(g, s, p, o) ;
+ public void deleteAny(Node g, Node s, Node p, Node o) {
+ while (true) {
+ Iterator<Quad> iter = find(g, s, p, o);
// Materialize - stops possible ConcurrentModificationExceptions
- List<Quad> some = take(iter, SLICE) ;
- for (Quad q : some)
- delete$(q) ;
- if (some.size() < SLICE) break ;
+ List<Quad> some = take(iter, SLICE);
+ for ( Quad q : some )
+ delete$(q);
+ if ( some.size() < SLICE )
+ break;
}
}
- @Override public void addGraph(Node gn, Graph g)
- {
+ @Override
+ public void addGraph(Node gn, Graph g) {
// Convert to quads.
- //super.addGraph(gn, g) ;
- ExtendedIterator<Triple> iter = g.find(Node.ANY, Node.ANY, Node.ANY) ;
- for ( ; iter.hasNext(); )
- {
- Triple t = iter.next() ;
- add(gn, t.getSubject(), t.getPredicate(), t.getObject()) ;
+ // super.addGraph(gn, g) ;
+ ExtendedIterator<Triple> iter = g.find(Node.ANY, Node.ANY, Node.ANY);
+ for ( ; iter.hasNext() ; ) {
+ Triple t = iter.next();
+ add(gn, t.getSubject(), t.getPredicate(), t.getObject());
}
}
- @Override public void removeGraph(Node gn)
- {
- //super.removeGraph(gn) ;
- deleteAny(gn, Node.ANY, Node.ANY, Node.ANY) ;
+ @Override
+ public void removeGraph(Node gn) {
+ // super.removeGraph(gn) ;
+ deleteAny(gn, Node.ANY, Node.ANY, Node.ANY);
}
- private void record(TextQuadAction action, Node g, Node s, Node p, Node o)
- {
- monitor.change(action, g, s, p, o) ;
+ private void record(TextQuadAction action, Node g, Node s, Node p, Node o) {
+ monitor.change(action, g, s, p, o);
}
@Override
public void sync() {
- SystemARQ.syncObject(monitor) ;
- super.sync() ;
+ SystemARQ.syncObject(monitor);
+ super.sync();
}
@Override
@@ -214,4 +208,3 @@ public class DatasetGraphTextMonitor extends DatasetGraphWrapper
return createNamedGraph(this, graphNode);
}
}
-
(jena) 04/06: GH-2755: DatasetGraphText call operations in correct order
Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
commit dbc0a6061f2e3c0312c5c16276b35085426fe908
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Fri Nov 8 10:31:19 2024 +0000
GH-2755: DatasetGraphText call operations in correct order
---
.../apache/jena/query/text/DatasetGraphText.java | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java b/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java
index 8a6276ff4e..e9b226c63b 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java
@@ -255,14 +255,22 @@ public class DatasetGraphText extends DatasetGraphTextMonitor implements Transac
super.end();
return;
}
- if ( readWriteMode.get() == ReadWrite.WRITE ) {
- // If we are still in a write transaction at this point, then commit
- // was never called, so rollback the TextIndex and the dataset.
- abortAction.run();
+ ReadWrite rwMode = readWriteMode.get();
+ switch(rwMode) {
+ case READ ->{
+ super.getMonitor().finish();
+ super.end();
+ readWriteMode.set(null);
+ }
+ case WRITE ->{
+ // If we are still in a write transaction at this point, then commit
+ // was never called, so rollback the TextIndex and the dataset.
+ super.getMonitor().finish();
+ abortAction.run();
+ super.end();
+ readWriteMode.set(null);
+ }
}
- super.end();
- super.getMonitor().finish();
- readWriteMode.set(null);
}
@Override
(jena) 06/06: Explicit abort on query read exceptions
Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
commit 30a2d21d9134e2598ba0e92673cc4dd0ea446602
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Fri Nov 8 10:33:14 2024 +0000
Explicit abort on query read exceptions
---
.../java/org/apache/jena/fuseki/servlets/SPARQLQueryProcessor.java | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQLQueryProcessor.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQLQueryProcessor.java
index ab91c0fbe0..f0b4199ce9 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQLQueryProcessor.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQLQueryProcessor.java
@@ -283,16 +283,22 @@ public abstract class SPARQLQueryProcessor extends ActionService
}
}
catch (QueryParseException ex) {
+ abortSilent(action);
// Late stage static error (e.g. bad fixed Lucene query string).
ServletOps.errorBadRequest("Query parse error: \n" + queryString + "\n" + SPARQLProtocol.messageForException(ex));
}
catch (QueryCancelledException ex) {
+ abortSilent(action);
// Additional counter information.
incCounter(action.getEndpoint().getCounters(), QueryTimeouts);
throw ex;
} finally { action.endRead(); }
}
+ private static void abortSilent(HttpAction action) {
+ action.abortSilent();
+ }
+
/**
* Check the query - if unacceptable, throw ActionErrorException
* or call on of the {@link ServletOps#error} operations.
(jena) 03/06: ActionPrefixes: Use HttpAction.endWrite. Call HttpAction.endRead once
Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
commit 922372d72e6bdee0ddebd860d490543bc9b65251
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Fri Nov 8 10:29:08 2024 +0000
ActionPrefixes: Use HttpAction.endWrite. Call HttpAction.endRead once
---
.../main/java/org/apache/jena/fuseki/servlets/ActionPrefixesR.java | 1 -
.../main/java/org/apache/jena/fuseki/servlets/ActionPrefixesRW.java | 4 ++--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ActionPrefixesR.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ActionPrefixesR.java
index 6a0a0c1312..17207e9e94 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ActionPrefixesR.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ActionPrefixesR.java
@@ -215,6 +215,5 @@ public class ActionPrefixesR extends ActionPrefixesBase {
}
action.commit();
ServletOps.success(action);
- action.endRead();
}
}
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ActionPrefixesRW.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ActionPrefixesRW.java
index 6b62f35349..e7300b4314 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ActionPrefixesRW.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ActionPrefixesRW.java
@@ -58,7 +58,7 @@ public class ActionPrefixesRW extends ActionPrefixesR {
action.abortSilent();
ServletOps.errorOccurred(ex);
} finally {
- action.end();
+ action.endWrite();
}
}
@@ -101,7 +101,7 @@ public class ActionPrefixesRW extends ActionPrefixesR {
ServletOps.errorOccurred(ex);
}
} finally {
- action.end();
+ action.endWrite();
}
}
}
(jena) 02/06: SPARQL_QueryGeneral: Convert dataset description handling to work on graphs
Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
commit 24a767551f0ba4ba0603322d1a4dd49ce7a6ba8a
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Fri Nov 8 10:26:43 2024 +0000
SPARQL_QueryGeneral: Convert dataset description handling to work on graphs
---
.../jena/fuseki/servlets/SPARQL_QueryGeneral.java | 116 ++++++++++-----------
.../apache/jena/fuseki/system/GraphLoadUtils.java | 15 ---
2 files changed, 58 insertions(+), 73 deletions(-)
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_QueryGeneral.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_QueryGeneral.java
index ff1bf63100..eacc2f641c 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_QueryGeneral.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_QueryGeneral.java
@@ -28,14 +28,14 @@ import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.fuseki.server.DataAccessPoint;
import org.apache.jena.fuseki.server.DataService;
import org.apache.jena.fuseki.system.GraphLoadUtils;
-import org.apache.jena.query.Dataset;
-import org.apache.jena.query.DatasetFactory;
+import org.apache.jena.graph.Graph;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
import org.apache.jena.query.Query;
-import org.apache.jena.rdf.model.Model;
-import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.riot.RiotException;
import org.apache.jena.sparql.core.DatasetDescription;
import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.core.DatasetGraphFactory;
import org.apache.jena.sparql.core.DatasetGraphZero;
public class SPARQL_QueryGeneral extends ServletAction {
@@ -109,62 +109,16 @@ public class SPARQL_QueryGeneral extends ServletAction {
if ( datasetDesc.isEmpty() )
return null;
- List<String> graphURLs = datasetDesc.getDefaultGraphURIs();
- List<String> namedGraphs = datasetDesc.getNamedGraphURIs();
-
- if ( graphURLs.size() == 0 && namedGraphs.size() == 0 )
+ if ( datasetDesc.isEmpty() )
return null;
- Dataset dataset = DatasetFactory.create();
- // Look in cache for loaded graphs!!
-
- // ---- Default graph
- {
- Model model = ModelFactory.createDefaultModel();
- for ( String uri : graphURLs ) {
- if ( uri == null || uri.equals("") )
- throw new InternalErrorException("Default graph URI is null or the empty string");
-
- try {
- GraphLoadUtils.loadModel(model, uri, MaxTriples);
- action.log.info(format("[%d] Load (default graph) %s", action.id, uri));
- }
- catch (RiotException ex) {
- action.log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
- ServletOps.errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
- }
- catch (Exception ex) {
- action.log.info(format("[%d] Failed to load (default) %s: %s", action.id, uri, ex.getMessage()));
- ServletOps.errorBadRequest("Failed to load URL " + uri);
- }
- }
- dataset.setDefaultModel(model);
- }
- // ---- Named graphs
- if ( namedGraphs != null ) {
- for ( String uri : namedGraphs ) {
- if ( uri == null || uri.equals("") )
- throw new InternalErrorException("Named graph URI is null or the empty string");
-
- try {
- Model model = ModelFactory.createDefaultModel();
- GraphLoadUtils.loadModel(model, uri, MaxTriples);
- action.log.info(format("[%d] Load (named graph) %s", action.id, uri));
- dataset.addNamedModel(uri, model);
- }
- catch (RiotException ex) {
- action.log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
- ServletOps.errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
- }
- catch (Exception ex) {
- action.log.info(format("[%d] Failed to load (named graph) %s: %s", action.id, uri, ex.getMessage()));
- ServletOps.errorBadRequest("Failed to load URL " + uri);
- }
- }
- }
-
- return dataset.asDatasetGraph();
+ DatasetGraph dsg = DatasetGraphFactory.create();
+ dsg.executeWrite(()-> {
+ datasetDescDefaultGraph(action, dsg, datasetDesc);
+ datasetDescNamedGraphs(action, dsg, datasetDesc);
+ });
+ return dsg;
}
catch (ActionErrorException ex) {
throw ex;
@@ -175,6 +129,52 @@ public class SPARQL_QueryGeneral extends ServletAction {
return null;
}
}
- }
+ // ---- Default graph
+ private static void datasetDescDefaultGraph(HttpAction action, DatasetGraph dsg, DatasetDescription datasetDesc) {
+ List<String> graphURLs = datasetDesc.getDefaultGraphURIs();
+ Graph graph = dsg.getDefaultGraph();
+
+ for ( String uri : graphURLs ) {
+ if ( uri == null || uri.equals("") )
+ throw new InternalErrorException("Default graph URI is null or the empty string");
+ try {
+ GraphLoadUtils.loadGraph(graph, uri, MaxTriples);
+ action.log.info(format("[%d] Load (default graph) %s", action.id, uri));
+ }
+ catch (RiotException ex) {
+ action.log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
+ ServletOps.errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
+ }
+ catch (Exception ex) {
+ action.log.info(format("[%d] Failed to load (default) %s: %s", action.id, uri, ex.getMessage()));
+ ServletOps.errorBadRequest("Failed to load URL " + uri);
+ }
+ }
+ }
+
+ // ---- Named graphs
+ private static void datasetDescNamedGraphs(HttpAction action, DatasetGraph dsg, DatasetDescription datasetDesc) {
+ List<String> namedGraphs = datasetDesc.getNamedGraphURIs();
+ for ( String uri : namedGraphs ) {
+ if ( uri == null || uri.equals("") )
+ throw new InternalErrorException("Named graph URI is null or the empty string");
+
+ try {
+ Node graphName = NodeFactory.createURI(uri);
+ Graph graph = dsg.getGraph(graphName);
+ GraphLoadUtils.loadGraph(graph, uri, MaxTriples);
+ action.log.info(format("[%d] Load (named graph) %s", action.id, uri));
+ }
+ catch (RiotException ex) {
+ action.log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
+ ServletOps.errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
+ }
+ catch (Exception ex) {
+ action.log.info(format("[%d] Failed to load (named graph) %s: %s", action.id, uri, ex.getMessage()));
+ ServletOps.errorBadRequest("Failed to load URL " + uri);
+ }
+ }
+ }
+ }
}
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/system/GraphLoadUtils.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/system/GraphLoadUtils.java
index f097501376..a4a5c95013 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/system/GraphLoadUtils.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/system/GraphLoadUtils.java
@@ -22,8 +22,6 @@ package org.apache.jena.fuseki.system;
import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.graph.GraphMemFactory;
import org.apache.jena.graph.Graph;
-import org.apache.jena.rdf.model.Model;
-import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.riot.RDFParser;
import org.apache.jena.riot.system.StreamRDF;
import org.apache.jena.riot.system.StreamRDFLib;
@@ -32,19 +30,6 @@ import org.apache.jena.riot.system.StreamRDFLib;
public class GraphLoadUtils
{
- // ---- Model level
-
- public static Model readModel(String uri, int limit) {
- Graph g = GraphMemFactory.createDefaultGraphSameTerm();
- readUtil(g, uri, limit);
- return ModelFactory.createModelForGraph(g);
- }
-
- public static void loadModel(Model model, String uri, int limit) {
- Graph g = model.getGraph();
- readUtil(g, uri, limit);
- }
-
// ---- Graph level
public static Graph readGraph(String uri, int limit) {
(jena) 05/06: GH-2755: Refactor to make finalization clearer
Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
commit 47b1a574a03ca298e3a7433eb5c5cdfb67a5d4c4
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Fri Nov 8 10:32:48 2024 +0000
GH-2755: Refactor to make finalization clearer
---
.../apache/jena/fuseki/servlets/HttpAction.java | 94 ++++++++++++----------
1 file changed, 52 insertions(+), 42 deletions(-)
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
index 0b1d619ba1..1b5626f121 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
@@ -320,42 +320,6 @@ public class HttpAction
startActionTxn();
}
- private /*public*/ void endInternal() {
- // Commit or abort may have called end() already.
- // Possibly multiple endWrite, endRead (not ideal, but not breaking)
- if ( actionTxEndCalled )
- return;
- actionTxEndCalled = true;
- finishActionTxn();
- if ( dataService != null )
- dataService.finishTxn();
- if ( transactional != null && transactional.isInTransaction() )
- forceAbort();
- leaveActionTxn();
- }
-
- /** Force an abort - i.e. abort with protection against anything going wrong. */
- private void forceAbort() {
- ReadWrite rwMode = transactional.transactionMode();
- if ( rwMode == null )
- // Damaged system.
- return;
- switch(rwMode) {
- case READ -> {}
- case WRITE -> {
- // Write transactions must have explicitly called commit or abort.
- FmtLog.warn(log, "[%d] Transaction still active - no commit or abort seen (forced abort)", this.id);
- try {
- transactional.abort();
- } catch (RuntimeException ex) {
- FmtLog.warn(log, "[%d] Exception in forced abort (trying to continue)", this.id, ex);
- }
- }
- }
- try { transactional.end(); }
- catch (RuntimeException ex) {}
- }
-
/**
* Begin a transaction - this should be paired with an {@link #end()}
* <pre>
@@ -422,11 +386,57 @@ public class HttpAction
endInternal();
}
- // An action begin-end is on the same thread. No concurrency issues for this flag.
+ private void endInternal() {
+ // Commit or abort may have called end() already.
+ // Possibly multiple endWrite, endRead (not ideal, but not breaking)
+ if ( actionTxnEndCalled )
+ return;
+ actionTxnEndCalled = true;
+ finishActionTxn();
+ if ( dataService != null )
+ dataService.finishTxn();
+ if ( transactional != null ) {
+ if ( transactional.isInTransaction() )
+ completeTransactional();
+ // Perform end()
+ try { transactional.end(); }
+ catch (RuntimeException ex) {}
+ }
+ leaveActionTxn();
+ }
+
+ /**
+ * Complete the transactional:
+ * <ul>
+ * <li>Read - No additional action needed</li>
+ * <li>Write force an abort</li>
+ * <ul>
+ */
+ private void completeTransactional() {
+ ReadWrite rwMode = transactional.transactionMode();
+ if ( rwMode == null )
+ // Damaged system. Robustly ignore.
+ return;
+ switch(rwMode) {
+ case READ -> {/* begin-end is accepted for a read action : work done in transactional.end() */}
+ case WRITE -> {
+ // Write transactions must have explicitly called commit or abort.
+ FmtLog.warn(log, "[%d] Transaction still active - no commit or abort seen (forced abort)", this.id);
+ try {
+ transactional.abort();
+ } catch (RuntimeException ex) {
+ FmtLog.warn(log, "[%d] Exception in forced abort (trying to continue)", this.id, ex);
+ }
+ }
+ }
+ }
+
+ // An action begin-end is on the same thread.
+ // No concurrency issues for these variables.
private boolean isInActionTxn = false;
private int actionTxnCount = 0;
- /** Used to detect two calls to {@link #endAny} */
- private boolean actionTxEndCalled = false;
+ // Protect against nesting endInternal. This should not happen.
+ private boolean actionTxnEndCalled = false;
// begin :: enter then start
// end :: finish then leave
@@ -462,7 +472,7 @@ public class HttpAction
private void startActionTxn() {
isInActionTxn = true;
actionTxnCount++;
- actionTxEndCalled = false;
+ actionTxnEndCalled = false;
}
/**
@@ -483,7 +493,7 @@ public class HttpAction
public void commit() {
if ( transactional != null )
transactional.commit();
- end();
+ endInternal();
}
/** Abort: ignore exceptions (for clearup code) */
@@ -493,7 +503,7 @@ public class HttpAction
transactional.abort();
} catch (Exception ex) {
} finally {
- try { end(); } catch (Exception ex) {}
+ try { endInternal(); } catch (Exception ex) {}
}
}