You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2011/05/20 15:52:24 UTC

svn commit: r1125396 - in /incubator/jena/Experimental/TxTDB/trunk: src-dev/tx/ src-dev/tx/blockstream/ src/main/java/com/hp/hpl/jena/tdb/base/block/ src/main/java/com/hp/hpl/jena/tdb/base/file/ src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ src/ma...

Author: andy
Date: Fri May 20 13:52:23 2011
New Revision: 1125396

URL: http://svn.apache.org/viewvc?rev=1125396&view=rev
Log: (empty)

Added:
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestBlobStream.java   (with props)
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileAccessByteArray.java   (with props)
    incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractFileAccessFixedSizeTest.java   (with props)
    incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractFileAccessVarSizeTest.java   (with props)
    incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TestFileAccessByteArray.java   (with props)
    incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TestFileAccessMem.java   (with props)
Modified:
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/blockstream/BlockStreamDirect.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/block/Block.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileAccessMem.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileDiskDirect.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodecSSE.java
    incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TS_File.java

Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java?rev=1125396&r1=1125395&r2=1125396&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java Fri May 20 13:52:23 2011
@@ -3,6 +3,11 @@ package tx;
 
 public class DevTx
 {
+    // BlobStream.
+    //   Include "read() == read next"
+    // TestByteArray and up - exception tests.
+    
+    
     // Run tests with BlockMgrFactory.tracked on.
     // Test with overlapping iterators.
     

Added: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestBlobStream.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestBlobStream.java?rev=1125396&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestBlobStream.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestBlobStream.java Fri May 20 13:52:23 2011
@@ -0,0 +1,45 @@
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+package tx;
+
+import org.junit.Test ;
+import org.openjena.atlas.junit.BaseTest ;
+
+public class TestBlobStream extends BaseTest
+{
+    @Test public void blob_io_1()
+    {
+        
+    }
+}
+
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
\ No newline at end of file

Propchange: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestBlobStream.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/blockstream/BlockStreamDirect.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/blockstream/BlockStreamDirect.java?rev=1125396&r1=1125395&r2=1125396&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/blockstream/BlockStreamDirect.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/blockstream/BlockStreamDirect.java Fri May 20 13:52:23 2011
@@ -19,7 +19,8 @@ public class BlockStreamDirect extends F
 {
     private long length ;
     
-    // NoteTable I/O is much the same - reuse ObjectFileDiskDirect
+    // ObjectFileDiskDirect
+    // Use a FileAccess wrapper and delete ObjectFileDiskDirect
 
     public BlockStreamDirect(String filename)
     {

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/block/Block.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/block/Block.java?rev=1125396&r1=1125395&r2=1125396&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/block/Block.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/block/Block.java Fri May 20 13:52:23 2011
@@ -20,14 +20,14 @@ public final class Block
     private boolean modified = false ;
     
     private final ByteBuffer byteBuffer ;
-    private BlockType type ;
+//    private BlockType type ;
 
     public Block(int id, ByteBuffer byteBuffer)
     { 
         // ByteBuffer is whole disk space from byte 0 for this disk unit. 
         this.id = id ; 
         this.byteBuffer = byteBuffer ;
-        this.type = BlockType.UNDEF ;
+        //this.type = BlockType.UNDEF ;
         this.fileRef = null ;
         this.readOnly = false ;
         // Initially a block is not modified.
@@ -75,21 +75,49 @@ public final class Block
         return fileRef ;
     }
 
-    public void setType(BlockType blockType) 
-    {
-        type = blockType ;
-    }
-        
-    public BlockType getType()
-    {
-        return type ;
-    }
+//    public void setType(BlockType blockType) 
+//    {
+//        type = blockType ;
+//    }
+//        
+//    public BlockType getType()
+//    {
+//        return type ;
+//    }
     
     @Override
     public String toString()
     {
         return "Block: "+id+" : Length: "+byteBuffer.capacity() ;
     }
+    
+    public Block replicate()
+    {
+        ByteBuffer dstBuffer = replicate(getByteBuffer()) ;
+        Block b = new Block(getId(), dstBuffer) ;
+        return b ;
+    }  
+
+    public static void replicate(Block srcBlock, Block dstBlock)
+    {
+        if ( ! srcBlock.getId().equals(dstBlock.getId()) )
+            throw new BlockException("FileAccessMem: Attempt to copy across blocks: "+srcBlock.getId()+" => "+dstBlock.getId()) ;
+        replicate(srcBlock.getByteBuffer(), dstBlock.getByteBuffer()) ;
+    }  
+
+    private static ByteBuffer replicate(ByteBuffer srcBlk)
+    {
+        ByteBuffer dstBlk = ByteBuffer.allocate(srcBlk.capacity()) ;
+        System.arraycopy(srcBlk.array(), 0, dstBlk.array(), 0, srcBlk.capacity()) ;
+        return dstBlk ; 
+    }  
+
+    private static void replicate(ByteBuffer srcBlk, ByteBuffer dstBlk)
+    {
+        srcBlk.position(0) ;
+        dstBlk.position(0) ;
+        dstBlk.put(srcBlk) ;
+    }  
 }
 
 /*

Added: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileAccessByteArray.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileAccessByteArray.java?rev=1125396&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileAccessByteArray.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileAccessByteArray.java Fri May 20 13:52:23 2011
@@ -0,0 +1,126 @@
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+package com.hp.hpl.jena.tdb.base.file;
+
+import java.nio.ByteBuffer ;
+
+import com.hp.hpl.jena.tdb.base.block.Block ;
+import static com.hp.hpl.jena.tdb.sys.SystemTDB.SizeOfInt ;
+
+/** 
+ *  FileAccess interface backed by a byte array.
+ */
+public class FileAccessByteArray implements FileAccess
+{
+    private ByteBuffer bytes ;
+    private long length ;           // Bytes in use: 0 to length-1 
+    private long alloc ;           // Bytes in use: 0 to length-1
+    
+    public FileAccessByteArray()
+    {
+        bytes = ByteBuffer.allocate(1024) ;
+        length = 0 ; 
+        alloc = 0 ;
+    }
+    
+    @Override
+    public Block allocate(int size)
+    {
+        long addr = alloc ;
+        ByteBuffer bb = ByteBuffer.allocate(size) ;
+        alloc += size + SizeOfInt ;
+        return new Block((int)addr, bb) ; 
+    }
+
+    @Override
+    public Block read(int id)
+    {
+        if ( id < 0 || id >= length || id >= bytes.capacity() )
+            throw new FileException("Bad id (read): "+id) ;
+        bytes.position(id) ;
+        int len = bytes.getInt() ;
+        ByteBuffer bb = ByteBuffer.allocate(len) ;
+        // Copy out the bytes - copy for safety.
+        bytes.get(bb.array(), 0, len) ;
+        return new Block(id, bb) ; 
+    }
+
+    @Override
+    public void write(Block block)
+    {
+        int loc = block.getId() ;
+        if ( loc < 0 || loc > length )  // Can be equal => append.
+            throw new FileException("Bad id (write): "+loc+" ("+alloc+","+length+")") ;
+        ByteBuffer bb = block.getByteBuffer() ; 
+        int len = bb.capacity() ;
+        
+        if ( loc == length )
+        {
+            if ( bytes.capacity()-length < len )
+            {
+                int cap2 = bytes.capacity()+1024 ;
+                while(bytes.capacity()-length < len)
+                    cap2 += 1024 ; 
+                
+                ByteBuffer bytes2 = ByteBuffer.allocate(cap2) ;
+                bytes2.position(0) ;
+                bytes2.put(bytes) ;
+            }
+            length += len +SizeOfInt ;
+        }
+        bytes.position(loc) ;
+        bytes.putInt(len) ;
+        bytes.put(bb.array(), 0, bb.capacity()) ;
+    }
+
+    @Override
+    public boolean isEmpty()
+    {
+        return length == 0  ;
+    }
+
+    @Override
+    public boolean valid(int id)
+    {
+        return ( id >= 0 && id < length ) ;
+    }
+
+    @Override
+    public void sync()
+    {}
+
+    @Override
+    public void close()
+    {}
+}
+
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
\ No newline at end of file

Propchange: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileAccessByteArray.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileAccessMem.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileAccessMem.java?rev=1125396&r1=1125395&r2=1125396&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileAccessMem.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileAccessMem.java Fri May 20 13:52:23 2011
@@ -45,7 +45,7 @@ public class FileAccessMem implements Fi
     public Block allocate(int blkSize)
     {
         if ( blkSize > 0 && blkSize != this.blockSize )
-            throw new FileException("Fixed blocksize only: request= "+blkSize+"fixed size="+this.blockSize) ;
+            throw new FileException("Fixed blocksize only: request= "+blkSize+" / fixed size="+this.blockSize) ;
         
         int x = blocks.size() ;
         ByteBuffer bb = ByteBuffer.allocate(blkSize) ;
@@ -60,7 +60,7 @@ public class FileAccessMem implements Fi
         check(id) ;
         Block blk = blocks.get(id) ;
         if ( safeModeThisMgr ) 
-            return replicate(blk) ;
+            return blk.replicate() ;
         else
             return blk ;
     }
@@ -70,14 +70,14 @@ public class FileAccessMem implements Fi
     {
         check(block) ;
         if ( safeModeThisMgr )
-            block = replicate(block) ;
+            block = block.replicate() ;
         blocks.set(block.getId(), block) ;
     }
     
     @Override
     public boolean isEmpty()
     {
-        return false ;
+        return blocks.isEmpty() ;
     }
 
     @Override
@@ -118,35 +118,6 @@ public class FileAccessMem implements Fi
         if ( bb.order() != SystemTDB.NetworkOrder )
             throw new FileException("BlockMgrMem: Wrong byte order") ;
     }
-    
-    private static Block replicate(Block srcBlock)
-    {
-        ByteBuffer dstBuffer = replicate(srcBlock.getByteBuffer()) ;
-        Block b = new Block(srcBlock.getId(), dstBuffer) ;
-        b.setType(srcBlock.getType()) ;
-        return b ;
-    }  
-
-    private static void replicate(Block srcBlock, Block dstBlock)
-    {
-        if ( ! srcBlock.getId().equals(dstBlock.getId()) )
-            throw new FileException("FileAccessMem: Attempt to copy across blocks: "+srcBlock.getId()+" => "+dstBlock.getId()) ;
-        replicate(srcBlock.getByteBuffer(), dstBlock.getByteBuffer()) ;
-    }  
-
-    private static ByteBuffer replicate(ByteBuffer srcBlk)
-    {
-        ByteBuffer dstBlk = ByteBuffer.allocate(srcBlk.capacity()) ;
-        System.arraycopy(srcBlk.array(), 0, dstBlk.array(), 0, srcBlk.capacity()) ;
-        return dstBlk ; 
-    }  
-    
-    private static void replicate(ByteBuffer srcBlk, ByteBuffer dstBlk)
-    {
-        srcBlk.position(0) ;
-        dstBlk.position(0) ;
-        dstBlk.put(srcBlk) ;
-    }  
 }
 /*
  * (c) Copyright 2011 Epimorphics Ltd.

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java?rev=1125396&r1=1125395&r2=1125396&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java Fri May 20 13:52:23 2011
@@ -13,8 +13,11 @@ import org.openjena.atlas.lib.Closeable 
 import org.openjena.atlas.lib.Pair ;
 import org.openjena.atlas.lib.Sync ;
 
-/** Temporary name.
+/** 
+ * An ObjectFile is an append-read file, that is you can append blocks
+ * to the stream or read any block.
  */
