]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.acorn/src/org/simantics/acorn/internal/ClusterSupport2.java
Acorn: Fix WriteRunnable.runReally() and other fixes
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / internal / ClusterSupport2.java
index 7cd007ace0f8918a1a191c8fa7ca9abfbff4e392..b1b1e8365f22bd8da329284a344639add33093cd 100644 (file)
@@ -8,6 +8,8 @@ import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
 
 import org.simantics.acorn.ClusterManager;
+import org.simantics.acorn.exception.AcornAccessVerificationException;
+import org.simantics.acorn.exception.IllegalAcornStateException;
 import org.simantics.db.Session;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.ClusterBase;
@@ -82,7 +84,11 @@ public class ClusterSupport2 implements ClusterSupport, IClusterTable {
        
        @Override
        public int getClusterKeyByClusterUIDOrMake(ClusterUID clusterUID) {
-               return impl.getClusterKeyByClusterUIDOrMakeWithoutMutex(clusterUID);
+               try {
+            return impl.getClusterKeyByClusterUIDOrMakeWithoutMutex(clusterUID);
+        } catch (IllegalAcornStateException | AcornAccessVerificationException e) {
+            throw new RuntimeException(e);
+        }
        }
        
     @Override
@@ -185,14 +191,16 @@ public class ClusterSupport2 implements ClusterSupport, IClusterTable {
         }
     }
 
-    public ResourceSegment getResourceSegment(int resourceIndex, ClusterUID clusterUID, long offset, short size)
-    throws DatabaseException {
+    public ResourceSegment getResourceSegment(int resourceIndex, ClusterUID clusterUID, long offset, short size) throws DatabaseException {
         if (DEBUG)
             System.out.println("DEBUG: getResourceSegment ri=" + resourceIndex + " cid=" + clusterUID + " offset=" + offset + " size=" + size);
         
-        org.simantics.db.Database.Session.ResourceSegment t = impl.getResourceSegment(clusterUID.asBytes(), resourceIndex, offset, size);
-        return new ResourceSegment(t.getValueSize(), t.getSegment());
-        
+        try {
+            org.simantics.db.Database.Session.ResourceSegment t = impl.getResourceSegment(clusterUID.asBytes(), resourceIndex, offset, size);
+            return new ResourceSegment(t.getValueSize(), t.getSegment());
+        } catch (AcornAccessVerificationException | IllegalAcornStateException e) {
+            throw new DatabaseException(e);
+        }
     }
     
     protected byte[] getValueBig(ClusterBase cluster, int resourceIndex, int offset, int length) throws DatabaseException {
@@ -202,8 +210,11 @@ public class ClusterSupport2 implements ClusterSupport, IClusterTable {
        
        ClusterUID clusterUID = cluster.clusterUID;
        
-       return impl.getResourceFile(clusterUID.asBytes(), resourceIndex);
-       
+       try {
+            return impl.getResourceFile(clusterUID.asBytes(), resourceIndex);
+        } catch (AcornAccessVerificationException | IllegalAcornStateException e) {
+            throw new DatabaseException(e);
+        }
     }
 
     protected InputStream getValueStreamBig(ClusterBase cluster, final int resourceIndex, int offset, int length) throws DatabaseException {
@@ -247,7 +258,8 @@ public class ClusterSupport2 implements ClusterSupport, IClusterTable {
                @Override
                public int read() throws IOException {
 
-                       if(left <= 0) throw new IllegalStateException();
+                       if(left <= 0)
+                           throw new IOException("left <= 0 for " + _s);
 
                        if(offset == _s.bytes.length) {
                                short slen = (short)Math.min(left, IMAX);