]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.acorn/src/org/simantics/acorn/lru/LRUObject.java
Fixing problems in the database unit testing environment with Acorn
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / lru / LRUObject.java
index a84a281089c289de2dbad32cd5dce6db359453ea..5230723b70b5bd25fc6b5e3a6ac5412c071615a1 100644 (file)
@@ -5,6 +5,7 @@ import java.nio.file.Path;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 
+import org.simantics.acorn.FileCache;
 import org.simantics.acorn.FileIO;
 import org.simantics.acorn.Persistable;
 import org.simantics.acorn.exception.AcornAccessVerificationException;
@@ -19,6 +20,7 @@ public abstract class LRUObject<MapKey, MapValue extends LRUObject<MapKey, MapVa
        
        // Final stuff
        final protected LRU<MapKey, MapValue> LRU;
+       final protected FileCache fileCache;
        final private Semaphore mutex = new Semaphore(1);
        final private MapKey key;
        final private String fileName;
@@ -39,8 +41,9 @@ public abstract class LRUObject<MapKey, MapValue extends LRUObject<MapKey, MapVa
        private Thread mutexOwner;
 
        // for loading
-       public LRUObject(LRU<MapKey, MapValue> LRU, MapKey key, Path readDirectory, String fileName, int offset, int length, boolean dirty, boolean resident) {
+       public LRUObject(LRU<MapKey, MapValue> LRU, FileCache fileCache, MapKey key, Path readDirectory, String fileName, int offset, int length, boolean dirty, boolean resident) {
                this.LRU = LRU;
+               this.fileCache = fileCache;
                this.key = key;
                this.fileName = fileName;
                this.offset = offset;
@@ -51,8 +54,8 @@ public abstract class LRUObject<MapKey, MapValue extends LRUObject<MapKey, MapVa
        }
 
        // for creating
-       public LRUObject(LRU<MapKey, MapValue> LRU, MapKey key, Path readDirectory, String fileName, boolean dirty, boolean resident) {
-               this(LRU, key, readDirectory, fileName, -1, -1, dirty, resident);
+       public LRUObject(LRU<MapKey, MapValue> LRU, FileCache fileCache, MapKey key, Path readDirectory, String fileName, boolean dirty, boolean resident) {
+               this(LRU, fileCache, key, readDirectory, fileName, -1, -1, dirty, resident);
        }
 
        /*
@@ -98,7 +101,7 @@ public abstract class LRUObject<MapKey, MapValue extends LRUObject<MapKey, MapVa
             Pair<byte[], Integer> pair = toBytes();
             byte[] data = pair.first;
             int length = pair.second;
-            FileIO fio = FileIO.get(bytes);
+            FileIO fio = fileCache.get(bytes);
             int offset = fio.saveBytes(data, length, overwrite());
             setPosition(offset, length);
         } catch (AcornAccessVerificationException | IllegalAcornStateException e) {
@@ -191,7 +194,7 @@ public abstract class LRUObject<MapKey, MapValue extends LRUObject<MapKey, MapVa
                if(VERIFY) verifyAccess();
                Path dir = getDirectory();
                Path f = dir.resolve(getFileName());
-               FileIO fio = FileIO.get(f);
+               FileIO fio = fileCache.get(f);
                return fio.readBytes(getOffset(), getLength());
        }