+
 public interface ObjectFile extends Sync, Closeable
 {
     public static final String type = "object" ;
@@ -22,13 +25,13 @@ public interface ObjectFile extends Sync
     /** Allocate space for a write - pass this buffer to completeWrite */ 
     public ByteBuffer allocWrite(int maxBytes) ;
     
-    /** Announce that a write is complete - return the accessor number */
+    /** Announce that a write is complete (buffer must come from allocWrite) - return the accessor number */
     public long completeWrite(ByteBuffer buffer) ;
 
     /** Write out the buffer - return the accessor number */ 
     public long write(ByteBuffer buffer) ;
 
-    /** Read a buffer. */
+    /** Read a buffer at the accessor number. */
     public ByteBuffer read(long id) ;
     
     /** Length, in units used by read/write for ids */

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileDiskDirect.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileDiskDirect.java?rev=1125396&r1=1125395&r2=1125396&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileDiskDirect.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileDiskDirect.java Fri May 20 13:52:23 2011
@@ -6,6 +6,9 @@
 
 package com.hp.hpl.jena.tdb.base.objectfile;
 
+import static com.hp.hpl.jena.tdb.sys.SystemTDB.ObjectFileWriteCacheSize ;
+import static com.hp.hpl.jena.tdb.sys.SystemTDB.SizeOfInt ;
+
 import java.io.IOException ;
 import java.nio.ByteBuffer ;
 import java.util.Iterator ;
@@ -16,27 +19,37 @@ import org.openjena.atlas.lib.Pair ;
 import com.hp.hpl.jena.tdb.base.block.BlockException ;
 import com.hp.hpl.jena.tdb.base.file.FileBase ;
 import com.hp.hpl.jena.tdb.base.file.FileException ;
-import com.hp.hpl.jena.tdb.lib.StringAbbrev ;
-import static com.hp.hpl.jena.tdb.sys.SystemTDB.SizeOfInt ;
-import static com.hp.hpl.jena.tdb.sys.SystemTDB.ObjectFileWriteCacheSize;
 
 /** Variable length ByteBuffer file on disk.  Read by id ; write is append-only */  
 
 public class ObjectFileDiskDirect implements ObjectFile 
 {
-    /* No synchronization - assumes that the caller has some appropriate lock
-     * because the combination of file and cache operations needs to be thread safe.  
+    /* 
+     * No synchronization - assumes that the caller has some appropriate lock
+     * because the combination of file and cache operations needs to be thread safe.
+     * 
+     * The position of the channel is assumed to be the end of the file always.
+     * Read operations are done with absolute channel calls, 
+     * which do not reset the position.
+     * 
+     * Writing is buffered.
      */
+    
+    // Replaces with a FileAccess wrapper?
+    
+    // One disk file size.
     protected long filesize ;
-    protected final FileBase file ;
     // Delayed write buffer
+    // This adds to the length of the file  
     private ByteBuffer output = ByteBuffer.allocate(ObjectFileWriteCacheSize) ;
+    
+    protected final FileBase file ;
     private boolean inAllocWrite = true ;
     private ByteBuffer allocByteBuffer = null ;
 
     public ObjectFileDiskDirect(String filename)
     {
-        file = new FileBase(filename) ;
+        file = new FileBase(filename) ; // Inherit?
         try { 
             filesize = file.out.length() ;
         } catch (IOException ex) { throw new BlockException("Failed to get filesize", ex) ; } 
@@ -48,6 +61,7 @@ public class ObjectFileDiskDirect implem
     public long write(ByteBuffer bb)
     {
         try {
+            // XXX Use the allocByteBuffer. 
             // Write length
             int len = bb.limit() - bb.position();
             lengthBuffer.clear() ;
@@ -148,7 +162,7 @@ public class ObjectFileDiskDirect implem
         if ( loc < 0 )
             throw new IllegalArgumentException("ObjectFile.read: Bad read: "+loc) ;
         
-        // Maybe be in the write buffer
+        // Maybe it's in the in the write buffer
         if ( loc >= filesize )
         {
             if ( loc > filesize+output.capacity() )
@@ -194,6 +208,12 @@ public class ObjectFileDiskDirect implem
     }
 
     @Override
+    public void close()                 { flushOutputBuffer() ; file.close() ; }
+
+    @Override
+    public void sync()                  { flushOutputBuffer() ; file.sync() ; }
+
+    @Override
     public Iterator<Pair<Long, ByteBuffer>> all()
     {
         try { file.out.seek(0) ; } 
@@ -236,14 +256,6 @@ public class ObjectFileDiskDirect implem
         { throw new UnsupportedOperationException() ; }
     }
     
-
-    @Override
-    public void close()
-    { file.close() ; }
-
-    @Override
-    public void sync()                  { flushOutputBuffer() ; file.sync() ; }
-    
     // ---- Dump
     public void dump() { dump(handler) ; }
 
@@ -271,42 +283,6 @@ public class ObjectFileDiskDirect implem
             System.out.printf("0x%08X : %s\n", fileIdx, str) ;
         }
     } ;
-    // ----
- 
-    
-    // URI compression can be effective but literals are more of a problem.  More variety. 
-    public final static boolean compression = false ; 
-    private static StringAbbrev abbreviations = new StringAbbrev() ;
-    static {
-        abbreviations.add(  "rdf",      "<http://www.w3.org/1999/02/22-rdf-syntax-ns#") ;
-        abbreviations.add(  "rdfs",     "<http://www.w3.org/2000/01/rdf-schema#") ;
-        abbreviations.add(  "xsd",      "<http://www.w3.org/2001/XMLSchema#") ;
-        
-        // MusicBrainz
-        abbreviations.add(  "mal",      "<http://musicbrainz.org/mm-2.1/album/") ;
-        abbreviations.add(  "mt",       "<http://musicbrainz.org/mm-2.1/track/") ;
-        abbreviations.add(  "mar",      "<http://musicbrainz.org/mm-2.1/artist/") ;
-        abbreviations.add(  "mtr",      "<http://musicbrainz.org/mm-2.1/trmid/") ;
-        abbreviations.add(  "mc",       "<http://musicbrainz.org/mm-2.1/cdindex/") ;
-        
-        abbreviations.add(  "m21",      "<http://musicbrainz.org/mm/mm-2.1#") ;
-        abbreviations.add(  "dc",       "<http://purl.org/dc/elements/1.1/") ;
-        // DBPedia
-        abbreviations.add(  "r",        "<http://dbpedia/resource/") ;
-        abbreviations.add(  "p",        "<http://dbpedia/property/") ;
-    }
-    private String compress(String str)
-    {
-        if ( !compression || abbreviations == null ) return str ;
-        return abbreviations.abbreviate(str) ;
-    }
-
-    private String decompress(String x)
-    {
-        if ( !compression || abbreviations == null ) return x ;
-        return abbreviations.expand(x) ;
-    }
-
 }
 
 /*

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodecSSE.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodecSSE.java?rev=1125396&r1=1125395&r2=1125396&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodecSSE.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodecSSE.java Fri May 20 13:52:23 2011
@@ -18,6 +18,7 @@ import com.hp.hpl.jena.rdf.model.AnonId 
 import com.hp.hpl.jena.shared.PrefixMapping ;
 import com.hp.hpl.jena.tdb.TDBException ;
 import com.hp.hpl.jena.tdb.lib.NodeFmtLib ;
+import com.hp.hpl.jena.tdb.lib.StringAbbrev ;
 
 /** Simple encoder/decoder for nodes that uses Turtle term string encoding. */
 
@@ -136,6 +137,39 @@ public class NodecSSE implements Nodec
         // Max 3 bytes UTF-8 for up to 10FFFF (NB Java treats above 16bites as surrogate pairs only). 
         return string.length()*3 ;
     }
+    
+    // URI compression can be effective but literals are more of a problem.  More variety. 
+    public final static boolean compression = false ; 
+    private static StringAbbrev abbreviations = new StringAbbrev() ;
+    static {
+        abbreviations.add(  "rdf",      "<http://www.w3.org/1999/02/22-rdf-syntax-ns#") ;
+        abbreviations.add(  "rdfs",     "<http://www.w3.org/2000/01/rdf-schema#") ;
+        abbreviations.add(  "xsd",      "<http://www.w3.org/2001/XMLSchema#") ;
+
+        // MusicBrainz
+        abbreviations.add(  "mal",      "<http://musicbrainz.org/mm-2.1/album/") ;
+        abbreviations.add(  "mt",       "<http://musicbrainz.org/mm-2.1/track/") ;
+        abbreviations.add(  "mar",      "<http://musicbrainz.org/mm-2.1/artist/") ;
+        abbreviations.add(  "mtr",      "<http://musicbrainz.org/mm-2.1/trmid/") ;
+        abbreviations.add(  "mc",       "<http://musicbrainz.org/mm-2.1/cdindex/") ;
+
+        abbreviations.add(  "m21",      "<http://musicbrainz.org/mm/mm-2.1#") ;
+        abbreviations.add(  "dc",       "<http://purl.org/dc/elements/1.1/") ;
+        // DBPedia
+        abbreviations.add(  "r",        "<http://dbpedia/resource/") ;
+        abbreviations.add(  "p",        "<http://dbpedia/property/") ;
+    }
+    private String compress(String str)
+    {
+        if ( !compression || abbreviations == null ) return str ;
+        return abbreviations.abbreviate(str) ;
+    }
+
+    private String decompress(String x)
+    {
+        if ( !compression || abbreviations == null ) return x ;
+        return abbreviations.expand(x) ;
+    }
 
 }
 

