*** empty log message ***
authornavid <navid>
Tue, 27 Jan 2009 01:12:16 +0000 (01:12 +0000)
committernavid <navid>
Tue, 27 Jan 2009 01:12:16 +0000 (01:12 +0000)
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/TransactionalFile.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTable.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTableTransactional.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/IndexedTableReaderTransactional.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/PagedIndex.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/PagedIndexTransactional.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/RowTransactional.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexEntryTransactional.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexPage.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexPageTransactional.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/ValueTransactional.java

index 22bac250eb2ca164b78e48aa400bb2be100cf0bc..694246a95148be1a06a62bf13e306cf115b15472 100644 (file)
@@ -342,28 +342,139 @@ public class TransactionalFile implements Comparable {
         return (int) (newpos - pos);
     }
 
-    public final int readByte(){
+    public final byte readByte(){
         byte[] data = new byte[1];
         read(data);
-        int result = (byte)(data[0]);
+        byte result = (byte)(data[0]);
         return result;
     }
     
-    public final int readChar(){
+    public final boolean readBoolean(){
+        byte[] data = new byte[1];
+        read(data);
+        if (data[0] == 0 )
+            return false;
+        return true;
+        //return ((boolean)data[0]);// != 0);
+    }
+    
+    public final char readChar(){
         byte[] data = new byte[2];
         read(data);
-        int result = (char)((data[0] << 8) | data[0]);
+        char result = (char)((data[0] << 8) | data[0]);
         return result;
     }
     
-    public final int readShort(){
+    public final short readShort(){
         byte[] data = new byte[2];
         read(data);
-        int result = (short)((data[0] << 8) | data[1]);
-        System.out.println("res " + result);
+        short result = (short)((data[0] << 8) | data[1]);
+     //   System.out.println("res " + result);
         return result;
     }
     
+    public final int readUnsignedShort() throws IOException {
+        byte[] data = new byte[2];
+        read(data);
+        return (data[0] << 8) + (data[1] << 0);    
+    }
+    
+    public final String readUTF() throws UTFDataFormatException{
+            int utflen = -1;
+            byte[] bytearr = null;
+            char[] chararr = null;
+        try {
+            utflen = readUnsignedShort();
+        } catch (IOException ex) {
+            Logger.getLogger(TransactionalFile.class.getName()).log(Level.SEVERE, null, ex);
+        }
+            bytearr = new byte[utflen];
+            chararr = new char[utflen];
+            
+
+                int c, char2, char3;
+                int count = 0;
+                int chararr_count = 0;
+
+                read(bytearr);
+
+                while (count < utflen) {
+                    c = (int) bytearr[count] & 0xff;
+                    if (c > 127)
+                        break;
+                    count++;
+                    chararr[chararr_count++] = (char) c;
+                }
+
+                while (count < utflen) {
+                    c = (int) bytearr[count] & 0xff;
+                    switch (c >> 4) {
+                    case 0:
+                    case 1:
+                    case 2:
+                    case 3:
+                    case 4:
+                    case 5:
+                    case 6:
+                    case 7:
+                        /* 0xxxxxxx*/
+                        count++;
+                        chararr[chararr_count++] = (char) c;
+                        break;
+                    case 12:
+                    case 13:
+                        /* 110x xxxx   10xx xxxx*/
+                        count += 2;
+                        if (count > utflen)
+                            throw new UTFDataFormatException(
+                                    "malformed input: partial character at end");
+                        char2 = (int) bytearr[count - 1];
+                        if ((char2 & 0xC0) != 0x80)
+                            throw new UTFDataFormatException(
+                                    "malformed input around byte " + count);
+                        chararr[chararr_count++] = (char) (((c & 0x1F) << 6) | (char2 & 0x3F));
+                        break;
+                    case 14:
+                        /* 1110 xxxx  10xx xxxx  10xx xxxx */
+                        count += 3;
+                        if (count > utflen)
+                            throw new UTFDataFormatException(
+                                    "malformed input: partial character at end");
+                        char2 = (int) bytearr[count - 2];
+                        char3 = (int) bytearr[count - 1];
+                        if (((char2 & 0xC0) != 0x80)
+                                || ((char3 & 0xC0) != 0x80))
+                            throw new UTFDataFormatException(
+                                    "malformed input around byte "
+                                            + (count - 1));
+                        chararr[chararr_count++] = (char) (((c & 0x0F) << 12)
+                                | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
+                        break;
+                    default:
+                        /* 10xx xxxx,  1111 xxxx */
+                        throw new UTFDataFormatException(
+                               "malformed input around byte " + count);
+                   }
+              }
+             // The number of chars produced may be less than utflen
+             return new String(chararr, 0, chararr_count);
+        
+    }
+    
+    public final float readFloat(){
+       // byte[] data = new byte[4];
+       // int k = read(data);
+        return Float.intBitsToFloat(readInt());
+       // float result = Conversions.bytes2float(data);
+        //int result = (data[0] << 24) | (data[1] << 16) + (data[2] << 8) + (data[3]<<0);
+      //  System.out.println("int res " + result);
+      //  return result;
+    }
+    
+    public final double readDouble(){
+        return Double.longBitsToDouble(readLong());
+    }
+    
     
     public final int readInt(){
         byte[] data = new byte[4];
@@ -371,7 +482,7 @@ public class TransactionalFile implements Comparable {
         
         int result = Conversions.bytes2int(data);
         //int result = (data[0] << 24) | (data[1] << 16) + (data[2] << 8) + (data[3]<<0);
-        System.out.println("int res " + result);
+      //  System.out.println("int res " + result);
         return result;
     }
     
@@ -381,7 +492,7 @@ public class TransactionalFile implements Comparable {
         read(data);
         //long result = ((long)data[0] << 56) + ((long)data[1] << 48) + ((long)data[2] << 40) + ((long)data[3] << 32) + ((long)data[4] << 24) + ((long)data[5] << 16)+ ((long)data[6] << 8) + data[7];
         long result = Conversions.bytes2long(data);
-        System.out.println("long res " + result);
+    //    System.out.println("long res " + result);
         return result;
     }
     
index f4f17d13638598a3720861279261a6ef2c484781..cbc26ac1f8838b8b6fc08ca30b794082bc368992 100644 (file)
@@ -548,8 +548,10 @@ public class DualFileTable implements Table{
          TableIndexEntry entry=null;
           // Handle index entry caching
           if(INDEXCACHESIZE>0){
+            //  System.out.println("in h");
               synchronized(indexcache){
                   entry=getCacheEntry(id);
+               //   System.out.println(entry);
                    if(entry==null){
                        entry=index.scanIndex(id);
                        if(entry!=null){
@@ -563,6 +565,7 @@ public class DualFileTable implements Table{
           if(entry!=null){
               long dataoffset=0;
               DataInputStream data=null;
+            //  System.out.println(entry);
               if(entry.location==Table.FILEA){
                   data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(Table.FILEA))));
               }else if(entry.location==Table.FILEB){
index 483b0e9dfa5f6d1d5f952639236ed0f8f6df1b7d..971feb1d39a776917aa0dd40034f435f58b326a5 100644 (file)
@@ -355,7 +355,9 @@ public class DualFileTableTransactional implements TableTransactional{
          args.add(row);
          Thread.doIt(new Callable<Boolean>() {
              public Boolean call() throws Exception{
-                 openFile(FILEA);             
+                      
+                 openFile(FILEA);         
+            
              //int pre=fileastream.size();
                  int pre= (int)fileastream.getFilePointer();
              //row.writeToStream(fileastream);
@@ -374,7 +376,7 @@ public class DualFileTableTransactional implements TableTransactional{
                     TableIndexEntryTransactional entry=new TableIndexEntryTransactional(((RowTransactional)args.get(0)).getId(),((RowTransactional)args.get(0)).getSize(),FILEA,atomicfields.getFileaposition());
                     addCacheEntry(entry);
                 }
-                atomicfields.setFileaposition(atomicfields.getFileaposition()+Row.calcSize(pre,post));
+                atomicfields.setFileaposition(atomicfields.getFileaposition()+RowTransactional.calcSize(pre,post));
                 return true;
             }
          });
@@ -402,7 +404,7 @@ public class DualFileTableTransactional implements TableTransactional{
                   TableIndexEntryTransactional entry=new TableIndexEntryTransactional(((RowTransactional)args.get(0)).getId(),((RowTransactional)args.get(0)).getSize(),FILEB,atomicfields.getFilebposition());
                   addCacheEntry(entry);
                 }
-                atomicfields.setFilebposition(atomicfields.getFilebposition()+Row.calcSize(pre,post));
+                atomicfields.setFilebposition(atomicfields.getFilebposition()+RowTransactional.calcSize(pre,post));
                 return true;
             }
          });
@@ -517,19 +519,19 @@ public class DualFileTableTransactional implements TableTransactional{
          TableIndexEntryTransactional entry=null;
          final Vector args = new Vector();
          args.add(row);
-         args.add(entry);
+         //args.add(entry);
          // Handle index entry caching
          if(INDEXCACHESIZE>0){
-             Thread.doIt(new Callable<Boolean>() {
-                public Boolean call() throws Exception {
-                    TableIndexEntryTransactional entry = (TableIndexEntryTransactional) (args.get(1));
+             entry = Thread.doIt(new Callable<TableIndexEntryTransactional>() {
+                public TableIndexEntryTransactional call() throws Exception {
+                    TableIndexEntryTransactional entry;// = (TableIndexEntryTransactional) (args.get(1));
                     RowTransactional row = (RowTransactional) (args.get(0));
                     entry = getCacheEntry(row.getId());
                     if(entry==null){
                        entry=index.scanIndex(row.getId());
                        addCacheEntry(entry);
                     }
-                    return true;
+                    return entry;
                 }
              });
           /*   synchronized(indexcache){
@@ -598,9 +600,11 @@ public class DualFileTableTransactional implements TableTransactional{
      private void updateRowA(RowTransactional row) throws IOException{
          final Vector args = new Vector();
          args.add(row);
+         System.out.println("b");
          Thread.doIt(new Callable<Boolean>() {
               public Boolean call() throws Exception{ 
          //synchronized(filealock){
+                  System.out.println("add a");
                   openFile(FILEA);
                   //int pre=filebstream.size();
                   int pre=(int)fileastream.getFilePointer();
@@ -623,10 +627,11 @@ public class DualFileTableTransactional implements TableTransactional{
 
      private void updateRowB(RowTransactional row) throws IOException{
          final Vector args = new Vector();
+         System.out.println("b");
          args.add(row);
          Thread.doIt(new Callable<Boolean>() {
              public Boolean call() throws Exception{ 
-         
+             System.out.println("add b");
          //synchronized(fileblock){
                 openFile(FILEB);
               //int pre=filebstream.size();
@@ -703,36 +708,44 @@ public class DualFileTableTransactional implements TableTransactional{
       */
      public RowTransactional getRow(String id) throws IOException{
          TableIndexEntryTransactional entry=null;
+          final Vector args = new Vector();
+              args.add(id);
+             // args.add(entry);
           // Handle index entry caching
           if(INDEXCACHESIZE>0){
-              final Vector args = new Vector();
-              args.add(id);
-              args.add(entry);
+             
               //synchronized(indexcache){
-              Thread.doIt(new Callable<Boolean>() {
-                public Boolean call() throws Exception{
-                  TableIndexEntryTransactional entry = (TableIndexEntryTransactional) (args.get(1));
+              entry = Thread.doIt(new Callable<TableIndexEntryTransactional>() {
+                public TableIndexEntryTransactional call() throws Exception{
+                  TableIndexEntryTransactional entry;// = (TableIndexEntryTransactional) (args.get(1));
                   String id = (String) (args.get(0));  
                   entry=getCacheEntry(id);
+                 //  System.out.println("presalam " + (TableIndexEntryTransactional) (args.get(1)));
                    if(entry==null){
                        entry=index.scanIndex(id);
                        if(entry!=null){
                            addCacheEntry(entry);
                        }
                    }
-                  return true;
+                  return entry;
                 }
               });
           }else{
               entry=index.scanIndexTransactional(id);
           }
+//          entry = (TableIndexEntryTransactional) (args.get(1));
+  //        args.clear();
+          
           if(entry!=null){
               long dataoffset=0;
-              DataInputStream data=null;
-              if(entry.getLocation()==Table.FILEA){
-                  data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(Table.FILEA))));
-              }else if(entry.getLocation()==Table.FILEB){
-                  data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(Table.FILEB))));
+              //DataInputStream data=null;
+              TransactionalFile data=null;
+              if(entry.getLocation()==TableTransactional.FILEA){
+                  //data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(TableTransactional.FILEA))));
+                  data=new TransactionalFile(getFileName(TableTransactional.FILEA), "rw");
+              }else if(entry.getLocation()==TableTransactional.FILEB){
+                  data=new TransactionalFile(getFileName(TableTransactional.FILEB), "rw");
+                  //data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(TableTransactional.FILEB))));
               }
               if(data!=null){
                   while(dataoffset!=entry.getPosition()){
@@ -740,13 +753,13 @@ public class DualFileTableTransactional implements TableTransactional{
                   }
                   RowTransactional row=RowTransactional.readFromStream(data);
                   data.close();
-                  final Vector args = new Vector();
-                  args.add(row);
+                  final Vector args2 = new Vector();
+                  args2.add(row);
                   Thread.doIt(new Callable<Boolean>() {
                       public Boolean call() throws Exception{
                   //synchronized(statlock){
                           atomicfields.setstat_read(atomicfields.getstat_read()+1);
-                          atomicfields.setstat_read_size(atomicfields.getstat_read_size()+((RowTransactional)args.get(0)).getSize());
+                          atomicfields.setstat_read_size(atomicfields.getstat_read_size()+((RowTransactional)args2.get(0)).getSize());
                           return true;
                       }
                   });
index e9c5cad73d505ea41f8a5da3cb43046af9a74aea..0289d57568eceaff8548bc054293f165a513d1fe 100644 (file)
@@ -31,6 +31,7 @@
  
  package com.solidosystems.tuplesoup.core;
  
+import TransactionalIO.core.TransactionalFile;
  import com.solidosystems.tuplesoup.filter.*;
  import java.io.*;
  import java.util.*;
@@ -41,8 +42,11 @@ import dstm2.factory.Factory;
 public class IndexedTableReaderTransactional extends TupleStreamTransactional{
 
     
-    private DataInputStream fileastream=null;
-    private DataInputStream filebstream=null;
+    private TransactionalFile fileastream=null;
+    private TransactionalFile filebstream=null;
+    
+    //private DataInputStream fileastream=null;
+    //private DataInputStream filebstream=null;
     private long fileaposition=0;
     private long filebposition=0;
 
@@ -76,9 +80,9 @@ public class IndexedTableReaderTransactional extends TupleStreamTransactional{
             TableIndexEntryTransactional entry=it.next();
             // TODO: we really shouldn't get nulls here
             if(entry!=null){
-                if(entry.getLocation()==Table.FILEA){
+                if(entry.getLocation()==TableTransactional.FILEA){
                     fileaentries.add(entry);
-                }else if(entry.getLocation()==Table.FILEB){
+                }else if(entry.getLocation()==TableTransactional.FILEB){
                     filebentries.add(entry);
                 }
             }
@@ -109,9 +113,9 @@ public class IndexedTableReaderTransactional extends TupleStreamTransactional{
             TableIndexEntryTransactional entry=it.next();
             // TODO: we really shouldn't get nulls here
             if(entry!=null){
-                if(entry.getLocation()==Table.FILEA){
+                if(entry.getLocation()==TableTransactional.FILEA){
                     fileaentries.add(entry);
-                }else if(entry.getLocation()==Table.FILEB){
+                }else if(entry.getLocation()==TableTransactional.FILEB){
                     filebentries.add(entry);
                 }
             }
@@ -135,7 +139,8 @@ public class IndexedTableReaderTransactional extends TupleStreamTransactional{
             if(fileaentries.size()>0){
                 TableIndexEntryTransactional nextfilea=fileaentries.remove(0);
                 if(fileastream==null){
-                    fileastream=new DataInputStream(new BufferedInputStream(new FileInputStream(table.getFileName(Table.FILEA))));
+                    fileastream=new TransactionalFile(table.getFileName(TableTransactional.FILEA), "rw");
+                  //  fileastream=new DataInputStream(new BufferedInputStream(new FileInputStream(table.getFileName(TableTransactional.FILEA))));
                     fileaposition=0;
                 }
                 if(fileaposition>nextfilea.getPosition()){
@@ -185,7 +190,8 @@ public class IndexedTableReaderTransactional extends TupleStreamTransactional{
             if(filebentries.size()>0){
                 TableIndexEntryTransactional nextfileb=filebentries.remove(0);
                 if(filebstream==null){
-                    filebstream=new DataInputStream(new BufferedInputStream(new FileInputStream(table.getFileName(Table.FILEB))));
+                    fileastream=new TransactionalFile(table.getFileName(TableTransactional.FILEB), "rw");
+                    //filebstream=new DataInputStream(new BufferedInputStream(new FileInputStream(table.getFileName(TableTransactional.FILEB))));
                     filebposition=0;
                 }
                 if(filebposition>nextfileb.getPosition()){
@@ -230,10 +236,10 @@ public class IndexedTableReaderTransactional extends TupleStreamTransactional{
             TableIndexEntryTransactional entry=entries.get(rowpointer++);
             if(entry!=null){
                    switch(entry.getLocation()){
-                    case Table.FILEA    : readNextFromFileA(entry);
+                    case TableTransactional.FILEA    : readNextFromFileA(entry);
                                         // return;
                                         break;
-                    case Table.FILEB : readNextFromFileB(entry);
+                    case TableTransactional.FILEB : readNextFromFileB(entry);
                                         // return;
                                         break;
                 }
index a36fb047b7982963e0bee4919f92e6e8b903b9a6..661443502182479b51b8704b848e2bfd0b55b3d1 100644 (file)
@@ -39,8 +39,11 @@ import java.nio.channels.*;
 
 public class PagedIndex implements TableIndex{
     
-protected static final int INITIALPAGEHASH=1024;
-    protected static final int PAGESIZE=2048;
+//protected static final int INITIALPAGEHASH=1024;
+  //  protected static final int PAGESIZE=2048;
+    
+    protected static final int INITIALPAGEHASH=32;
+    protected static final int PAGESIZE=64;
     
     private RandomAccessFile out=null;
     private String filename;
@@ -65,13 +68,11 @@ protected static final int INITIALPAGEHASH=1024;
             for(int i=0;i<INITIALPAGEHASH;i++){
                 root[i]=new TableIndexPage(this,out);
                 root[i].setFirst();
-                System.out.println("In loop " + root[i].getEndLocation());
                 out.seek(root[i].getEndLocation());
             }
         }else{
             for(int i=0;i<INITIALPAGEHASH;i++){
                 root[i]=TableIndexPage.createNewPage(this,out,PAGESIZE);
-                System.out.println("In Othe loop " + root[i].getEndLocation());
                 root[i].setFirst();
             }
         }
index 2034f9f69a78d85aee751636e2a8f3eb09be74e5..35a914b460c68cfc5166cb233ec8d30d5b0e1a58 100644 (file)
@@ -50,8 +50,12 @@ public class PagedIndexTransactional implements TableIndexTransactional{
     
     
     private TransactionalFile out=null;
-    protected static final int INITIALPAGEHASH=1024;
-    protected static final int PAGESIZE=2048;
+    
+    //protected static final int INITIALPAGEHASH=1024;
+    //protected static final int PAGESIZE=2048;
+    
+    protected static final int INITIALPAGEHASH=32;
+    protected static final int PAGESIZE=64;
     
         public PagedIndexTransactional(String filename) throws IOException{
         atomicfields = factory.create();
@@ -67,19 +71,19 @@ public class PagedIndexTransactional implements TableIndexTransactional{
         if(!ftest.exists())ftest.createNewFile();
         out=new TransactionalFile(filename,"rw");
         atomicfields.setRoots(new AtomicArray<TableIndexPageTransactional>(TableIndexPageTransactional.class, INITIALPAGEHASH));
-        System.out.println(filename);
-        System.out.println(out.length());
+       // System.out.println(filename);
+       // System.out.println(out.length());
         if(out.length()>0){
             for(int i=0;i<INITIALPAGEHASH;i++){
                 atomicfields.getRoots().set(i, new TableIndexPageTransactional(this,out));
                 atomicfields.getRoots().get(i).setFirst();
-                System.out.println("In loop " + atomicfields.getRoots().get(i).getEndLocation());
+               // System.out.println("In loop " + atomicfields.getRoots().get(i).getEndLocation());
                 out.seek(atomicfields.getRoots().get(i).getEndLocation());
             }
         }else{
             for(int i=0;i<INITIALPAGEHASH;i++){
                 atomicfields.getRoots().set(i, TableIndexPageTransactional.createNewPage(this,out,PAGESIZE));
-                     System.out.println("In Othe loop " + atomicfields.getRoots().get(i).getEndLocation());
+                //     System.out.println("In Othe loop " + atomicfields.getRoots().get(i).getEndLocation());
                 atomicfields.getRoots().get(i).setFirst();
             }
         }
@@ -159,7 +163,7 @@ public class PagedIndexTransactional implements TableIndexTransactional{
         });
     }
     
-    public synchronized List<TableIndexEntryTransactional> scanIndex(List<String> rows) throws IOException{
+    public /*synchronized*/ List<TableIndexEntryTransactional> scanIndex(List<String> rows) throws IOException{
         final List<String> rows2 = rows;
         return Thread.doIt(new Callable<List<TableIndexEntryTransactional>>() {
            public List<TableIndexEntryTransactional> call() throws Exception{
@@ -168,7 +172,7 @@ public class PagedIndexTransactional implements TableIndexTransactional{
                     String id=rows2.get(i);
                     TableIndexEntryTransactional entry=scanIndex(id);
                     if(entry!=null){
-                        if(entry.getLocation()!=Table.DELETE)lst.add(entry);
+                        if(entry.getLocation()!=TableTransactional.DELETE)lst.add(entry);
                     }
                 }
                 return lst;
@@ -179,9 +183,11 @@ public class PagedIndexTransactional implements TableIndexTransactional{
         return Thread.doIt(new Callable<List<TableIndexEntryTransactional>>() {
            public List<TableIndexEntryTransactional> call() throws Exception{
                 ArrayList<TableIndexEntryTransactional> lst=new ArrayList<TableIndexEntryTransactional>();
+                System.out.println(Thread.currentThread() + " start");
                 for(int i=0;i<INITIALPAGEHASH;i++){
                     atomicfields.getRoots().get(i).addEntriesToList(lst);
                 }
+                System.out.println(Thread.currentThread() +" done");
                 return lst;
            }
         });
index 3bdf0e8ac7c0cf65d384fa16f7627c9b251b2f98..8e5a5e8725290d5a3d702bde91f8dc374435846e 100644 (file)
@@ -299,8 +299,24 @@ public class RowTransactional {
      /**
       * Reads a full row from the given DataInputStream and returns it.
       */
-     public static RowTransactional readFromStream(DataInputStream in) throws IOException{
+     /*public static RowTransactional readFromStream(DataInputStream in) throws IOException{
          String id=in.readUTF();
+         //System.out.println("id " + id);
+         RowTransactional row=new RowTransactional(id);
+         int size=in.readInt();
+         for(int i=0;i<size;i++){
+             String key=in.readUTF();
+             ValueTransactional value=ValueTransactional.readFromStream(in);
+             row.put(key,value);
+         }
+         size=in.readInt();
+         row.atomicfields.setSize(size);
+         return row;
+     }*/
+     
+     public static RowTransactional readFromStream(TransactionalFile in) throws IOException{
+         String id=in.readUTF();
+         //System.out.println("id " + id);
          RowTransactional row=new RowTransactional(id);
          int size=in.readInt();
          for(int i=0;i<size;i++){
@@ -313,6 +329,7 @@ public class RowTransactional {
          return row;
      }
  
      /**
       * Returns a string representing this row formatted as the following example:
       * (1732)=>{"name":string:"Kasper J. Jeppesen","age":int:31}
index eaca765b2d4631f68792960dafccb00f696a4d74..aa550bf46613a3ad3122fb56eaf7d54b0e413325 100644 (file)
@@ -145,6 +145,7 @@ public class TableIndexEntryTransactional implements AtomicSuperClass, Comparabl
     protected static TableIndexEntryTransactional readData(TransactionalFile in) throws IOException{
         long pre=in.getFilePointer();
         in.readInt();
+        //short num=in.readShort();
         int num=in.readShort();
         //System.out.println("num= " + num);
         StringBuilder buf=new StringBuilder(num);
index dc8c289016713958ed03729b5882239d13f12683..f260cf2fbe73080e4a1cbd3e405acb743964fab8 100644 (file)
@@ -58,39 +58,33 @@ public class TableIndexPage{
         this.index=index;
         first=false;
         location=file.getFilePointer();
-        System.out.println(location);
         size=file.readInt();
         next=file.readLong();
         lower=file.readLong();
         offset=file.readInt();
         endhash=file.readInt();
-        System.out.println("si " + size);
-        System.out.println("next "  + next);
-        System.out.println("lower " + lower);
-        System.out.println("offset " + offset);
-        System.out.println("endhash " + endhash);
+   //     System.out.println("si " + size);
+  //      System.out.println("next "  + next);
+   //     System.out.println("lower " + lower);
+   //     System.out.println("offset " + offset);
+   //     System.out.println("endhash " + endhash);
         if(offset>0)starthash=file.readInt();
-        System.out.println("here tav;eindepage");
+   //     System.out.println("here tav;eindepage");
         
         
     }
     
     public static TableIndexPage createNewPage(PagedIndex index,RandomAccessFile file,int size) throws IOException{
         long pre=file.length();
-        System.out.println("pre " + pre);
-           System.out.println("pointer1 " + file.length()+size+BASEOFFSET);
+
         file.setLength(file.length()+size+BASEOFFSET);
         file.seek(pre);
      
-        System.out.println("pointer2 " + file.getFilePointer());
-        file.writeInt(size);
-         System.out.println("pointer2 " + file.getFilePointer());
+        
+        file.writeInt(size); 
         file.writeLong(-1l);
-         System.out.println("pointer2 " + file.getFilePointer());
         file.writeLong(-1l);
-         System.out.println("pointer2 " + file.getFilePointer());
         file.writeInt(0);
-         System.out.println("pointer2 " + file.getFilePointer());
         file.writeInt(-1);
         file.seek(pre);
         index.stat_create_page++;
@@ -148,6 +142,7 @@ public class TableIndexPage{
         }
         file.seek(location+BASEOFFSET);
         long pre=file.getFilePointer();
+        System.out.println(Thread.currentThread() + " " +offset + " " + pre);
         while(file.getFilePointer()<pre+offset){
             TableIndexEntry entry=TableIndexEntry.readData(file);
             if(entry!=null){
index e2bebd1b70c07cee973822ab426e010700694e53..8eb43a7b0093767847343a0d09283dcc54c6b517 100644 (file)
@@ -83,18 +83,18 @@ public class TableIndexPageTransactional implements AtomicSuperClass{
         this.atomicfields.setIndex(index);
         this.atomicfields.setFirst(false);
         this.atomicfields.setLocation(file.getFilePointer());
-        System.out.println(file.getFilePointer());
+      //  System.out.println(file.getFilePointer());
         this.atomicfields.setSize(file.readInt());
-         System.out.println(file.getFilePointer());
+      //   System.out.println(file.getFilePointer());
         this.atomicfields.setNext(file.readLong());
-         System.out.println(file.getFilePointer());
+      //   System.out.println(file.getFilePointer());
         this.atomicfields.setLower(file.readLong());
-         System.out.println(file.getFilePointer());
-          System.out.println(file.getFilePointer());
+      //   System.out.println(file.getFilePointer());
+      //    System.out.println(file.getFilePointer());
         this.atomicfields.setOffset(file.readInt());
-         System.out.println(file.getFilePointer());
+      //   System.out.println(file.getFilePointer());
         this.atomicfields.setEndhash(file.readInt());
-             System.out.println("size " + atomicfields.getSize());
+       //      System.out.println("size " + atomicfields.getSize());
         System.out.println("next "  + atomicfields.getNext());
         System.out.println("lower " + atomicfields.getLower());
         System.out.println("offset " + atomicfields.getOffset());
@@ -108,32 +108,32 @@ public class TableIndexPageTransactional implements AtomicSuperClass{
     public static TableIndexPageTransactional createNewPage(PagedIndexTransactional index,TransactionalFile file,int size) throws IOException{
     
         long pre=file.length();
-        System.out.println("pre " + pre);
+      //  System.out.println("pre " + pre);
 //        file.setLength(file.length()+size+BASEOFFSET);
         file.seek(pre);
         byte[] dummy = new byte[size+BASEOFFSET];
         file.write(dummy);
-        System.out.println("pointer " + file.getFilePointer());
+      //  System.out.println("pointer " + file.getFilePointer());
         
         file.seek(pre);
-        System.out.println("pointer2 " + file.getFilePointer());
+       // System.out.println("pointer2 " + file.getFilePointer());
         file.writeInt(size);
  
-         System.out.println("pointer2 " + file.getFilePointer());
+       //  System.out.println("pointer2 " + file.getFilePointer());
         file.writeLong(-1l);
-         System.out.println("pointer2 " + file.getFilePointer());
+       //  System.out.println("pointer2 " + file.getFilePointer());
         file.writeLong(-1l);
-         System.out.println("pointer2 " + file.getFilePointer());
+       //  System.out.println("pointer2 " + file.getFilePointer());
         file.writeInt(0);
-         System.out.println("pointer2 " + file.getFilePointer());
+      //   System.out.println("pointer2 " + file.getFilePointer());
         file.writeInt(-1);
         file.seek(pre);
-        file.readInt();
-        file.readLong();
-        file.readLong();
-        file.readInt();
-        file.readInt();
-        file.seek(pre);
+      //  file.readInt();
+      //  file.readLong();
+       // file.readLong();
+       // file.readInt();
+       // file.readInt();
+       // file.seek(pre);
         
         //index.atomicfields.setStat_create_page((long)2);
         index.atomicfields.setStat_create_page(index.atomicfields.getStat_create_page()+1);
@@ -191,10 +191,12 @@ public class TableIndexPageTransactional implements AtomicSuperClass{
         }
         file.seek(this.atomicfields.getLocation()+BASEOFFSET);
         long pre=file.getFilePointer();
+    //    System.out.println(Thread.currentThread() + " " +this.atomicfields.getOffset() + " " + pre);
         while(file.getFilePointer()<pre+this.atomicfields.getOffset()){
+            
             TableIndexEntryTransactional entry=TableIndexEntryTransactional.readData(file);
             if(entry!=null){
-                if(entry.getLocation()!=Table.DELETE)lst.add(entry);
+                if(entry.getLocation()!=TableTransactional.DELETE)lst.add(entry);
             }
         }
     }
@@ -223,7 +225,7 @@ public class TableIndexPageTransactional implements AtomicSuperClass{
         file.seek(this.atomicfields.getLocation()+BASEOFFSET);
         long pre=file.getFilePointer();
         while(file.getFilePointer()<pre+this.atomicfields.getOffset()){
-            System.out.println("neddddxtex " + atomicfields.getNext());
+            //System.out.println("neddddxtex " + atomicfields.getNext());
             TableIndexEntryTransactional entry=TableIndexEntryTransactional.lookForData(id,file);
             if(entry!=null)return entry;
         }
index 1b560d6a9f156f88224f892e09e9764c0533338e..ad76661923f2332b30cd9aa8e1a7e7c6d8965f4d 100644 (file)
@@ -525,7 +525,7 @@ public class ValueTransactional implements AtomicSuperClass{
       * @param in the DataInputStream the Value should be read from
       * @return the Value read from the stream
       */
-     public static ValueTransactional readFromStream(DataInputStream in) throws IOException{
+   /*  public static ValueTransactional readFromStream(DataInputStream in) throws IOException{
          byte type=in.readByte();
          switch(type){
              case STRING :   int size=in.readInt();
@@ -548,6 +548,33 @@ public class ValueTransactional implements AtomicSuperClass{
                            }
                            return new ValueTransactional(abuf);
 
+         }
+         return new ValueTransactional();
+     }*/
+     
+        public static ValueTransactional readFromStream(TransactionalFile in) throws IOException{
+         byte type=in.readByte();
+         switch(type){
+             case STRING :   int size=in.readInt();
+                             StringBuffer buf=new StringBuffer();
+                             for(int i=0;i<size;i++){
+                                 buf.append(in.readChar());
+                             }
+                             return new ValueTransactional(buf.toString());
+             case INT    :   return new ValueTransactional(in.readInt());
+             case LONG   :   return new ValueTransactional(in.readLong());
+             case FLOAT  :   return new ValueTransactional(in.readFloat());
+             case DOUBLE :   return new ValueTransactional(in.readDouble());
+             case BOOLEAN:   return new ValueTransactional(in.readBoolean());
+             case TIMESTAMP: return new ValueTransactional(new Date(in.readLong()));
+             case BINARY : int length=in.readInt();
+                           byte[] abuf=new byte[length];
+                           int read=0;
+                           while(read<length){
+                               read+=in.read(abuf);//,read,length-read);
+                           }
+                           return new ValueTransactional(abuf);
+
          }
          return new ValueTransactional();
      }