Author: andy
Date: Sat Aug 24 16:23:06 2013
New Revision: 1517159

URL: http://svn.apache.org/r1517159
Log:
Remove custom exception.

Modified:
    
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphWithLock.java

Modified: 
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphWithLock.java
URL: 
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphWithLock.java?rev=1517159&r1=1517158&r2=1517159&view=diff
==============================================================================
--- 
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphWithLock.java
 (original)
+++ 
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphWithLock.java
 Sat Aug 24 16:23:06 2013
@@ -16,94 +16,76 @@
  * limitations under the License.
  */
 
-package com.hp.hpl.jena.sparql.core;
+package com.hp.hpl.jena.sparql.core ;
 
 import org.apache.jena.atlas.lib.Lib ;
 import org.apache.jena.atlas.lib.Sync ;
 
 import com.hp.hpl.jena.query.ReadWrite ;
-import com.hp.hpl.jena.shared.JenaException ;
 import com.hp.hpl.jena.sparql.JenaTransactionException ;
 import com.hp.hpl.jena.sparql.SystemARQ ;
 import com.hp.hpl.jena.sparql.util.Context ;
 
-/** A DatasetGraph that uses the dataset lock to give weak transactional 
behaviour.
- *  Only supports multiple-reader OR single-writer, and no transction abort.
- *  Transactions are not durable. 
+/**
+ * A DatasetGraph that uses the dataset lock to give weak transactional
+ * behaviour. Only supports multiple-reader OR single-writer, and no 
write-transction
+ * abort. Transactions are not durable.
  */
-public class DatasetGraphWithLock extends DatasetGraphTrackActive implements 
Sync
-{
-    static class JenaLockException extends JenaException
-    {
-        public JenaLockException()                                  { super(); 
}
-        public JenaLockException(String message)                    { 
super(message); }
-        public JenaLockException(Throwable cause)                   { 
super(cause) ; }
-        public JenaLockException(String message, Throwable cause)   { 
super(message, cause) ; }
-    }
-    
-    static class ThreadLocalBoolean extends ThreadLocal<Boolean>
-    {
-        @Override protected Boolean initialValue() {
+public class DatasetGraphWithLock extends DatasetGraphTrackActive implements 
Sync {
+    static class ThreadLocalBoolean extends ThreadLocal<Boolean> {
+        @Override
+        protected Boolean initialValue() {
             return false ;
         }
     }
-    
-    static class ThreadLocalReadWrite extends ThreadLocal<ReadWrite>
-    {
-        @Override protected ReadWrite initialValue() {
+
+    static class ThreadLocalReadWrite extends ThreadLocal<ReadWrite> {
+        @Override
+        protected ReadWrite initialValue() {
             return null ;
         }
     }
 
-    private final DatasetGraph dsg ;
-    private final ThreadLocalReadWrite readWrite = new ThreadLocalReadWrite() ;
-    private final ThreadLocalBoolean inTransaction = new ThreadLocalBoolean() ;
-
-    
+    private final DatasetGraph         dsg ;
+    private final ThreadLocalReadWrite readWrite     = new 
ThreadLocalReadWrite() ;
+    private final ThreadLocalBoolean   inTransaction = new 
ThreadLocalBoolean() ;
 
-    public DatasetGraphWithLock(DatasetGraph dsg)
-    {
+    public DatasetGraphWithLock(DatasetGraph dsg) {
         this.dsg = dsg ;
     }
 
     @Override
-    protected DatasetGraph get()
-    {
+    protected DatasetGraph get() {
         return dsg ;
     }
 
     @Override
-    protected void checkActive()
-    {
-        if ( ! isInTransaction() )
+    protected void checkActive() {
+        if ( !isInTransaction() )
             throw new JenaTransactionException("Not in a transaction") ;
     }
-    
+
     @Override
-    protected void checkNotActive()
-    {
+    protected void checkNotActive() {
         if ( isInTransaction() )
             throw new JenaTransactionException("Currently in a transaction") ;
     }
-    
+
     @Override
-    public boolean isInTransaction()    
-    { 
+    public boolean isInTransaction() {
         return inTransaction.get() ;
     }
 
     @Override
-    protected void _begin(ReadWrite readWrite)
-    {
+    protected void _begin(ReadWrite readWrite) {
         this.readWrite.set(readWrite) ;
-        boolean b = ( readWrite == ReadWrite.READ ) ;
+        boolean b = (readWrite == ReadWrite.READ) ;
         dsg.getLock().enterCriticalSection(b) ;
-        inTransaction.set(true) ; 
+        inTransaction.set(true) ;
     }
 
     @Override
-    protected void _commit()
-    {
+    protected void _commit() {
         if ( readWrite.get() == ReadWrite.WRITE )
             sync() ;
         dsg.getLock().leaveCriticalSection() ;
@@ -112,45 +94,42 @@ public class DatasetGraphWithLock extend
     }
 
     @Override
-    protected void _abort()
-    {
-        throw new JenaLockException("Can't abort a locked update") ;   
-        //dsg.getLock().leaveCriticalSection() ;
+    protected void _abort() {
+        // OK for read, not for write.
+        if ( readWrite.get() == ReadWrite.WRITE )
+            throw new JenaTransactionException("Can't abort a write 
lock-transaction") ;
+        _end() ;
     }
 
     @Override
-    protected void _end()
-    {
+    protected void _end() {
         if ( isInTransaction() )
             dsg.getLock().leaveCriticalSection() ;
         inTransaction.set(false) ;
     }
 
     @Override
-    protected void _close()
-    {
+    protected void _close() {
         if ( dsg != null )
             dsg.close() ;
     }
 
     @Override
-    public Context getContext()
-    {
+    public Context getContext() {
         return get().getContext() ;
     }
 
     @Override
-    public void sync()
-    {
+    public void sync() {
         SystemARQ.sync(dsg) ;
-        // ARQ 2.7.0 bug - fails to sync the default graph.
-        // When moving to 2.7.1 or later, remove the code line below. 
-        // And these comments. 
-        SystemARQ.sync(dsg.getDefaultGraph()) ;
-    }
-    
-    @Override 
-    public String toString() { 
-        try { return dsg.toString() ; } catch (Exception ex) { return 
Lib.className(this) ; }  
+    }
+
+    @Override
+    public String toString() {
+        try {
+            return dsg.toString() ;
+        } catch (Exception ex) {
+            return Lib.className(this) ;
+        }
     }
 }


Reply via email to