Added: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractFileAccessFixedSizeTest.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractFileAccessFixedSizeTest.java?rev=1125396&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractFileAccessFixedSizeTest.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractFileAccessFixedSizeTest.java Fri May 20 13:52:23 2011
@@ -0,0 +1,119 @@
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+package com.hp.hpl.jena.tdb.base.file;
+
+import java.nio.ByteBuffer ;
+
+import org.junit.Test ;
+import org.openjena.atlas.junit.BaseTest ;
+
+import com.hp.hpl.jena.tdb.base.block.Block ;
+
+public abstract class AbstractFileAccessFixedSizeTest extends BaseTest
+{
+    // Fixed block tests.
+    
+    int blkSize ;
+    
+    protected AbstractFileAccessFixedSizeTest(int blkSize)
+    {
+        this.blkSize = blkSize ;
+    }
+    
+    protected abstract FileAccess make() ;
+    protected static Block data(FileAccess file, int len)
+    {
+        Block b = file.allocate(len) ;
+        for (int i = 0 ; i < len ; i++ )
+            b.getByteBuffer().put((byte)(i&0xFF)) ;
+        return b ;
+    }
+    
+    protected static boolean sameValue(Block block1, Block block2)
+    {
+        if ( block1.getId() != block2.getId()) return false ;
+        ByteBuffer bb1 = block1.getByteBuffer() ; 
+        ByteBuffer bb2 = block2.getByteBuffer() ;
+        
+        if ( bb1.capacity() != bb2.capacity() ) return false ;
+        
+        for ( int i = 0 ; i < bb1.capacity() ; i++ )
+            if ( bb1.get(i) != bb2.get(i) ) return false ;
+        return true ;
+    }
+
+    @Test public void fileaccess_01()
+    {
+        FileAccess file = make() ;
+        assertTrue(file.isEmpty()) ;
+    }
+    
+    @Test public void fileaccess_02()
+    {
+        FileAccess file = make() ;
+        Block b = data(file, blkSize) ;
+        file.write(b) ;
+    }
+
+    @Test public void fileaccess_03()
+    {
+        FileAccess file = make() ;
+        Block b1 = data(file, blkSize) ;
+        file.write(b1) ;
+        int x = b1.getId() ;
+        Block b9 = file.read(x) ;
+        assertNotSame(b1, b9) ;
+        assertTrue(sameValue(b1, b9)) ;
+        b9 = file.read(x) ;
+        assertNotSame(b1, b9) ;
+        assertTrue(sameValue(b1, b9)) ;
+    }
+    
+    @Test public void fileaccess_04()
+    {
+        FileAccess file = make() ;
+        Block b1 = data(file, blkSize) ;
+        Block b2 = data(file, blkSize) ;
+        file.write(b1) ;
+        file.write(b2) ;
+        
+        int x = b1.getId() ;
+        Block b8 = file.read(b1.getId()) ;
+        Block b9 = file.read(b1.getId()) ;
+        assertNotSame(b8, b9) ;
+        assertTrue(b8.getId() == b9.getId()) ;
+    }
+    
+    // Exceptions.
+}
+
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
\ No newline at end of file

