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 2019/02/09 15:50:51 UTC
[jena] branch master updated: JENA-1663: Add triples and prefixes
inside a transaction
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/master by this push:
new a9d9021 JENA-1663: Add triples and prefixes inside a transaction
new 3246b34 Merge pull request #529 from afs/jena1663
a9d9021 is described below
commit a9d902193d49c33f6a6dc611514f4b8b26a8b581
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Thu Jan 31 20:04:08 2019 +0000
JENA-1663: Add triples and prefixes inside a transaction
---
.../jena/assembler/assemblers/ModelAssembler.java | 46 ++++++++++++++++------
1 file changed, 33 insertions(+), 13 deletions(-)
diff --git a/jena-core/src/main/java/org/apache/jena/assembler/assemblers/ModelAssembler.java b/jena-core/src/main/java/org/apache/jena/assembler/assemblers/ModelAssembler.java
index 35d7491..508c539 100644
--- a/jena-core/src/main/java/org/apache/jena/assembler/assemblers/ModelAssembler.java
+++ b/jena-core/src/main/java/org/apache/jena/assembler/assemblers/ModelAssembler.java
@@ -38,25 +38,45 @@ public abstract class ModelAssembler extends AssemblerBase implements Assembler
return m;
}
+ /** Execute an action in a transaction if the model supports transactions.*/
+ private static void exec(Model m, Resource root, Runnable action) {
+ boolean b = m.supportsTransactions();
+ if ( b ) m.begin();
+ try {
+ action.run();
+ if ( b ) m.commit();
+ }
+ catch (Throwable t) {
+ // Compatibility ...
+ if ( b ) {
+ m.abort();
+ throw new TransactionAbortedException(root, t);
+ }
+ else
+ throw t;
+ }
+ }
+
@Override public Object open( Assembler a, Resource root, Mode mode )
{
Model m = openModel( a, root, getInitialContent( a, root ), mode );
- addContent( root, m, getContent( a, root ) );
- m.setNsPrefixes( getPrefixMapping( a, root ) );
+ exec(m, root, ()->{
+ // JENA-1663: Do these together inside a transaction.
+ addContent( root, m, getContent( a, root ) );
+ addPrefixes( m, a, root );
+ });
return m;
}
- protected void addContent( Resource root, Model m, Content c )
- {
- if (m.supportsTransactions())
- {
- m.begin();
- try { c.fill( m ); m.commit(); }
- catch (Throwable t) { m.abort(); throw new TransactionAbortedException( root, t ); }
- }
- else
- c.fill( m );
- }
+ /** Add contents, inside a model-transaction if applicable */
+ protected void addContent( Resource root, Model m, Content c ) {
+ c.fill( m );
+ }
+
+ /** Add prefixes, inside a model-transaction if applicable */
+ protected void addPrefixes(Model m, Assembler a, Resource root) {
+ m.setNsPrefixes( getPrefixMapping( a, root ) );
+ }
private PrefixMapping getPrefixMapping( Assembler a, Resource root )
{