2424
2525/**
2626 * @author Jeen Broekstra
27+ * @author James Leigh
2728 */
2829public class SailUpdate extends AbstractParserUpdate {
2930
@@ -51,34 +52,42 @@ public void execute()
5152 SailUpdateExecutor executor = new SailUpdateExecutor (con .getSailConnection (), con .getValueFactory (),
5253 con .getParserConfig ());
5354
54- for (UpdateExpr updateExpr : updateExprs ) {
55+ boolean localTransaction = false ;
56+ try {
57+ if (isLocalTransaction ()) {
58+ localTransaction = true ;
59+ beginLocalTransaction ();
60+ }
61+ for (UpdateExpr updateExpr : updateExprs ) {
5562
56- Dataset activeDataset = getMergedDataset (datasetMapping .get (updateExpr ));
63+ Dataset activeDataset = getMergedDataset (datasetMapping .get (updateExpr ));
5764
58- try {
59- boolean localTransaction = isLocalTransaction ();
60- if (localTransaction ) {
61- beginLocalTransaction ();
65+ try {
66+ executor .executeUpdate (updateExpr , activeDataset , getBindings (), getIncludeInferred (),
67+ getMaxExecutionTime ());
6268 }
63-
64- executor .executeUpdate (updateExpr , activeDataset , getBindings (), getIncludeInferred (),
65- getMaxExecutionTime ());
66-
67- if (localTransaction ) {
68- commitLocalTransaction ();
69+ catch (RDF4JException e ) {
70+ logger .warn ("exception during update execution: " , e );
71+ if (!updateExpr .isSilent ()) {
72+ throw new UpdateExecutionException (e );
73+ }
6974 }
70- }
71- catch ( RDF4JException e ) {
72- logger . warn ( "exception during update execution: " , e );
73- if (! updateExpr . isSilent ()) {
74- throw new UpdateExecutionException ( e );
75+ catch ( IOException e ) {
76+ logger . warn ( "exception during update execution: " , e );
77+ if (! updateExpr . isSilent ()) {
78+ throw new UpdateExecutionException ( e );
79+ }
7580 }
7681 }
77- catch (IOException e ) {
78- logger .warn ("exception during update execution: " , e );
79- if (!updateExpr .isSilent ()) {
80- throw new UpdateExecutionException (e );
81- }
82+
83+ if (localTransaction ) {
84+ commitLocalTransaction ();
85+ localTransaction = false ;
86+ }
87+ }
88+ finally {
89+ if (localTransaction ) {
90+ rollbackLocalTransaction ();
8291 }
8392 }
8493 }
@@ -101,4 +110,11 @@ private void commitLocalTransaction()
101110 getConnection ().commit ();
102111
103112 }
113+
114+ private void rollbackLocalTransaction ()
115+ throws RepositoryException
116+ {
117+ getConnection ().rollback ();
118+
119+ }
104120}
0 commit comments