Propchange: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractFileAccessFixedSizeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractFileAccessVarSizeTest.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractFileAccessVarSizeTest.java?rev=1125396&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractFileAccessVarSizeTest.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractFileAccessVarSizeTest.java Fri May 20 13:52:23 2011
@@ -0,0 +1,69 @@
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+package com.hp.hpl.jena.tdb.base.file;
+
+import org.junit.Test ;
+
+import com.hp.hpl.jena.tdb.base.block.Block ;
+
+
+public abstract class AbstractFileAccessVarSizeTest extends AbstractFileAccessFixedSizeTest
+{
+    AbstractFileAccessVarSizeTest()
+    {
+        super(25) ;
+    }
+    
+    @Test public void fileaccess_50()
+    {
+        FileAccess file = make() ;
+        Block b1 = data(file, 10) ;
+        Block b2 = data(file, 20) ;
+        file.write(b1) ;
+        
+        System.out.println("b1: "+b1) ;
+        System.out.println("b2: "+b2) ;
+        
+        // SHOULD NOT WORK.
+        Block b2a = file.read(b2.getId()) ;
+        Block b1a = file.read(b1.getId()) ;
+        
+        assertNotSame(b1a, b1) ;
+        assertNotSame(b2a, b2) ;
+        sameValue(b1, b1a) ;
+        sameValue(b2, b2a) ;
+        
+        
+    }        
+}
+
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */

Propchange: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractFileAccessVarSizeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TS_File.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TS_File.java?rev=1125396&r1=1125395&r2=1125396&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TS_File.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TS_File.java Fri May 20 13:52:23 2011
@@ -13,6 +13,8 @@ import org.junit.runners.Suite;
 @Suite.SuiteClasses( {
     TestMetaFile.class
     , TestStringFile.class 
+    , TestFileAccessMem.class
+    , TestFileAccessByteArray.class
 })
 
 

Added: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TestFileAccessByteArray.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TestFileAccessByteArray.java?rev=1125396&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TestFileAccessByteArray.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TestFileAccessByteArray.java Fri May 20 13:52:23 2011
@@ -0,0 +1,45 @@
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+package com.hp.hpl.jena.tdb.base.file;
+
+public class TestFileAccessByteArray extends AbstractFileAccessVarSizeTest
+{
+
+    @Override
+    protected FileAccess make()
+    {
+        return new FileAccessByteArray() ;
+    }
+
+}
+
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
\ No newline at end of file

Propchange: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TestFileAccessByteArray.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TestFileAccessMem.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TestFileAccessMem.java?rev=1125396&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TestFileAccessMem.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TestFileAccessMem.java Fri May 20 13:52:23 2011
@@ -0,0 +1,50 @@
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+package com.hp.hpl.jena.tdb.base.file;
+
+public class TestFileAccessMem extends AbstractFileAccessFixedSizeTest
+{
+    static final int BlockSize = 50 ;
+    public TestFileAccessMem()
+    {
+        super(BlockSize) ;
+    }
+
+    @Override
+    protected FileAccess make()
+    {
+        return new FileAccessMem(BlockSize) ;
+    }
+
+}
+
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
\ No newline at end of file

Propchange: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/TestFileAccessMem.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain