You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2018/02/12 14:19:59 UTC
jena git commit: Make sure to use datasets transactionally (JENA-1486)
Repository: jena
Updated Branches:
refs/heads/JENA-1486 [created] 4add7df01
Make sure to use datasets transactionally (JENA-1486)
textindexer did not use datasets transactionally which could fail for
dataset implementations that require transactional usage. And it is
safer to always use transactions where provided anyway.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/4add7df0
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/4add7df0
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/4add7df0
Branch: refs/heads/JENA-1486
Commit: 4add7df01950bb24f84f4a20a28129804e59b8a6
Parents: 22933e3
Author: Rob Vesse <rv...@apache.org>
Authored: Mon Feb 12 14:19:01 2018 +0000
Committer: Rob Vesse <rv...@apache.org>
Committed: Mon Feb 12 14:19:01 2018 +0000
----------------------------------------------------------------------
jena-text/src/main/java/jena/textindexer.java | 76 ++++++++++++++--------
1 file changed, 48 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/4add7df0/jena-text/src/main/java/jena/textindexer.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/jena/textindexer.java b/jena-text/src/main/java/jena/textindexer.java
index 870dfec..2af46a8 100644
--- a/jena-text/src/main/java/jena/textindexer.java
+++ b/jena-text/src/main/java/jena/textindexer.java
@@ -24,8 +24,10 @@ import java.util.Set ;
import org.apache.jena.graph.Node ;
import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.ReadWrite;
import org.apache.jena.query.text.* ;
import org.apache.jena.sparql.core.Quad ;
+import org.apache.jena.system.Txn;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import jena.cmd.ArgDecl ;
@@ -104,39 +106,57 @@ public class textindexer extends CmdARQ {
@Override
protected void exec() {
- Set<Node> properties = getIndexedProperties() ;
-
- // there are various strategies possible here
- // what is implemented is a first cut simple approach
- // currently - for each indexed property
- // list and index triples with that property
- // that way only process triples that will be indexed
- // but each entity may be updated several times
-
- for ( Node property : properties )
- {
- Iterator<Quad> quadIter = dataset.find( Node.ANY, Node.ANY, property, Node.ANY );
- for (; quadIter.hasNext(); )
+ try {
+ // JENA-1486 Make sure to use transactions if supported
+ // The supportsTransactions() check should be strictly unecessary as we should always be using a
+ // DatasetGraphText which is transactional but just for future proofing we check anyway
+ if (dataset.supportsTransactions()) {
+ dataset.begin(ReadWrite.READ);
+ }
+
+ Set<Node> properties = getIndexedProperties() ;
+
+ // there are various strategies possible here
+ // what is implemented is a first cut simple approach
+ // currently - for each indexed property
+ // list and index triples with that property
+ // that way only process triples that will be indexed
+ // but each entity may be updated several times
+
+ for ( Node property : properties )
{
- Quad quad = quadIter.next();
- if ( Quad.isDefaultGraph(quad.getGraph()) ) {
- // Need to use urn:x-arq:DefaultGraphNode for text indexing (JENA-1133)
- quad = Quad.create(Quad.defaultGraphNodeGenerated,
- quad.getSubject(), quad.getPredicate(), quad.getObject());
- }
- Entity entity = TextQueryFuncs.entityFromQuad( entityDefinition, quad );
- if ( entity != null )
+ Iterator<Quad> quadIter = dataset.find( Node.ANY, Node.ANY, property, Node.ANY );
+ for (; quadIter.hasNext(); )
{
- textIndex.addEntity( entity );
- progressMonitor.progressByOne();
+ Quad quad = quadIter.next();
+ if ( Quad.isDefaultGraph(quad.getGraph()) ) {
+ // Need to use urn:x-arq:DefaultGraphNode for text indexing (JENA-1133)
+ quad = Quad.create(Quad.defaultGraphNodeGenerated,
+ quad.getSubject(), quad.getPredicate(), quad.getObject());
+ }
+ Entity entity = TextQueryFuncs.entityFromQuad( entityDefinition, quad );
+ if ( entity != null )
+ {
+ textIndex.addEntity( entity );
+ progressMonitor.progressByOne();
+ }
}
}
+
+ textIndex.commit();
+ textIndex.close();
+
+ if (dataset.supportsTransactions()) {
+ dataset.commit();
+ }
+ dataset.close();
+
+ progressMonitor.close() ;
+ } finally {
+ if (dataset.supportsTransactions()) {
+ dataset.end();
+ }
}
-
- textIndex.commit();
- textIndex.close();
- dataset.close();
- progressMonitor.close() ;
}
private Set<Node> getIndexedProperties() {