promote(Promote mode)

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/5f99f5f3
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/5f99f5f3
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/5f99f5f3

Branch: refs/heads/master
Commit: 5f99f5f3bb1a0e34d71048d1cec97f6b81bdbb64
Parents: d8306ce
Author: Andy Seaborne <a...@apache.org>
Authored: Tue Feb 6 12:36:52 2018 +0000
Committer: Andy Seaborne <a...@apache.org>
Committed: Fri Feb 9 21:52:42 2018 +0000

----------------------------------------------------------------------
 .../java/org/apache/jena/query/TxnType.java     |   7 +
 .../jena/sparql/core/DatasetGraphMap.java       |   3 +-
 .../jena/sparql/core/DatasetGraphMapLink.java   |   3 +-
 .../jena/sparql/core/DatasetGraphOne.java       |   3 +-
 .../jena/sparql/core/DatasetGraphSink.java      |   3 +-
 .../sparql/core/DatasetGraphTrackActive.java    |   6 +-
 .../jena/sparql/core/DatasetGraphWithLock.java  |   2 +-
 .../jena/sparql/core/DatasetGraphWrapper.java   |   2 +-
 .../jena/sparql/core/DatasetGraphZero.java      |   3 +-
 .../apache/jena/sparql/core/DatasetImpl.java    |   7 +-
 .../apache/jena/sparql/core/Transactional.java  |  41 +-
 .../jena/sparql/core/TransactionalLock.java     |   8 +-
 .../sparql/core/TransactionalNotSupported.java  |   6 +-
 .../core/TransactionalNotSupportedMixin.java    |   7 +-
 .../jena/sparql/core/TransactionalNull.java     |   8 +-
 .../sparql/core/mem/DatasetGraphInMemory.java   |  27 +-
 .../engine/QueryEngineFactoryWrapper.java       |   8 +-
 .../jena/sparql/util/DyadicDatasetGraph.java    |  35 +-
 .../java/org/apache/jena/system/TxnCounter.java |  11 +-
 .../org/apache/jena/sparql/ARQTestSuite.java    |   5 +-
 .../jena/sparql/graph/TestGraphUnionRead.java   | 149 +++---
 .../AbstractTestTransactionLifecycle.java       | 523 +++++++++++--------
 .../sparql/util/TestDyadicDatasetGraph.java     |  66 ++-
 .../java/org/apache/jena/system/JenaSystem.java |   2 +-
 .../jena/dboe/transaction/txn/Transaction.java  |  18 +-
 .../transaction/txn/TransactionCoordinator.java |  50 +-
 .../dboe/transaction/txn/TransactionalBase.java |  28 +-
 .../transaction/TestTransactionLifecycle.java   |   5 +-
 .../transaction/TestTransactionLifecycle2.java  |  15 +-
 .../jena/tdb2/setup/AbstractTDBBuilder.java     |   4 +-
 .../apache/jena/tdb2/solver/OpExecutorTDB1.java | 428 ---------------
 .../apache/jena/tdb2/solver/OpExecutorTDB2.java | 428 +++++++++++++++
 .../jena/tdb2/store/DatasetGraphSwitchable.java |   3 +-
 .../apache/jena/tdb2/store/DatasetGraphTDB.java |   5 +-
 .../jena/tdb2/store/DatasetGraphWrapperTxn.java |  34 --
 .../apache/jena/tdb2/store/TestDatasetTDB.java  |   7 +
 .../jena/rdfconnection/RDFConnectionLocal.java  |   3 +-
 .../rdfconnection/RDFConnectionModular.java     |   3 +-
 .../jena/rdfconnection/RDFConnectionRemote.java |   3 +-
 .../apache/jena/sdb/store/DatasetGraphSDB.java  |   3 +-
 .../apache/jena/tdb/store/DatasetGraphTDB.java  |   3 +-
 .../transaction/DatasetGraphTransaction.java    |  17 +-
 .../tdb/transaction/TransactionManager.java     |  22 +-
 pom.xml                                         |   1 +
 44 files changed, 1029 insertions(+), 986 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/query/TxnType.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/query/TxnType.java 
b/jena-arq/src/main/java/org/apache/jena/query/TxnType.java
index 56c841a..5367a74 100644
--- a/jena-arq/src/main/java/org/apache/jena/query/TxnType.java
+++ b/jena-arq/src/main/java/org/apache/jena/query/TxnType.java
@@ -21,6 +21,7 @@ package org.apache.jena.query;
 import java.util.Objects;
 
 import org.apache.jena.sparql.JenaTransactionException;
+import org.apache.jena.sparql.core.Transactional;
 
 public enum TxnType {
     /** Transaction mode:
@@ -74,4 +75,10 @@ public enum TxnType {
         return (txnType == TxnType.WRITE) ? ReadWrite.WRITE : ReadWrite.READ;
     }
 
+    /** Convert a {@code TxnType} mode to {@link ReadWrite} : "promote" not 
supported.  */
+    public static TxnType promote(Transactional.Promote promoteMode) {
+        Objects.requireNonNull(promoteMode);
+        return (promoteMode == Transactional.Promote.ISOLATED) ? READ_PROMOTE 
: READ_COMMITTED_PROMOTE;
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
index df6762c..c01f250 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
@@ -73,8 +73,7 @@ public class DatasetGraphMap extends DatasetGraphTriplesQuads
     @Override public void begin()                       { txn.begin(); }
     @Override public void begin(TxnType txnType)        { txn.begin(txnType); }
     @Override public void begin(ReadWrite mode)         { txn.begin(mode); }
-    @Override public boolean promote()                  { return 
txn.promote(); }
-    @Override public boolean promote(TxnType txnType)   { return 
txn.promote(txnType); }
+    @Override public boolean promote(Promote txnType)   { return 
txn.promote(txnType); }
     @Override public void commit()                      { txn.commit(); }
     @Override public void abort()                       { txn.abort(); }
     @Override public boolean isInTransaction()          { return 
txn.isInTransaction(); }

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
index b3f1880..90efd0e 100644
--- 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
+++ 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
@@ -130,8 +130,7 @@ public class DatasetGraphMapLink extends 
DatasetGraphCollection
     @Override public void begin()                       { txn.begin(); }
     @Override public void begin(TxnType txnType)        { txn.begin(txnType); }
     @Override public void begin(ReadWrite mode)         { txn.begin(mode); }
-    @Override public boolean promote()                  { return 
txn.promote(); }
-    @Override public boolean promote(TxnType txnType)   { return 
txn.promote(txnType); }
+    @Override public boolean promote(Promote txnType)   { return 
txn.promote(txnType); }
     //@Override public void commit()                      { txn.commit(); }
     @Override public void abort()                       { txn.abort(); }
     @Override public boolean isInTransaction()          { return 
txn.isInTransaction(); }

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphOne.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphOne.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphOne.java
index 7c302c2..89d76cb 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphOne.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphOne.java
@@ -76,8 +76,7 @@ public class DatasetGraphOne extends DatasetGraphBaseFind {
     @Override public void begin(TxnType txnType)        { txn.begin(txnType); }
     @Override public void begin(ReadWrite mode)         { txn.begin(mode); }
     @Override public void commit()                      { txn.commit(); }
-    @Override public boolean promote()                  { return 
txn.promote(); }
-    @Override public boolean promote(TxnType txnType)   { return 
txn.promote(txnType); }
+    @Override public boolean promote(Promote txnType)   { return 
txn.promote(txnType); }
     @Override public void abort()                       { txn.abort(); }
     @Override public boolean isInTransaction()          { return 
txn.isInTransaction(); }
     @Override public void end()                         { txn.end(); }

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphSink.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphSink.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphSink.java
index 2799aff..90cda52 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphSink.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphSink.java
@@ -44,8 +44,7 @@ public class DatasetGraphSink extends DatasetGraphBaseFind {
     private TransactionalNull txn                       = 
TransactionalNull.create();
     @Override public void begin(TxnType txnType)        { txn.begin(txnType); }
     @Override public void begin(ReadWrite mode)         { txn.begin(mode); }
-    @Override public boolean promote()                  { return 
txn.promote(); }
-    @Override public boolean promote(TxnType txnType)   { return 
txn.promote(txnType); }
+    @Override public boolean promote(Promote txnType)   { return 
txn.promote(txnType); }
     @Override public void commit()                      { txn.commit(); }
     @Override public void abort()                       { txn.abort(); }
     @Override public boolean isInTransaction()          { return 
txn.isInTransaction(); }

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphTrackActive.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphTrackActive.java
 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphTrackActive.java
index ef15ea1..ec323d4 100644
--- 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphTrackActive.java
+++ 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphTrackActive.java
@@ -48,9 +48,9 @@ public abstract class DatasetGraphTrackActive extends 
DatasetGraphWrapper
     }
 
     @Override
-    public final boolean promote() {
+    public final boolean promote(Promote promoteMode) {
         checkActive();
-        return _promote();
+        return _promote(promoteMode);
     }
 
     @Override
@@ -74,7 +74,7 @@ public abstract class DatasetGraphTrackActive extends 
DatasetGraphWrapper
     @Override
     public abstract boolean isInTransaction() ;
     protected abstract void _begin(TxnType txnType);
-    protected abstract boolean _promote() ;
+    protected abstract boolean _promote(Promote promoteMode) ;
     protected abstract void _commit() ;
     protected abstract void _abort() ;
     protected abstract void _end() ;

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWithLock.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWithLock.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWithLock.java
index 815414e..ff79e97 100644
--- 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWithLock.java
+++ 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWithLock.java
@@ -106,7 +106,7 @@ public class DatasetGraphWithLock extends 
DatasetGraphTrackActive implements Syn
     }
 
     @Override
-    protected boolean _promote() {
+    protected boolean _promote(Promote promoteMode) {
         throw new JenaTransactionException("promote not supported");
     }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWrapper.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWrapper.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWrapper.java
index e9dfd6e..426faef 100644
--- 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWrapper.java
+++ 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphWrapper.java
@@ -211,7 +211,7 @@ public class DatasetGraphWrapper implements DatasetGraph, 
Sync
     { return getT().promote(); }
     
     @Override
-    public boolean promote(TxnType type)
+    public boolean promote(Promote type)
     { return getT().promote(type); }
     
     @Override

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphZero.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphZero.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphZero.java
index 376721e..388d850 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphZero.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphZero.java
@@ -44,8 +44,7 @@ public class DatasetGraphZero extends DatasetGraphBaseFind {
     @Override public void begin()                       { txn.begin(); }
     @Override public void begin(TxnType txnType)        { txn.begin(txnType); }
     @Override public void begin(ReadWrite mode)         { txn.begin(mode); }
-    @Override public boolean promote()                  { return 
txn.promote(); }
-    @Override public boolean promote(TxnType txnType)   { return 
txn.promote(txnType); }
+    @Override public boolean promote(Promote txnType)   { return 
txn.promote(txnType); }
     @Override public void commit()                      { txn.commit(); }
     @Override public void abort()                       { txn.abort(); }
     @Override public boolean isInTransaction()          { return 
txn.isInTransaction(); }

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetImpl.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetImpl.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetImpl.java
index 85bf584..dc6a7f2 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetImpl.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetImpl.java
@@ -115,12 +115,7 @@ public class DatasetImpl implements Dataset
     }
 
     @Override
-    public boolean promote() {
-        return transactional.promote();
-    }
-
-    @Override
-    public boolean promote(TxnType txnType) {
+    public boolean promote(Promote txnType) {
         return transactional.promote(txnType);
     }
     

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/Transactional.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/Transactional.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/Transactional.java
index ce36188..899f503 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/Transactional.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/Transactional.java
@@ -117,8 +117,10 @@ public interface Transactional
      * Returns "true" if the transaction is in write mode after the call. The 
method
      * always succeeds of the transaction is already "write".
      * <p>
-     * A {@code READ_COMMITTED_PROMOTE} can always be promoted, but the call 
can need to
-     * wait. This method returns true if a {@code READ_PROMOTE} or
+     * A {@code READ_COMMITTED_PROMOTE} can always be promoted, but the call 
may need to
+     * wait.
+     * <p>
+     * This method returns true if a {@code READ_PROMOTE} or
      * {@code READ_COMMITTED_PROMOTE} is promoted.
      * <p>
      * This method returns false if a {@code READ_PROMOTE} can't be promoted - 
the
@@ -129,16 +131,28 @@ public interface Transactional
      * transaction.
      */
     public default boolean promote() {
-        return promote(transactionType());
+        if ( transactionMode() == ReadWrite.WRITE )
+            return true;
+        TxnType txnType = transactionType();
+        if ( txnType == null )
+            throw new JenaTransactionException("txnType");
+        switch(txnType) {
+            case WRITE :                  return true;
+            case READ :                   return false;
+            case READ_PROMOTE :           return promote(Promote.ISOLATED);
+            case READ_COMMITTED_PROMOTE : return 
promote(Promote.READ_COMMITTED);
+        }
+        throw new JenaTransactionException("Can't determine promote 
'"+txnType+"'transaction");
     }
 
-    public enum Promote { ISOLATED, @Deprecated SERIALIZED, READ_COMMITTED } ; 
+    public enum Promote { ISOLATED, READ_COMMITTED } ; 
     
     /**
-     * Attempt to promote a transaction from "read" to "write" and the 
transaction. This
-     * method allows the form of promotion to be specified.
+     * Attempt to promote a transaction from "read" mode to "write" and the 
transaction. This
+     * method allows the form of promotion to be specified. The transaction 
must not have been started
+     * with {@code READ}, which is read-only. 
      * <p>
-     * {@code READ_PROMOTE} treats the promotion as if the transaction was 
started
+     * An argument of {@code READ_PROMOTE} treats the promotion as if the 
transaction was started
      * with {@code READ_PROMOTE} (any other writer commiting since the 
transaction started
      * blocks promotion) and {@code READ_COMMITTED_PROMOTE} treats the 
promotion as if the transaction was started
      * with {@code READ_COMMITTED_PROMOTE} (intemediate writer commits become 
visible).
@@ -152,8 +166,10 @@ public interface Transactional
      * This method returns false if a {@code READ_PROMOTE} can't be promoted - 
the
      * transaction is still valid and in "read" mode.
      * <p>
+     * This method throws an exception if there is an attempt to promote a 
{@code READ}
+     * transaction.
      */
-    public boolean promote(TxnType mode);
+    public boolean promote(Promote mode);
 
     /** Commit a transaction - finish the transaction and make any changes 
permanent (if a "write" transaction) */  
     public void commit() ;
@@ -164,12 +180,15 @@ public interface Transactional
     /** Finish the transaction - if a write transaction and commit() has not 
been called, then abort */  
     public void end() ;
 
-    /** Return the current mode of the transaction - "read" or "write" */ 
+    /** Return the current mode of the transaction - "read" or "write".
+     * If the caller is not in a transaction, this method returns null. 
+     */ 
     public ReadWrite transactionMode();
 
-    /** Return the transaction type used in {@code begin(TxnType)}. */ 
+    /** Return the transaction type used in {@code begin(TxnType)}. 
+     * If the caller is not in a transaction, this method returns null. 
+     */ 
     public TxnType transactionType();
-    //public default TxnType transactionType() { throw new 
JenaTransactionException("Not implemented"); }
 
     /** Say whether inside a transaction. */ 
     public boolean isInTransaction() ;

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalLock.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalLock.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalLock.java
index c4414de..3db630e 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalLock.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalLock.java
@@ -54,7 +54,6 @@ public class TransactionalLock implements Transactional {
     @Override public void begin()                       { txn.begin(); }
     @Override public void begin(TxnType txnType)        { txn.begin(txnType); }
     @Override public void begin(ReadWrite mode)         { txn.begin(mode); }
-    @Override public boolean promote()                  { return 
txn.promote(); }
     @Override public void commit()                      { txn.commit(); }
     @Override public void abort()                       { txn.abort(); }
     @Override public boolean isInTransaction()          { return 
txn.isInTransaction(); }
@@ -128,12 +127,7 @@ public class TransactionalLock implements Transactional {
     // Lock propmotion required (Ok for mutex) 
     
     @Override
-    public boolean promote() { 
-        return false;
-    }
-
-    @Override
-    public boolean promote(TxnType txnType) { 
+    public boolean promote(Promote txnType) { 
         return false;
     }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNotSupported.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNotSupported.java
 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNotSupported.java
index 1700fcb..e482ed5 100644
--- 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNotSupported.java
+++ 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNotSupported.java
@@ -42,7 +42,6 @@ public class TransactionalNotSupported implements 
Transactional
     @Override public void begin()                       { txn.begin(); }
     @Override public void begin(TxnType txnType)        { txn.begin(txnType); }
     @Override public void begin(ReadWrite mode)         { txn.begin(mode); }
-    @Override public boolean promote()                  { return 
txn.promote(); }
     @Override public void commit()                      { txn.commit(); }
     @Override public void abort()                       { txn.abort(); }
     @Override public boolean isInTransaction()          { return 
txn.isInTransaction(); }
@@ -68,11 +67,8 @@ public class TransactionalNotSupported implements 
Transactional
     public void begin(ReadWrite readWrite)
     { throw new 
UnsupportedOperationException("Transactional.begin(ReadWrite)") ; }
 
-    @Override public boolean promote()
+    @Override public boolean promote(Promote txnType)
     { throw new UnsupportedOperationException("Transactional.promote") ; }
-    
-    @Override public boolean promote(TxnType txnType)
-    { throw new 
UnsupportedOperationException("Transactional.promote(TxnType)") ; }
 
     @Override
     public void commit()

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNotSupportedMixin.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNotSupportedMixin.java
 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNotSupportedMixin.java
index 66253ad..894d965 100644
--- 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNotSupportedMixin.java
+++ 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNotSupportedMixin.java
@@ -38,11 +38,8 @@ public interface TransactionalNotSupportedMixin extends 
Transactional
     public default void begin(ReadWrite readWrite)
     { throw new 
UnsupportedOperationException("Transactional.begin(ReadWrite)") ; }
 
-    @Override public default boolean promote()
-    { throw new UnsupportedOperationException("Transactional.promote()") ; }
-    
-    @Override public default boolean promote(TxnType txnType)
-    { throw new 
UnsupportedOperationException("Transactional.promote(TxnType)") ; }
+    @Override public default boolean promote(Promote txnType)
+    { throw new UnsupportedOperationException("Transactional.promote") ; }
     
     @Override
     public default void commit()

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNull.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNull.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNull.java
index 1ab2e60..89dee0f 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNull.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/TransactionalNull.java
@@ -32,7 +32,6 @@ public class TransactionalNull implements Transactional {
     @Override public void begin()                       { txn.begin(); }
     @Override public void begin(TxnType txnType)        { txn.begin(txnType); }
     @Override public void begin(ReadWrite mode)         { txn.begin(mode); }
-    @Override public boolean promote()                  { return 
txn.promote(); }
     @Override public void commit()                      { txn.commit(); }
     @Override public void abort()                       { txn.abort(); }
     @Override public boolean isInTransaction()          { return 
txn.isInTransaction(); }
@@ -77,17 +76,12 @@ public class TransactionalNull implements Transactional {
     }
 
     @Override
-    public boolean promote() {
+    public boolean promote(Promote txnType) {
         if ( ! inTransaction.get() )
             throw new JenaTransactionException("Not in transaction"); 
         txnMode.set(ReadWrite.WRITE);
         return true;
     }
-    
-    @Override
-    public boolean promote(TxnType txnType) {
-        return promote(); 
-    }
 
     @Override
     public void commit() {

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
index 8c965cd..e7823b9 100644
--- 
a/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
+++ 
b/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
@@ -178,31 +178,16 @@ public class DatasetGraphInMemory extends 
DatasetGraphTriplesQuads implements Tr
     }
 
     @Override
-    public boolean promote() {
-        return promote(transactionType.get());
-    }
-    
-    @Override
-    public boolean promote(TxnType txnType) {
+    public boolean promote(Promote promoteMode) {
         if (!isInTransaction())
             throw new JenaTransactionException("Tried to promote outside a 
transaction!");
         if ( transactionMode().equals(ReadWrite.WRITE) )
             return true;
-        boolean readCommitted;
-        switch(txnType) {
-            case WRITE :
-                return true;
-            case READ :
-                throw new JenaTransactionException("Tried to promote READ 
transaction");
-            case READ_COMMITTED_PROMOTE :
-                readCommitted = true;
-            case READ_PROMOTE :
-                readCommitted = false;
-                // Maybe!
-                break;
-            default:
-                throw new NullPointerException();
-        }
+        
+        if ( transactionType() == TxnType.READ )
+            return false;
+        
+        boolean readCommitted = (promoteMode == Promote.READ_COMMITTED);
         
         try {
             _promote(readCommitted);

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/engine/QueryEngineFactoryWrapper.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/engine/QueryEngineFactoryWrapper.java
 
b/jena-arq/src/main/java/org/apache/jena/sparql/engine/QueryEngineFactoryWrapper.java
index 004688d..2f00eee 100644
--- 
a/jena-arq/src/main/java/org/apache/jena/sparql/engine/QueryEngineFactoryWrapper.java
+++ 
b/jena-arq/src/main/java/org/apache/jena/sparql/engine/QueryEngineFactoryWrapper.java
@@ -36,7 +36,7 @@ public class QueryEngineFactoryWrapper implements 
QueryEngineFactory
     
     @Override
     public boolean accept(Query query, DatasetGraph dsg, Context context) {
-        if ( !(  dsg instanceof DatasetGraphWrapper ) )
+        if ( !( dsg instanceof DatasetGraphWrapper ) )
             return false ;    
         DatasetGraph dsg2 = ((DatasetGraphWrapper)dsg).getWrapped() ;
         return QueryEngineRegistry.findFactory(query, dsg2, 
context).accept(query, dsg2, context) ;
@@ -44,7 +44,7 @@ public class QueryEngineFactoryWrapper implements 
QueryEngineFactory
 
     @Override
     public Plan create(Query query, DatasetGraph dsg, Binding inputBinding, 
Context context) {
-        if ( !(  dsg instanceof DatasetGraphWrapper ) )
+        if ( ! ( dsg instanceof DatasetGraphWrapper ) )
             return null ;    
         DatasetGraph dsg2 = ((DatasetGraphWrapper)dsg).getWrapped() ;
         return QueryEngineRegistry.findFactory(query, dsg2, 
context).create(query, dsg2, inputBinding, context) ;
@@ -52,7 +52,7 @@ public class QueryEngineFactoryWrapper implements 
QueryEngineFactory
 
     @Override
     public boolean accept(Op op, DatasetGraph dsg, Context context) {
-        if ( !(  dsg instanceof DatasetGraphWrapper ) )
+        if ( ! ( dsg instanceof DatasetGraphWrapper ) )
             return false ;    
         DatasetGraph dsg2 = ((DatasetGraphWrapper)dsg).getWrapped() ;
         return QueryEngineRegistry.findFactory(op, dsg2, context).accept(op, 
dsg2, context) ;
@@ -60,7 +60,7 @@ public class QueryEngineFactoryWrapper implements 
QueryEngineFactory
 
     @Override
     public Plan create(Op op, DatasetGraph dsg, Binding inputBinding, Context 
context) {
-        if ( !(  dsg instanceof DatasetGraphWrapper ) )
+        if ( ! ( dsg instanceof DatasetGraphWrapper ) )
             return null ;    
         DatasetGraph dsg2 = ((DatasetGraphWrapper)dsg).getWrapped() ;
         return QueryEngineRegistry.findFactory(op, dsg2, context).create(op, 
dsg2, inputBinding, context) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/sparql/util/DyadicDatasetGraph.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/util/DyadicDatasetGraph.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/util/DyadicDatasetGraph.java
index ef68b59..66e2e30 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/util/DyadicDatasetGraph.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/DyadicDatasetGraph.java
@@ -28,6 +28,7 @@ import static 
org.apache.jena.sparql.core.Quad.defaultGraphIRI;
 import static org.apache.jena.sparql.util.graph.GraphUtils.triples2quads;
 
 import java.util.Iterator;
+import java.util.Objects;
 
 import org.apache.jena.atlas.lib.PairOfSameType;
 import org.apache.jena.graph.Graph;
@@ -36,6 +37,7 @@ import org.apache.jena.graph.compose.MultiUnion;
 import org.apache.jena.query.ReadWrite;
 import org.apache.jena.query.TxnType;
 import org.apache.jena.shared.Lock;
+import org.apache.jena.sparql.JenaTransactionException;
 import org.apache.jena.sparql.core.DatasetGraph;
 import org.apache.jena.sparql.core.Quad;
 
@@ -57,43 +59,50 @@ public abstract class DyadicDatasetGraph extends 
PairOfSameType<DatasetGraph> im
 
     @Override
     public void commit() {
-        throwNoMutationAllowed();
+        forEach(DatasetGraph::commit);
     }
 
     @Override
+    public void begin() {
+        begin(TxnType.READ);
+    }
+
+    
+    @Override
     public void begin(TxnType type) {
         switch (type) {
         case READ:
             forEach(dsg -> dsg.begin(type));
             break;
         default:
-            throwNoMutationAllowed();
+            throw new JenaTransactionException("Only READ transactions 
supported");
         }
     }
 
     @Override
-    public boolean promote() {
-        // no mutation allowed
-        return false;
-    }
-
-    @Override
-    public boolean promote(TxnType txnType) {
+    public boolean promote(Promote txnType) {
         // no mutation allowed
         return false;
     }
+    
     @Override
     public ReadWrite transactionMode() {
+        if ( ! isInTransaction() )
+            return null; 
         return TxnType.convert(transactionType());
     }
 
     @Override
     public TxnType transactionType() {
-        return both(dsg -> dsg.transactionType() == READ) ? READ : null;
+        if ( ! isInTransaction() )
+            return null;
+        // no mutation allowed
+        return READ ;
     }
 
     @Override
     public synchronized void begin(ReadWrite readWrite) {
+        Objects.requireNonNull(readWrite);
         begin(TxnType.convert(readWrite));
     }
 
@@ -109,7 +118,11 @@ public abstract class DyadicDatasetGraph extends 
PairOfSameType<DatasetGraph> im
 
     @Override
     public boolean isInTransaction() {
-        return either(DatasetGraph::isInTransaction);
+        if ( both(DatasetGraph::isInTransaction) )
+            return true;
+        if ( !either(DatasetGraph::isInTransaction) )
+            return false;
+        throw new JenaTransactionException("One datset in a transaction and 
one not");
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/main/java/org/apache/jena/system/TxnCounter.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/system/TxnCounter.java 
b/jena-arq/src/main/java/org/apache/jena/system/TxnCounter.java
index e04a267..086c70a 100644
--- a/jena-arq/src/main/java/org/apache/jena/system/TxnCounter.java
+++ b/jena-arq/src/main/java/org/apache/jena/system/TxnCounter.java
@@ -118,18 +118,13 @@ public class TxnCounter implements Transactional {
     }
 
     @Override
-    public boolean promote() {
-        return promote(transactionType.get());
-    }
-    
-    @Override
-    public boolean promote(TxnType txnType) {
+    public boolean promote(Promote promoteMode) {
         checkTxn();
         if ( transactionMode.get() == ReadWrite.WRITE )
             return true;
-        if ( txnType == TxnType.READ )
+        if ( transactionType.get() == TxnType.READ )
             throw new JenaTransactionException("Attempt to promote a READ 
transsction");
-        if ( txnType == TxnType.READ_COMMITTED_PROMOTE ) {
+        if ( promoteMode == Promote.READ_COMMITTED ) {
             // READ_COMMITTED_PROMOTE
             acquireWriterLock(true);
             transactionMode.set(ReadWrite.WRITE);

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java 
b/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java
index 23f3e66..29d243c 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java
@@ -43,7 +43,10 @@ public class ARQTestSuite extends TestSuite
 
     // Log4j for testing.
     public static final String log4jPropertiesResourceName = 
"log4j-testing.properties" ;
-    static { System.getProperty("log4j.configuration", 
log4jPropertiesResourceName) ; }
+    static { 
+        System.getProperty("log4j.configuration", log4jPropertiesResourceName) 
;
+        JenaSystem.init();
+    }
     
     static public TestSuite suite()
     {

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/test/java/org/apache/jena/sparql/graph/TestGraphUnionRead.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/test/java/org/apache/jena/sparql/graph/TestGraphUnionRead.java 
b/jena-arq/src/test/java/org/apache/jena/sparql/graph/TestGraphUnionRead.java
index ecd37c0..bf3c454 100644
--- 
a/jena-arq/src/test/java/org/apache/jena/sparql/graph/TestGraphUnionRead.java
+++ 
b/jena-arq/src/test/java/org/apache/jena/sparql/graph/TestGraphUnionRead.java
@@ -18,21 +18,21 @@
 
 package org.apache.jena.sparql.graph;
 
-import java.util.Arrays ;
-import java.util.List ;
+import java.util.Arrays;
+import java.util.List;
 
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.junit.BaseTest ;
-import org.apache.jena.atlas.lib.StrUtils ;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.sparql.graph.GraphUnionRead ;
-import org.apache.jena.sparql.sse.Item ;
-import org.apache.jena.sparql.sse.SSE ;
-import org.apache.jena.sparql.sse.builders.BuilderGraph ;
-import org.junit.Test ;
+import org.apache.jena.atlas.iterator.Iter;
+import org.apache.jena.atlas.junit.BaseTest;
+import org.apache.jena.atlas.lib.StrUtils;
+import org.apache.jena.graph.Graph;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.graph.GraphUnionRead;
+import org.apache.jena.sparql.sse.Item;
+import org.apache.jena.sparql.sse.SSE;
+import org.apache.jena.sparql.sse.builders.BuilderGraph;
+import org.junit.Test;
 
 public class TestGraphUnionRead extends BaseTest
 {
@@ -53,80 +53,79 @@ public class TestGraphUnionRead extends BaseTest
       " (graph <http://example/g3>",
       "   (triple <http://example/s> <http://example/p> 'g3')",
       "   (triple <http://example/s> <http://example/p> <http://example/o>)",
-      " ))") ;
-    private static DatasetGraph dsg = null ;
+      " ))");
+    private static DatasetGraph dsg = null;
     static {
-        Item item = SSE.parse(dataStr) ;
-        dsg = BuilderGraph.buildDataset(item) ;
+        Item item = SSE.parse(dataStr);
+        dsg = BuilderGraph.buildDataset(item);
     }
-    private static Node gn1 = SSE.parseNode("<http://example/g1>") ;
-    private static Node gn2 = SSE.parseNode("<http://example/g2>") ;
-    private static Node gn3 = SSE.parseNode("<http://example/g3>") ;
-    private static Node gn9 = SSE.parseNode("<http://example/g9>") ;
+    private static Node gn1 = SSE.parseNode("<http://example/g1>");
+    private static Node gn2 = SSE.parseNode("<http://example/g2>");
+    private static Node gn3 = SSE.parseNode("<http://example/g3>");
+    private static Node gn9 = SSE.parseNode("<http://example/g9>");
     
-    @Test public void gr_union_01()
-    {
-        List<Node> gnodes = list(gn1, gn2) ;
-        Graph g = new GraphUnionRead(dsg, gnodes) ;
-        long x = Iter.count(g.find(null, null, null)) ;
-        assertEquals(3, x) ;
+    @Test
+    public void gr_union_01() {
+        List<Node> gnodes = list(gn1, gn2);
+        Graph g = new GraphUnionRead(dsg, gnodes);
+        long x = Iter.count(g.find(null, null, null));
+        assertEquals(3, x);
     }
-    
-    @Test public void gr_union_02()
-    {
-        List<Node> gnodes = list(gn1, gn2) ;
-        Graph g = new GraphUnionRead(dsg, gnodes) ;
-        Node s = NodeFactory.createURI("http://example/s";) ; 
-        long x = Iter.count(g.find(s, null, null)) ;
-        assertEquals(3, x) ;
+
+    @Test
+    public void gr_union_02() {
+        List<Node> gnodes = list(gn1, gn2);
+        Graph g = new GraphUnionRead(dsg, gnodes);
+        Node s = NodeFactory.createURI("http://example/s";);
+        long x = Iter.count(g.find(s, null, null));
+        assertEquals(3, x);
     }
 
-    @Test public void gr_union_03()
-    {
-        List<Node> gnodes = list(gn1, gn2, gn9) ;
-        Graph g = new GraphUnionRead(dsg, gnodes) ;
-        Node o = NodeFactory.createLiteral("g2") ; 
-        long x = Iter.count(g.find(null, null, o)) ;
-        assertEquals(1, x) ;
+    @Test
+    public void gr_union_03() {
+        List<Node> gnodes = list(gn1, gn2, gn9);
+        Graph g = new GraphUnionRead(dsg, gnodes);
+        Node o = NodeFactory.createLiteral("g2");
+        long x = Iter.count(g.find(null, null, o));
+        assertEquals(1, x);
     }
-    
-    @Test public void gr_union_04()
-    {
-        List<Node> gnodes = list(gn9) ;
-        Graph g = new GraphUnionRead(dsg, gnodes) ;
-        long x = Iter.count(g.find(null, null, null)) ;
-        assertEquals(0, x) ;
+
+    @Test
+    public void gr_union_04() {
+        List<Node> gnodes = list(gn9);
+        Graph g = new GraphUnionRead(dsg, gnodes);
+        long x = Iter.count(g.find(null, null, null));
+        assertEquals(0, x);
     }
 
-    @Test public void gr_union_05()
-    {
-        List<Node> gnodes = list() ;
-        Graph g = new GraphUnionRead(dsg, gnodes) ;
-        long x = Iter.count(g.find(null, null, null)) ;
-        assertEquals(0, x) ;
+    @Test
+    public void gr_union_05() {
+        List<Node> gnodes = list();
+        Graph g = new GraphUnionRead(dsg, gnodes);
+        long x = Iter.count(g.find(null, null, null));
+        assertEquals(0, x);
     }
-    
-    @Test public void gr_union_06()
-    {
-        List<Node> gnodes = list(gn1, gn1) ;
-        Graph g = new GraphUnionRead(dsg, gnodes) ;
-        long x = Iter.count(g.find(null, null, null)) ;
-        assertEquals(2, x) ;
+
+    @Test
+    public void gr_union_06() {
+        List<Node> gnodes = list(gn1, gn1);
+        Graph g = new GraphUnionRead(dsg, gnodes);
+        long x = Iter.count(g.find(null, null, null));
+        assertEquals(2, x);
     }
 
-    @Test public void gr_union_of_one_1()
-    {
-        List<Node> gnodes = list(gn2) ;
-        Graph g = new GraphUnionRead(dsg, gnodes) ;
-        long x1 = Iter.count(g.find(null, null, null)) ;
-        assertEquals(2, x1) ;
-        Node o = NodeFactory.createLiteral("g2") ; 
-        long x2 = Iter.count(g.find(null, null, o)) ;
-        assertEquals(1, x2) ;
+    @Test
+    public void gr_union_of_one_1() {
+        List<Node> gnodes = list(gn2);
+        Graph g = new GraphUnionRead(dsg, gnodes);
+        long x1 = Iter.count(g.find(null, null, null));
+        assertEquals(2, x1);
+        Node o = NodeFactory.createLiteral("g2");
+        long x2 = Iter.count(g.find(null, null, o));
+        assertEquals(1, x2);
     }
 
-    static <T> List<T> list(@SuppressWarnings("unchecked") T...x)
-    {
-        return Arrays.asList(x) ;
+    static List<Node> list(Node...x) {
+        return Arrays.asList(x);
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/test/java/org/apache/jena/sparql/transaction/AbstractTestTransactionLifecycle.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/test/java/org/apache/jena/sparql/transaction/AbstractTestTransactionLifecycle.java
 
b/jena-arq/src/test/java/org/apache/jena/sparql/transaction/AbstractTestTransactionLifecycle.java
index ec80425..f593b7c 100644
--- 
a/jena-arq/src/test/java/org/apache/jena/sparql/transaction/AbstractTestTransactionLifecycle.java
+++ 
b/jena-arq/src/test/java/org/apache/jena/sparql/transaction/AbstractTestTransactionLifecycle.java
@@ -18,145 +18,143 @@
 
 package org.apache.jena.sparql.transaction;
 
-import static org.apache.jena.query.TxnType.READ ;
-import static org.apache.jena.query.TxnType.WRITE ;
 import static org.junit.Assume.assumeTrue;
 
-import java.util.ArrayList ;
-import java.util.List ;
-import java.util.concurrent.* ;
-import java.util.concurrent.atomic.AtomicLong ;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicLong;
 
-import org.apache.jena.atlas.junit.BaseTest ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.query.Dataset ;
-import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.atlas.junit.BaseTest;
+import org.apache.jena.atlas.lib.Lib;
+import org.apache.jena.query.Dataset;
+import org.apache.jena.query.ReadWrite;
 import org.apache.jena.query.TxnType;
-import org.apache.jena.shared.JenaException;
-import org.apache.jena.sparql.JenaTransactionException ;
-import org.junit.Test ;
+import org.apache.jena.sparql.JenaTransactionException;
+import org.apache.jena.sparql.core.Transactional.Promote;
+import org.junit.Test;
 
 /**
  * Dataset transaction lifecycle. 
  */
 public abstract class AbstractTestTransactionLifecycle extends BaseTest
 {
-    protected abstract Dataset create() ;
+    protected abstract Dataset create();
     
-    protected boolean supportsAbort()   { return true ; } 
-    protected boolean supportsPromote() { return true ; }
+    protected boolean supportsAbort()   { return true; } 
+    protected boolean supportsPromote() { return true; }
 
     @Test
     public void transaction_00() {
-        Dataset ds = create() ;
-        assertTrue(ds.supportsTransactions()) ;
+        Dataset ds = create();
+        assertTrue(ds.supportsTransactions());
     }
 
     @Test
     public void transaction_r01() {
-        Dataset ds = create() ;
-        ds.begin(TxnType.READ) ;
-        assertTrue(ds.isInTransaction()) ;
-        ds.end() ;
-        assertFalse(ds.isInTransaction()) ;
+        Dataset ds = create();
+        ds.begin(TxnType.READ);
+        assertTrue(ds.isInTransaction());
+        ds.end();
+        assertFalse(ds.isInTransaction());
     }
 
     @Test
     public void transaction_r02() {
-        Dataset ds = create() ;
-        ds.begin(TxnType.READ) ;
-        assertTrue(ds.isInTransaction()) ;
-        ds.commit() ;
-        assertFalse(ds.isInTransaction()) ;
-        ds.end() ;
-        assertFalse(ds.isInTransaction()) ;
+        Dataset ds = create();
+        ds.begin(TxnType.READ);
+        assertTrue(ds.isInTransaction());
+        ds.commit();
+        assertFalse(ds.isInTransaction());
+        ds.end();
+        assertFalse(ds.isInTransaction());
     }
 
     @Test
     public void transaction_r03() {
-        Dataset ds = create() ;
-        ds.begin(TxnType.READ) ;
-        assertTrue(ds.isInTransaction()) ;
-        ds.abort() ;
-        assertFalse(ds.isInTransaction()) ;
-        ds.end() ;
-        assertFalse(ds.isInTransaction()) ;
+        Dataset ds = create();
+        ds.begin(TxnType.READ);
+        assertTrue(ds.isInTransaction());
+        ds.abort();
+        assertFalse(ds.isInTransaction());
+        ds.end();
+        assertFalse(ds.isInTransaction());
     }
 
     @Test
     public void transaction_r04() {
-        Dataset ds = create() ;
-        ds.begin(ReadWrite.READ) ;
-        assertTrue(ds.isInTransaction()) ;
-        ds.end() ;
-        assertFalse(ds.isInTransaction()) ;
+        Dataset ds = create();
+        ds.begin(ReadWrite.READ);
+        assertTrue(ds.isInTransaction());
+        ds.end();
+        assertFalse(ds.isInTransaction());
     }
 
     @Test
     public void transaction_w01() {
-        Dataset ds = create() ;
-        ds.begin(TxnType.WRITE) ;
-        assertTrue(ds.isInTransaction()) ;
-        ds.commit() ;
-        assertFalse(ds.isInTransaction()) ;
+        Dataset ds = create();
+        ds.begin(TxnType.WRITE);
+        assertTrue(ds.isInTransaction());
+        ds.commit();
+        assertFalse(ds.isInTransaction());
     }
     
     @Test
     public void transaction_w02() {
-        Dataset ds = create() ;
-        ds.begin(ReadWrite.WRITE) ;
-        assertTrue(ds.isInTransaction()) ;
-        ds.commit() ;
-        assertFalse(ds.isInTransaction()) ;
+        Dataset ds = create();
+        ds.begin(ReadWrite.WRITE);
+        assertTrue(ds.isInTransaction());
+        ds.commit();
+        assertFalse(ds.isInTransaction());
     }
 
     @Test
     public void transaction_w03() {
-        assumeTrue(supportsAbort()) ;
-        Dataset ds = create() ;
-        ds.begin(TxnType.WRITE) ;
-        assertTrue(ds.isInTransaction()) ;
-        ds.abort() ;
-        assertFalse(ds.isInTransaction()) ;
+        assumeTrue(supportsAbort());
+        Dataset ds = create();
+        ds.begin(TxnType.WRITE);
+        assertTrue(ds.isInTransaction());
+        ds.abort();
+        assertFalse(ds.isInTransaction());
     }
 
     @Test
     public void transaction_w04() {
-        Dataset ds = create() ;
-        ds.begin(TxnType.WRITE) ;
-        assertTrue(ds.isInTransaction()) ;
-        ds.commit() ;
-        assertFalse(ds.isInTransaction()) ;
-        ds.end() ;
-        assertFalse(ds.isInTransaction()) ;
+        Dataset ds = create();
+        ds.begin(TxnType.WRITE);
+        assertTrue(ds.isInTransaction());
+        ds.commit();
+        assertFalse(ds.isInTransaction());
+        ds.end();
+        assertFalse(ds.isInTransaction());
     }
 
     @Test
     public void transaction_w05() {
-        assumeTrue(supportsAbort()) ;
-        Dataset ds = create() ;
-        ds.begin(TxnType.WRITE) ;
-        assertTrue(ds.isInTransaction()) ;
-        ds.abort() ;
-        assertFalse(ds.isInTransaction()) ;
-        ds.end() ;
-        assertFalse(ds.isInTransaction()) ;
+        assumeTrue(supportsAbort());
+        Dataset ds = create();
+        ds.begin(TxnType.WRITE);
+        assertTrue(ds.isInTransaction());
+        ds.abort();
+        assertFalse(ds.isInTransaction());
+        ds.end();
+        assertFalse(ds.isInTransaction());
     }
 
     @Test
     public void transaction_w06() {
-        assumeTrue(supportsAbort()) ;
+        assumeTrue(supportsAbort());
         // .end is not necessary
-        Dataset ds = create() ;
-        ds.begin(TxnType.WRITE) ;
-        assertTrue(ds.isInTransaction()) ;
-        ds.abort() ;
-        assertFalse(ds.isInTransaction()) ;
+        Dataset ds = create();
+        ds.begin(TxnType.WRITE);
+        assertTrue(ds.isInTransaction());
+        ds.abort();
+        assertFalse(ds.isInTransaction());
 
-        ds.begin(TxnType.WRITE) ;
-        assertTrue(ds.isInTransaction()) ;
-        ds.abort() ;
-        assertFalse(ds.isInTransaction()) ;
+        ds.begin(TxnType.WRITE);
+        assertTrue(ds.isInTransaction());
+        ds.abort();
+        assertFalse(ds.isInTransaction());
     }
 
 //    TxnType.READ_PROMOTE
@@ -164,11 +162,11 @@ public abstract class AbstractTestTransactionLifecycle 
extends BaseTest
     
     @Test
     public void transaction_p01() {
-        assumeTrue(supportsPromote()) ;
-        Dataset ds = create() ;
-        ds.begin(TxnType.READ_PROMOTE) ;
+        assumeTrue(supportsPromote());
+        Dataset ds = create();
+        ds.begin(TxnType.READ_PROMOTE);
         assertEquals(TxnType.READ_PROMOTE, ds.transactionType());
-        assertTrue(ds.isInTransaction()) ;
+        assertTrue(ds.isInTransaction());
         assertEquals(ReadWrite.READ, ds.transactionMode());
         ds.promote();
         assertEquals(ReadWrite.WRITE, ds.transactionMode());
@@ -178,14 +176,14 @@ public abstract class AbstractTestTransactionLifecycle 
extends BaseTest
     
     @Test
     public void transaction_p02() {
-        assumeTrue(supportsPromote()) ;
-        Dataset ds = create() ;
-        ds.begin(TxnType.READ_COMMITTED_PROMOTE) ;
+        assumeTrue(supportsPromote());
+        Dataset ds = create();
+        ds.begin(TxnType.READ_COMMITTED_PROMOTE);
         assertEquals(TxnType.READ_COMMITTED_PROMOTE, ds.transactionType());
-        assertTrue(ds.isInTransaction()) ;
+        assertTrue(ds.isInTransaction());
         assertEquals(ReadWrite.READ, ds.transactionMode());
         boolean b = ds.promote();
-        assertTrue(b) ;
+        assertTrue(b);
         assertEquals(ReadWrite.WRITE, ds.transactionMode());
         ds.commit();
         ds.end();
@@ -193,72 +191,151 @@ public abstract class AbstractTestTransactionLifecycle 
extends BaseTest
     
     @Test
     public void transaction_p03() {
-        assumeTrue(supportsPromote()) ;
-        Dataset ds = create() ;
-        ds.begin(TxnType.READ_PROMOTE) ;
-        assertTrue(ds.isInTransaction()) ;
+        assumeTrue(supportsPromote());
+        Dataset ds = create();
+        ds.begin(TxnType.READ_PROMOTE);
+        assertTrue(ds.isInTransaction());
         assertEquals(ReadWrite.READ, ds.transactionMode());
         boolean b = ds.promote();
-        assertTrue(b) ;
+        assertTrue(b);
         assertEquals(ReadWrite.WRITE, ds.transactionMode());
         ds.abort();
         ds.end();
-        assertFalse(ds.isInTransaction()) ;
+        assertFalse(ds.isInTransaction());
     }
 
     @Test
     public void transaction_p04() {
-        assumeTrue(supportsPromote()) ;
-        Dataset ds = create() ;
-        ds.begin(TxnType.READ_COMMITTED_PROMOTE) ;
-        assertTrue(ds.isInTransaction()) ;
+        assumeTrue(supportsPromote());
+        Dataset ds = create();
+        ds.begin(TxnType.READ_COMMITTED_PROMOTE);
+        assertTrue(ds.isInTransaction());
         assertEquals(ReadWrite.READ, ds.transactionMode());
         boolean b = ds.promote();
-        assertTrue(b) ;
+        assertTrue(b);
         assertEquals(ReadWrite.WRITE, ds.transactionMode());
         ds.abort();
         ds.end();
-        assertFalse(ds.isInTransaction()) ;
+        assertFalse(ds.isInTransaction());
     }
 
     @Test
     public void transaction_p05() {
-        assumeTrue(supportsPromote()) ;
-        Dataset ds = create() ;
-        ds.begin(TxnType.READ_COMMITTED_PROMOTE) ;
-        assertTrue(ds.isInTransaction()) ;
+        assumeTrue(supportsPromote());
+        Dataset ds = create();
+        ds.begin(TxnType.READ_COMMITTED_PROMOTE);
+        assertTrue(ds.isInTransaction());
         boolean b1 = ds.promote();
-        assertTrue(b1) ;
+        assertTrue(b1);
         boolean b2 = ds.promote();
-        assertTrue(b2) ;
+        assertTrue(b2);
         ds.commit();
         ds.end();
     }
     
+    @Test
+    public void transaction_p06_err() {
+        assumeTrue(supportsPromote());
+        Dataset ds = create();
+        ds.begin(TxnType.READ);
+        assertTrue(ds.isInTransaction());
+        boolean b1 = ds.promote();
+        assertFalse(b1);
+        boolean b2 = ds.promote();
+        assertFalse(b2);
+        ds.end();
+    }
+
+    
     // JENA-1469
     @Test
-    public void transaction_p06() {
+    public void transaction_p10() {
         transaction_promote_write(TxnType.READ_COMMITTED_PROMOTE);
     }
 
     @Test
-    public void transaction_p07() {
+    public void transaction_p11() {
         transaction_promote_write(TxnType.READ_PROMOTE);
     }
 
-    @Test(expected=JenaException.class)
-    public void transaction_err_read_promote() {
-        assumeTrue(supportsPromote()) ;
-        Dataset ds = create() ;
-        ds.begin(TxnType.READ) ;
-        boolean b = ds.promote();   // Illgeal.
-        assertFalse(b) ;
+    // XXX Refactor the above code.
+    
+    // promotion tyope specified
+    private void testPromote(TxnType txnType , Promote promoteMode, boolean 
succeeds) {
+        Dataset ds = create();
+        ds.begin(txnType);
+        assertTrue(ds.isInTransaction());
+        boolean b1 = ds.promote(promoteMode);
+        assertEquals(succeeds, b1);
+        boolean b2 = ds.promote(promoteMode);
+        assertEquals("Try same promote again", b1, b2);
+        ds.commit();
+        ds.end();
+        
+    }
+    
+    @Test
+    public void transaction_promote_write_isolated() {
+        assumeTrue(supportsPromote());
+        testPromote(TxnType.WRITE, Promote.ISOLATED, true);
+    }
+    
+    @Test
+    public void transaction_promote_write_readCommitted() {
+        assumeTrue(supportsPromote());
+        testPromote(TxnType.WRITE, Promote.READ_COMMITTED, true);
+    }
+        
+    @Test
+    public void transaction_promote_read_isolated() {
+        assumeTrue(supportsPromote());
+        testPromote(TxnType.READ, Promote.ISOLATED, false);
+    }
+    
+    @Test
+    public void transaction_promote_read_readCommitted() {
+        assumeTrue(supportsPromote());
+        testPromote(TxnType.READ, Promote.READ_COMMITTED, false);
+    }
+        
+    @Test
+    public void transaction_promote_readPromote_isolated() {
+        assumeTrue(supportsPromote());
+        testPromote(TxnType.READ_PROMOTE, Promote.ISOLATED, true);
+    }
+    
+    @Test
+    public void transaction_promote_readPromote_committed() {
+        assumeTrue(supportsPromote());
+        testPromote(TxnType.READ_PROMOTE, Promote.READ_COMMITTED, true);
+    }
+        
+    @Test
+    public void transaction_promote_readCommitted_isolated() {
+        assumeTrue(supportsPromote());
+        testPromote(TxnType.READ_COMMITTED_PROMOTE, Promote.ISOLATED, true);
+    }
+    
+    @Test
+    public void transaction_promote_readCommitted_readCommitted() {
+        assumeTrue(supportsPromote());
+        testPromote(TxnType.READ_COMMITTED_PROMOTE, Promote.READ_COMMITTED, 
true);
+    }
+        
+    
+    @Test
+    public void transaction_read_promote() {
+        assumeTrue(supportsPromote());
+        Dataset ds = create();
+        ds.begin(TxnType.READ);
+        boolean b = ds.promote();   // Fails
+        assertFalse(b);
         ds.commit();
         ds.end();
     }
 
     private void transaction_promote_write(TxnType txnType) {
-        Dataset ds = create() ;
+        Dataset ds = create();
         ds.begin(txnType);
         ds.promote();
         ds.commit();
@@ -271,33 +348,33 @@ public abstract class AbstractTestTransactionLifecycle 
extends BaseTest
     // Patterns.
     @Test
     public void transaction_pattern_01() {
-        Dataset ds = create() ;
-        read1(ds) ;
-        read1(ds) ;
+        Dataset ds = create();
+        read1(ds);
+        read1(ds);
     }
 
     @Test
     public void transaction_pattern_02() {
-        Dataset ds = create() ;
-        read2(ds) ;
-        read2(ds) ;
+        Dataset ds = create();
+        read2(ds);
+        read2(ds);
     }
 
     @Test
     public void transaction_pattern_03() {
-        Dataset ds = create() ;
-        write(ds) ;
-        write(ds) ;
+        Dataset ds = create();
+        write(ds);
+        write(ds);
     }
 
     @Test
     public void transaction_pattern_04() {
-        Dataset ds = create() ;
-        write(ds) ;
-        read2(ds) ;
-        read2(ds) ;
-        write(ds) ;
-        read2(ds) ;
+        Dataset ds = create();
+        write(ds);
+        read2(ds);
+        read2(ds);
+        write(ds);
+        read2(ds);
     }
     
     // Cycle misalignment.
@@ -307,177 +384,177 @@ public abstract class AbstractTestTransactionLifecycle 
extends BaseTest
     
     @Test(expected=JenaTransactionException.class)
     public void transaction_err_nontxn_commit_1() { 
-        Dataset ds = create() ;
-        ds.commit() ;
+        Dataset ds = create();
+        ds.commit();
     }    
     
     @Test(expected=JenaTransactionException.class)
     public void transaction_err_nontxn_commit_2() { 
-        Dataset ds = create() ;
-        ds.begin(READ) ;
-        ds.end() ;
-        ds.commit() ;
+        Dataset ds = create();
+        ds.begin(TxnType.READ);
+        ds.end();
+        ds.commit();
     }    
     
     @Test(expected=JenaTransactionException.class)
     public void transaction_err_nontxn_commit_3() { 
-        Dataset ds = create() ;
-        ds.begin(WRITE) ;
-        ds.end() ;
-        ds.commit() ;
+        Dataset ds = create();
+        ds.begin(TxnType.WRITE);
+        ds.end();
+        ds.commit();
     }    
 
     @Test(expected=JenaTransactionException.class)
     public void transaction_err_nontxn_abort_1() { 
-        Dataset ds = create() ;
-        ds.abort() ;
+        Dataset ds = create();
+        ds.abort();
     }    
 
     @Test(expected=JenaTransactionException.class)
     public void transaction_err_nontxn_abort_2() { 
-        Dataset ds = create() ;
-        ds.begin(READ) ;
-        ds.end() ;
-        ds.abort() ;
+        Dataset ds = create();
+        ds.begin(TxnType.READ);
+        ds.end();
+        ds.abort();
     }    
 
     @Test(expected=JenaTransactionException.class)
     public void transaction_err_nontxn_abort_3() { 
-        Dataset ds = create() ;
-        ds.begin(WRITE) ;
-        ds.end() ;
-        ds.abort() ;
+        Dataset ds = create();
+        ds.begin(TxnType.WRITE);
+        ds.end();
+        ds.abort();
     }    
     
     @Test
-    public void transaction_err_01()    { testBeginBegin(WRITE, WRITE) ; }
+    public void transaction_err_01()    { testBeginBegin(TxnType.WRITE, 
TxnType.WRITE); }
 
     @Test
-    public void transaction_err_02()    { testBeginBegin(WRITE, READ) ; }
+    public void transaction_err_02()    { testBeginBegin(TxnType.WRITE, 
TxnType.READ); }
 
     @Test
-    public void transaction_err_03()    { testBeginBegin(READ, READ) ; }
+    public void transaction_err_03()    { testBeginBegin(TxnType.READ, 
TxnType.READ); }
 
     @Test
-    public void transaction_err_04()    { testBeginBegin(READ, WRITE) ; }
+    public void transaction_err_04()    { testBeginBegin(TxnType.READ, 
TxnType.WRITE); }
 
     @Test 
-    public void transaction_err_05()    { testCommitCommit(READ) ; }
+    public void transaction_err_05()    { testCommitCommit(TxnType.READ); }
 
     @Test 
-    public void transaction_err_06()    { testCommitCommit(WRITE) ; }
+    public void transaction_err_06()    { testCommitCommit(TxnType.WRITE); }
 
     @Test 
-    public void transaction_err_07()    { testCommitAbort(READ) ; }
+    public void transaction_err_07()    { testCommitAbort(TxnType.READ); }
 
     @Test 
-    public void transaction_err_08()    { testCommitAbort(WRITE) ; }
+    public void transaction_err_08()    { testCommitAbort(TxnType.WRITE); }
 
     @Test 
-    public void transaction_err_09()    { testAbortAbort(READ) ; }
+    public void transaction_err_09()    { testAbortAbort(TxnType.READ); }
 
     @Test 
-    public void transaction_err_10()    { testAbortAbort(WRITE) ; }
+    public void transaction_err_10()    { testAbortAbort(TxnType.WRITE); }
 
     @Test 
-    public void transaction_err_11()    { testAbortCommit(READ) ; }
+    public void transaction_err_11()    { testAbortCommit(TxnType.READ); }
 
     @Test 
-    public void transaction_err_12()    { testAbortCommit(WRITE) ; }
+    public void transaction_err_12()    { testAbortCommit(TxnType.WRITE); }
 
     private void read1(Dataset ds) {
-        ds.begin(TxnType.READ) ;
-        assertTrue(ds.isInTransaction()) ;
-        ds.commit() ;
-        assertFalse(ds.isInTransaction()) ;
-        ds.end() ;
+        ds.begin(TxnType.READ);
+        assertTrue(ds.isInTransaction());
+        ds.commit();
+        assertFalse(ds.isInTransaction());
+        ds.end();
     }
 
     private void read2(Dataset ds) {
-        ds.begin(TxnType.READ) ;
-        assertTrue(ds.isInTransaction()) ;
-        ds.end() ;
-        assertFalse(ds.isInTransaction()) ;
+        ds.begin(TxnType.READ);
+        assertTrue(ds.isInTransaction());
+        ds.end();
+        assertFalse(ds.isInTransaction());
     }
 
     private void write(Dataset ds) {
-        ds.begin(TxnType.WRITE) ;
-        assertTrue(ds.isInTransaction()) ;
-        ds.commit() ;
-        assertFalse(ds.isInTransaction()) ;
-        ds.end() ;
+        ds.begin(TxnType.WRITE);
+        assertTrue(ds.isInTransaction());
+        ds.commit();
+        assertFalse(ds.isInTransaction());
+        ds.end();
     }
 
     private static void safeEnd(Dataset ds) {
-        try { ds.end() ; } catch (JenaTransactionException ex) {}
+        try { ds.end(); } catch (JenaTransactionException ex) {}
     }
     
     // Error conditions that should be detected.
 
     private void testBeginBegin(TxnType txnType1, TxnType txnType2) {
-        Dataset ds = create() ;
-        ds.begin(txnType1) ;
+        Dataset ds = create();
+        ds.begin(txnType1);
         try {
-            ds.begin(txnType2) ;
-            fail("Expected transaction exception - begin-begin (" + txnType1 + 
", " + txnType2 + ")") ;
+            ds.begin(txnType2);
+            fail("Expected transaction exception - begin-begin (" + txnType1 + 
", " + txnType2 + ")");
         }
         catch (JenaTransactionException ex) {
-            safeEnd(ds) ;
+            safeEnd(ds);
         }
     }
     
     private void testCommitCommit(TxnType txnType) {
-        Dataset ds = create() ;
-        ds.begin(txnType) ;
-        ds.commit() ;
+        Dataset ds = create();
+        ds.begin(txnType);
+        ds.commit();
         try {
-            ds.commit() ;
-            fail("Expected transaction exception - commit-commit(" + txnType + 
")") ;
+            ds.commit();
+            fail("Expected transaction exception - commit-commit(" + txnType + 
")");
         }
         catch (JenaTransactionException ex) {
-            safeEnd(ds) ;
+            safeEnd(ds);
         }
     }
 
     private void testCommitAbort(TxnType txnType) {
-        assumeTrue(supportsAbort()) ;
-        Dataset ds = create() ;
-        ds.begin(txnType) ;
-        ds.commit() ;
+        assumeTrue(supportsAbort());
+        Dataset ds = create();
+        ds.begin(txnType);
+        ds.commit();
         try {
-            ds.abort() ;
-            fail("Expected transaction exception - commit-abort(" + txnType + 
")") ;
+            ds.abort();
+            fail("Expected transaction exception - commit-abort(" + txnType + 
")");
         }
         catch (JenaTransactionException ex) {
-            safeEnd(ds) ;
+            safeEnd(ds);
         }
     }
 
     private void testAbortAbort(TxnType txnType) {
-        assumeTrue(supportsAbort()) ;
-        Dataset ds = create() ;
-        ds.begin(txnType) ;
-        ds.abort() ;
+        assumeTrue(supportsAbort());
+        Dataset ds = create();
+        ds.begin(txnType);
+        ds.abort();
         try {
-            ds.abort() ;
-            fail("Expected transaction exception - abort-abort(" + txnType + 
")") ;
+            ds.abort();
+            fail("Expected transaction exception - abort-abort(" + txnType + 
")");
         }
         catch (JenaTransactionException ex) {
-            ds.end() ;
+            ds.end();
         }
     }
 
     private void testAbortCommit(TxnType txnType) {
-        assumeTrue(supportsAbort()) ;
-        Dataset ds = create() ;
-        ds.begin(txnType) ;
-        ds.abort() ;
+        assumeTrue(supportsAbort());
+        Dataset ds = create();
+        ds.begin(txnType);
+        ds.abort();
         try {
-            ds.commit() ;
-            fail("Expected transaction exception - abort-commit(" + txnType + 
")") ;
+            ds.commit();
+            fail("Expected transaction exception - abort-commit(" + txnType + 
")");
         }
         catch (JenaTransactionException ex) {
-            safeEnd(ds) ;
+            safeEnd(ds);
         }
     }
 
@@ -485,20 +562,20 @@ public abstract class AbstractTestTransactionLifecycle 
extends BaseTest
     @Test
     public synchronized void transaction_concurrency_writer() throws 
InterruptedException, ExecutionException, TimeoutException {
         ExecutorService executor = Executors.newFixedThreadPool(2);
-        AtomicLong counter = new AtomicLong(0) ;
+        AtomicLong counter = new AtomicLong(0);
         try {
-            final Dataset ds = create() ;
+            final Dataset ds = create();
 
             Callable<Boolean> callable = new Callable<Boolean>() {
 
                 @Override
                 public Boolean call() {
                     ds.begin(TxnType.WRITE);
-                    long x = counter.incrementAndGet() ;
+                    long x = counter.incrementAndGet();
                     // Hold the lock for a short while.
                     // The W threads will take the sleep serially.
-                    Lib.sleep(500) ;
-                    long x1 = counter.get() ;
+                    Lib.sleep(500);
+                    long x1 = counter.get();
                     assertEquals("Two writers in the transaction", x, x1);
                     ds.commit();
                     return true;
@@ -519,18 +596,18 @@ public abstract class AbstractTestTransactionLifecycle 
extends BaseTest
     @Test
     public synchronized void transaction_concurrency_reader() throws 
InterruptedException, ExecutionException, TimeoutException {
         ExecutorService executor = Executors.newCachedThreadPool();
-        AtomicLong counter = new AtomicLong(0) ;
+        AtomicLong counter = new AtomicLong(0);
         
         try {
-            final Dataset ds = create() ;
+            final Dataset ds = create();
 
             Callable<Boolean> callable = new Callable<Boolean>() {
                 @Override
                 public Boolean call() {
                     ds.begin(TxnType.READ);
-                    long x = counter.incrementAndGet() ;
+                    long x = counter.incrementAndGet();
                     // Hold the lock for a few seconds - these should be in 
parallel.
-                    Lib.sleep(1000) ;
+                    Lib.sleep(1000);
                     ds.commit();
                     return true;
                 }

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-arq/src/test/java/org/apache/jena/sparql/util/TestDyadicDatasetGraph.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/test/java/org/apache/jena/sparql/util/TestDyadicDatasetGraph.java
 
b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestDyadicDatasetGraph.java
index 0113c46..ea83c75 100644
--- 
a/jena-arq/src/test/java/org/apache/jena/sparql/util/TestDyadicDatasetGraph.java
+++ 
b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestDyadicDatasetGraph.java
@@ -25,6 +25,7 @@ import org.apache.jena.graph.Node;
 import org.apache.jena.graph.NodeFactory;
 import org.apache.jena.query.ReadWrite;
 import org.apache.jena.query.TxnType;
+import org.apache.jena.sparql.JenaTransactionException;
 import org.apache.jena.sparql.core.DatasetGraph;
 import org.apache.jena.sparql.core.DatasetGraphZero;
 import org.junit.Test;
@@ -126,52 +127,75 @@ public abstract class TestDyadicDatasetGraph extends 
BaseTest {
         emptyDsg().getGraph(graphName).remove(null, null, null);
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    // Read lifecycle.
+    @Test
+    public void txnRead1() {
+        final DatasetGraph dsg = emptyDsg();
+        assertFalse(dsg.isInTransaction());
+        dsg.begin(ReadWrite.READ);
+        assertTrue(dsg.isInTransaction());
+        dsg.commit();
+        dsg.end();
+    }
+    
+    @Test
+    public void txnRead2() {
+        final DatasetGraph dsg = emptyDsg();
+        assertFalse(dsg.isInTransaction());
+        dsg.begin(ReadWrite.READ);
+        assertTrue(dsg.isInTransaction());
+        dsg.end();
+    }
+    
+    @Test
+    public void txnRead3() {
+        final DatasetGraph dsg = emptyDsg();
+        assertFalse(dsg.isInTransaction());
+        dsg.begin();
+        assertTrue(dsg.isInTransaction());
+        assertEquals(ReadWrite.READ, dsg.transactionMode());
+        assertEquals(TxnType.READ, dsg.transactionType());
+        dsg.end();
+    }
+    
+    @Test(expected = JenaTransactionException.class)
     public void noWriting1() {
         emptyDsg().begin(ReadWrite.WRITE);
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test(expected = JenaTransactionException.class)
     public void noWriting2() {
         emptyDsg().begin(TxnType.WRITE);
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test(expected = JenaTransactionException.class)
     public void noWriting3() {
         emptyDsg().begin(TxnType.READ_PROMOTE);
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test(expected = JenaTransactionException.class)
     public void noWriting4() {
         emptyDsg().begin(TxnType.READ_COMMITTED_PROMOTE);
     }
     
     @Test
     public void noPromoting() {
-        assertFalse(emptyDsg().promote());
-    }
-
-    @Test(expected = UnsupportedOperationException.class)
-    public void noCommitting() {
         final DatasetGraph dsg = emptyDsg();
-        assertFalse(dsg.isInTransaction());
+        // Dynadic datasets are read-only.
         dsg.begin(ReadWrite.READ);
-        assertTrue(dsg.isInTransaction());
-        dsg.commit();
+        boolean b = dsg.promote();
+        assertFalse(b);
     }
-    
+
     @Test
     public void testTransactionTypeAndMode() {
         final DatasetGraph dsg = emptyDsg();
         assertFalse(dsg.isInTransaction());
-        try {
-            dsg.begin(TxnType.READ);
-            assertTrue(dsg.isInTransaction());
-            assertEquals(TxnType.READ, dsg.transactionType());
-            assertEquals(ReadWrite.READ, dsg.transactionMode());
-        } finally {
-            dsg.end();
-        }
+        dsg.begin(TxnType.READ);
+        assertTrue(dsg.isInTransaction());
+        assertEquals(TxnType.READ, dsg.transactionType());
+        assertEquals(ReadWrite.READ, dsg.transactionMode());
+        dsg.end();
         assertFalse(dsg.isInTransaction());
     }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java 
b/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
index e7c59b1..18b2188 100644
--- a/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
+++ b/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
@@ -76,7 +76,7 @@ public class JenaSystem {
         // The same thread will not stop at the lock.
         // Set initialized to true before a recursive call is possible
         // handles this.  The recursive call will see initialized true and
-        // and returnn on the first test.
+        // and return on the first test.
 
         // Net effect:
         // After a top level call of JenaSystem.init() returns, tjena has

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/Transaction.java
----------------------------------------------------------------------
diff --git 
a/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/Transaction.java
 
b/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/Transaction.java
index 7144fda..97eac5a 100644
--- 
a/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/Transaction.java
+++ 
b/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/Transaction.java
@@ -107,17 +107,20 @@ public class Transaction implements TransactionInfo {
         setState(ACTIVE) ;
     }
     
+    private boolean promoteReadCommitted() {
+        if ( txnType == TxnType.READ_COMMITTED_PROMOTE ) return true;
+        if ( txnType == TxnType.READ_PROMOTE ) return false;
+        return false;
+    }
+    
     public boolean promote() {
-        checkState(ACTIVE);
-        boolean b = txnMgr.promoteTxn(this) ;
-        if ( !b )
-            return false ;
-        mode = ReadWrite.WRITE;
-        return true ;
+        return promote(promoteReadCommitted());
     }
     
     public boolean promote(boolean readCommitted) {
         checkState(ACTIVE);
+        if ( txnType == TxnType.READ )
+            return false;
         boolean b = txnMgr.promoteTxn(this, readCommitted) ;
         if ( !b )
             return false ;
@@ -137,8 +140,7 @@ public class Transaction implements TransactionInfo {
     public void notifyUpdate() {
         checkState(ACTIVE) ;
         if ( mode == ReadWrite.READ ) {
-            System.err.println("notifyUpdate - promote needed") ;
-            promote() ;
+            promote(promoteReadCommitted()) ;
             mode = ReadWrite.WRITE ;
         }
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionCoordinator.java
----------------------------------------------------------------------
diff --git 
a/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionCoordinator.java
 
b/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionCoordinator.java
index 81d3100..e4431cb 100644
--- 
a/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionCoordinator.java
+++ 
b/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionCoordinator.java
@@ -28,7 +28,6 @@ import java.util.concurrent.atomic.AtomicLong ;
 import java.util.concurrent.locks.ReadWriteLock ;
 import java.util.concurrent.locks.ReentrantReadWriteLock ;
 
-import org.apache.jena.atlas.lib.InternalErrorException;
 import org.apache.jena.atlas.logging.Log ;
 import org.apache.jena.dboe.base.file.Location;
 import org.apache.jena.dboe.sys.Sys;
@@ -275,14 +274,13 @@ public class TransactionCoordinator {
             throw new TransactionException("TransactionCoordinator has already 
been started") ;
     }
 
-    // Are we up and ruuning?
+    // Is this TransactionCoordinator up and running?
     private void checkActive() {
         if ( ! coordinatorStarted )
             throw new TransactionException("TransactionCoordinator has not 
been started") ;
         checkNotShutdown();
     }
 
-    // Check not wrapped up
     private void checkNotShutdown() {
         if ( coordinatorLock == null )
             throw new TransactionException("TransactionCoordinator has been 
shutdown") ;
@@ -382,7 +380,6 @@ public class TransactionCoordinator {
      * 
      * @see #tryBlockWriters()
      * @see #enableWriters()
-     * 
      */
     public void blockWriters() {
         acquireWriterLock(true) ;
@@ -396,7 +393,7 @@ public class TransactionCoordinator {
      *  
      * @see #blockWriters()
      * @see #enableWriters()
-
+     *
      * @return true if the operation succeeded and writers are blocked 
      */
     public boolean tryBlockWriters() {
@@ -559,42 +556,6 @@ public class TransactionCoordinator {
         return cg ;
     }
 
-//    /** Is promotion of transactions enabled? */ 
-//    /*private*/public/*for development*/ static boolean promotion            
   = true ;
-//    
-//    /** Control of whether a transaction promotion can see any commits that
-//     *  happened between this transaction starting and it promoting.
-//     *  A form of "ReadCommitted".   
-//     */
-//    /*private*/public/*for development*/ static boolean 
readCommittedPromotion  = false ;
-    
-    /** Whether to wait for writers when trying to promote */
-    private static final boolean promotionWaitForWriters = true;
-
-    /** Attempt to promote a transaction from READ mode to WRITE mode based on 
its declared start type.
-     * Return true if the transaction is already a writer.
-     */
-    /*package*/ boolean promoteTxn(Transaction transaction) {
-        if ( transaction.getMode() == ReadWrite.WRITE )
-            return true ;
-        if ( transaction.getTxnType() == TxnType.READ )
-            throw new TransactionException("promote: can't promote a READ 
transaction") ;
-        
-        if ( transaction.getTxnType() != TxnType.READ_COMMITTED_PROMOTE && 
-             transaction.getTxnType() != TxnType.READ_PROMOTE )
-            throw new InternalErrorException("Transaction type is 
"+transaction.getTxnType());
-        
-        // Has there been an writer active since the transaction started?
-        // Do a test outside the lock - only dataVaersion can change and that 
increases.
-        // If "read commited transactions" not allowed, the data has changed 
in a way we
-        // do no twish to expose.
-        // If this test fails outside the lock it will fail inside.
-        // If it passes, we have to test again in case there is an active 
writer.
-        
-        boolean readCommittedPromotion = transaction.getTxnType() == 
TxnType.READ_COMMITTED_PROMOTE;
-        return promoteTxn$(transaction, readCommittedPromotion);
-    }
-    
     /** Attempt to promote a transaction from READ mode to WRITE mode based.
      *  Whether intevening commits are seen is determined by the boolean flag.
      * Return true if the transaction is already a writer.
@@ -602,7 +563,8 @@ public class TransactionCoordinator {
     /*package*/ boolean promoteTxn(Transaction transaction, boolean 
readCommittedPromotion) {
         if ( transaction.getMode() == ReadWrite.WRITE )
             return true ;
-        // XXX Not sure what the right choice is.
+        // While this code allows promotion of TxnType.READ, this ability is 
usually rejected
+        // by the transaction system around it. e.g. TransactionalBase.
         if ( transaction.getTxnType() == TxnType.READ )
             throw new TransactionException("promote: can't promote a READ 
transaction") ;
         return promoteTxn$(transaction, readCommittedPromotion);
@@ -680,6 +642,9 @@ public class TransactionCoordinator {
         return true;
     }
     
+    /** Whether to wait for writers when trying to promote */
+    private static final boolean promotionWaitForWriters = true;
+
     private boolean promotionWaitForWriters() {
         if ( promotionWaitForWriters )
             return acquireWriterLock(true) ;
@@ -841,4 +806,3 @@ public class TransactionCoordinator {
 
     public long countFinished()     { return countFinished.get() ; }
 }
-

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionalBase.java
----------------------------------------------------------------------
diff --git 
a/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionalBase.java
 
b/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionalBase.java
index 5dd6e86..1f1266f 100644
--- 
a/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionalBase.java
+++ 
b/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionalBase.java
@@ -20,7 +20,6 @@ package org.apache.jena.dboe.transaction.txn;
 
 import java.util.Objects ;
 
-import org.apache.jena.atlas.lib.InternalErrorException;
 import org.apache.jena.atlas.lib.Lib;
 import org.apache.jena.atlas.logging.Log ;
 import org.apache.jena.query.ReadWrite ;
@@ -95,12 +94,12 @@ public class TransactionalBase implements 
TransactionalSystem {
         if ( trackAttachDetach )
             Log.info(this,  "<< attach");
     } 
-    
-  @Override
-  public final void begin(ReadWrite readWrite) { 
-      begin(TxnType.convert(readWrite));
-  }
-    
+
+    @Override
+    public final void begin(ReadWrite readWrite) { 
+        begin(TxnType.convert(readWrite));
+    }
+
     @Override
     public final void begin(TxnType txnType) {
         Objects.nonNull(txnType) ;
@@ -109,21 +108,18 @@ public class TransactionalBase implements 
TransactionalSystem {
         Transaction transaction = txnMgr.begin(txnType) ;
         theTxn.set(transaction) ;
     }
-    
+
     @Override
     public final boolean promote() {
-        checkActive() ;
-        Transaction txn = getValidTransaction() ;
-        return txn.promote() ;
+        checkActive();
+        return TransactionalSystem.super.promote();
     }
 
+    
     @Override
-    public final boolean promote(TxnType txnType) {
+    public final boolean promote(Promote promoteMode) {
         checkActive() ;
-        if ( txnType != TxnType.READ_COMMITTED_PROMOTE && 
-             txnType != TxnType.READ_PROMOTE )
-           throw new InternalErrorException("Transaction type is not 
"+TxnType.READ_PROMOTE+ " nor "+TxnType.READ_COMMITTED_PROMOTE);
-        boolean readCommitted = (txnType == TxnType.READ_COMMITTED_PROMOTE) ;
+        boolean readCommitted = (promoteMode == Promote.READ_COMMITTED);
         Transaction txn = getValidTransaction() ;
         return txn.promote(readCommitted) ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-db/jena-dboe-transaction/src/test/java/org/apache/jena/dboe/transaction/TestTransactionLifecycle.java
----------------------------------------------------------------------
diff --git 
a/jena-db/jena-dboe-transaction/src/test/java/org/apache/jena/dboe/transaction/TestTransactionLifecycle.java
 
b/jena-db/jena-dboe-transaction/src/test/java/org/apache/jena/dboe/transaction/TestTransactionLifecycle.java
index 72230a0..85baebd 100644
--- 
a/jena-db/jena-dboe-transaction/src/test/java/org/apache/jena/dboe/transaction/TestTransactionLifecycle.java
+++ 
b/jena-db/jena-dboe-transaction/src/test/java/org/apache/jena/dboe/transaction/TestTransactionLifecycle.java
@@ -234,9 +234,8 @@ public class TestTransactionLifecycle extends 
AbstractTestTxn {
     
     @Test public void txn_read_promote_commit() {
         unit.begin(TxnType.READ);
-        try { unit.promote(); fail(); }
-        // Exception is correct - it is illegal to call promote in a 
TxnType.READ 
-        catch (TransactionException ex) { /* Expected : can continue */ }
+        boolean b = unit.promote();
+        assertFalse(b);
         unit.end() ;
         checkClear() ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-db/jena-dboe-transaction/src/test/java/org/apache/jena/dboe/transaction/TestTransactionLifecycle2.java
----------------------------------------------------------------------
diff --git 
a/jena-db/jena-dboe-transaction/src/test/java/org/apache/jena/dboe/transaction/TestTransactionLifecycle2.java
 
b/jena-db/jena-dboe-transaction/src/test/java/org/apache/jena/dboe/transaction/TestTransactionLifecycle2.java
index 4fe50a2..94c38f1 100644
--- 
a/jena-db/jena-dboe-transaction/src/test/java/org/apache/jena/dboe/transaction/TestTransactionLifecycle2.java
+++ 
b/jena-db/jena-dboe-transaction/src/test/java/org/apache/jena/dboe/transaction/TestTransactionLifecycle2.java
@@ -191,18 +191,25 @@ public class TestTransactionLifecycle2 {
         checkClear() ;
     }
     
-    @Test(expected=TransactionException.class)
+    @Test
     public void txn_promote_3() {
         Transaction txn1 = txnMgr.begin(TxnType.READ) ;
         boolean b = txn1.promote() ;
-        assertTrue(b) ;
+        assertFalse(b) ;
         b = txn1.promote() ;
-        assertTrue(b) ;
-        // Exception - now a writer
+        assertFalse(b) ;
+        // Not a writer
         txn1.end() ;
         checkClear() ;
     }
 
+    @Test(expected=TransactionException.class)
+    public void txn_promote_4() {
+        Transaction txn1 = txnMgr.begin(TxnType.READ) ;
+        txn1.end() ;
+        txn1.promote();
+    }
+
     //Not a @Test
     public void txn_promote_deadlock() {
         Transaction txn1 = txnMgr.begin(TxnType.READ) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/5f99f5f3/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/setup/AbstractTDBBuilder.java
----------------------------------------------------------------------
diff --git 
a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/setup/AbstractTDBBuilder.java
 
b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/setup/AbstractTDBBuilder.java
index eb78123..6bcb2f5 100644
--- 
a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/setup/AbstractTDBBuilder.java
+++ 
b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/setup/AbstractTDBBuilder.java
@@ -36,7 +36,7 @@ import org.apache.jena.dboe.transaction.txn.journal.Journal;
 import org.apache.jena.sparql.engine.main.QC;
 import org.apache.jena.sparql.engine.optimizer.reorder.ReorderLib;
 import org.apache.jena.tdb2.TDBException;
-import org.apache.jena.tdb2.solver.OpExecutorTDB1;
+import org.apache.jena.tdb2.solver.OpExecutorTDB2;
 import org.apache.jena.tdb2.store.*;
 import org.apache.jena.tdb2.store.nodetable.NodeTable;
 import org.apache.jena.tdb2.store.nodetable.NodeTableCache;
@@ -103,7 +103,7 @@ public abstract class AbstractTDBBuilder {
         DatasetGraphTxn dsg = new DatasetGraphTDB(trans, 
                                                   tripleTable, quadTable, 
prefixes, 
                                                   ReorderLib.fixed(), 
location, params);
-        QC.setFactory(dsg.getContext(), OpExecutorTDB1.OpExecFactoryTDB);
+        QC.setFactory(dsg.getContext(), OpExecutorTDB2.OpExecFactoryTDB);
         txnCoord.start();
         return dsg;
     }

Reply via email to