incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1204298 - in /incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore: Index.java IndexAccessor.java Table.java TableAccessor.java TableStore.java
Date Mon, 21 Nov 2011 00:17:09 GMT
Author: kwright
Date: Mon Nov 21 00:17:08 2011
New Revision: 1204298

URL: http://svn.apache.org/viewvc?rev=1204298&view=rev
Log:
Move some methods from TableStore into Table

Modified:
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexAccessor.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java?rev=1204298&r1=1204297&r2=1204298&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
Mon Nov 21 00:17:08 2011
@@ -79,7 +79,7 @@ public class Index implements WHIndex
   public WHAccessor buildAccessor(IndexCriteria[] criteria)
     throws WHException
   {
-    return new IndexAccessor(ts,this,criteria);
+    return new IndexAccessor(this,criteria);
   }
   
   /** Get the index name */
@@ -139,7 +139,7 @@ public class Index implements WHIndex
         newRowIndexValues = new WHValue[columnNames.length];
         for (int i = 0 ; i < newRowIndexValues.length ; i++)
         {
-          newRowIndexValues[i] = ts.getTableColumnValue(table.getName(),rowID,columnNames[i]);
+          newRowIndexValues[i] = table.getValue(rowID,columnNames[i]);
         }
       }
       
@@ -151,7 +151,7 @@ public class Index implements WHIndex
       {
         String currentColumn = columnNames[i];
         // Get the value from the row, so we can fire the comparator
-        WHValue currentValue = ts.getTableColumnValue(table.getName(),nodeRowID,currentColumn);
+        WHValue currentValue = table.getValue(nodeRowID,currentColumn);
         int comparatorResult = comparators[i].compare(currentValue,newRowIndexValues[i]);
         // Based on the result, decide which way to go
         long nextNodeID;

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexAccessor.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexAccessor.java?rev=1204298&r1=1204297&r2=1204298&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexAccessor.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexAccessor.java
Mon Nov 21 00:17:08 2011
@@ -38,9 +38,7 @@ import java.util.*;
 */
 public class IndexAccessor implements WHAccessor
 {
-  protected TableStore ts;
   protected Index index;
-  protected String tableName;
   protected String[] indexColumns;
   protected WHComparator[] comparators;
   protected IndexCriteria[] indexCriteria;
@@ -52,12 +50,10 @@ public class IndexAccessor implements WH
   protected long nextRowID = -1L;
   
   /** Constructor */
-  public IndexAccessor(TableStore ts, Index index, IndexCriteria[] indexCriteria)
+  public IndexAccessor(Index index, IndexCriteria[] indexCriteria)
     throws WHException
   {
-    this.ts = ts;
     this.index = index;
-    this.tableName = index.getTable().getName();
     this.indexColumns = index.getColumnNames();
     this.comparators = index.getComparators();
     this.indexCriteria = indexCriteria;
@@ -159,7 +155,7 @@ public class IndexAccessor implements WH
     // Get the table row
     long rowID = index.readIndexNodeTableRow(nodeID);
     // Get the column value
-    WHValue columnValue = ts.getTableColumnValue(tableName,rowID,currentColumn);
+    WHValue columnValue = index.getTable().getValue(rowID,currentColumn);
 
     // Do the assessment, if there are index criteria for this column
     int criteria;

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java?rev=1204298&r1=1204297&r2=1204298&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
Mon Nov 21 00:17:08 2011
@@ -20,6 +20,7 @@
 package org.apache.warthog.tablestore;
 
 import org.apache.warthog.interfaces.*;
+import org.apache.warthog.common.*;
 import java.util.*;
 
 /** This is the standard implementation of WHTable.
@@ -51,13 +52,13 @@ public class Table implements WHTable
     throws WHException
   {
     // Allocate the row
-    long rowID = ts.allocateNewTableRow(tableName);
+    long rowID = allocateNewTableRow();
     // Link in the row
-    ts.addTableRow(tableName,rowID);
+    addTableRow(rowID);
     // Set the values
     for (int i = 0 ; i < columns.length ; i++)
     {
-      ts.setTableColumnValue(tableName,rowID,columns[i],values[i]);
+      setTableColumnValue(rowID,columns[i],values[i]);
     }
     // Add to all indices
     ts.addIndexRow(tableName,rowID,null);
@@ -91,7 +92,7 @@ public class Table implements WHTable
       // Change the values as specified
       for (int i = 0 ; i < columns.length ; i++)
       {
-        ts.setTableColumnValue(tableName,rowID,columns[i],values[i]);
+        setTableColumnValue(rowID,columns[i],values[i]);
       }
       // Add the row back to all indexes which can potentially intersect the changes
       ts.addIndexRow(tableName,rowID,columnSet);
@@ -112,10 +113,10 @@ public class Table implements WHTable
       // Delete all values
       for (int i = 0 ; i < columns.length ; i++)
       {
-        ts.setTableColumnValue(tableName,rowID,columns[i],null);
+        setTableColumnValue(rowID,columns[i],null);
       }
       // Unlink the row in the linked list
-      ts.removeTableRow(tableName,rowID);
+      removeTableRow(rowID);
     }
   }
   
@@ -123,14 +124,14 @@ public class Table implements WHTable
   public WHValue getValue(long rowID, String columnName)
     throws WHException
   {
-    return ts.getTableColumnValue(tableName,rowID,columnName);
+    return getTableColumnValue(rowID,columnName);
   }
 
   /** Build an accessor that simply scans all the rows in the table */
   public WHAccessor buildAccessor()
     throws WHException
   {
-    return new TableAccessor(ts,tableName,ts.readFirstTableRowID(tableName));
+    return new TableAccessor(this);
   }
 
   /** Get name */
@@ -140,4 +141,123 @@ public class Table implements WHTable
     return tableName;
   }
   
+  // Protected methods
+  
+  /** Add a table row to the linked list for that table.
+  * We add it at the end, although technically we could just as well add at the
+  * beginning.
+  */
+  protected void addTableRow(long rowID)
+    throws WHException
+  {
+    TableTailKey tailKey = new TableTailKey(tableName);
+    LongValue tailValue = (LongValue)ts.get(tailKey);
+    if (tailValue == null)
+    {
+      // First row.  Set the head.
+      TableHeadKey headKey = new TableHeadKey(tableName);
+      ts.put(headKey,new LongValue(rowID));
+    }
+    else
+    {
+      // Set the next pointer for last row.
+      TableRowNextKey nextKey = new TableRowNextKey(tableName,tailValue.getValue());
+      ts.put(nextKey,new LongValue(rowID));
+    }
+    // Set the tail pointer to the new record
+    ts.put(tailKey,new LongValue(rowID));
+  }
+  
+  /** Remove a table row from the linked list for that table.
+  */
+  protected void removeTableRow(long rowID)
+    throws WHException
+  {
+    TableRowPrevKey prevKey = new TableRowPrevKey(tableName,rowID);
+    TableRowNextKey nextKey = new TableRowNextKey(tableName,rowID);
+    LongValue prevValue = (LongValue)ts.get(prevKey);
+    LongValue nextValue = (LongValue)ts.get(nextKey);
+    // Fix up the previous pointer reference
+    if (prevValue == null)
+    {
+      TableHeadKey headKey = new TableHeadKey(tableName);
+      ts.put(headKey,nextValue);
+    }
+    else
+    {
+      TableRowNextKey prevNextKey = new TableRowNextKey(tableName,prevValue.getValue());
+      ts.put(prevNextKey,nextValue);
+    }
+    // Fix up the next pointer reference
+    if (nextValue == null)
+    {
+      TableTailKey tailKey = new TableTailKey(tableName);
+      ts.put(tailKey,prevValue);
+    }
+    else
+    {
+      TableRowPrevKey nextPrevKey = new TableRowPrevKey(tableName,nextValue.getValue());
+      ts.put(nextPrevKey,prevValue);
+    }
+  }
+  
+  /** Set a table column value.
+  */
+  protected void setTableColumnValue(long rowID, String columnName, WHValue value)
+    throws WHException
+  {
+    TableColumnKey key = new TableColumnKey(tableName,rowID,columnName);
+    ts.put(key,value);
+  }
+  
+  /** Get a table column value.
+  */
+  protected WHValue getTableColumnValue(long rowID, String columnName)
+    throws WHException
+  {
+    TableColumnKey key = new TableColumnKey(tableName,rowID,columnName);
+    return ts.get(key);
+  }
+
+  
+  /** Read the first table row ID.
+  */
+  protected long readFirstTableRowID()
+    throws WHException
+  {
+    TableHeadKey headKey = new TableHeadKey(tableName);
+    LongValue headValue = (LongValue)ts.get(headKey);
+    if (headValue == null)
+      return -1L;
+    return headValue.getValue();
+  }
+  
+  /** Reade the next table row ID.
+  */
+  protected long readNextTableRowID(long currentRowID)
+    throws WHException
+  {
+    // Read the row's next pointer
+    TableRowNextKey nextKey = new TableRowNextKey(tableName,currentRowID);
+    LongValue nextValue = (LongValue)ts.get(nextKey);
+    if (nextValue == null)
+      return -1L;
+    return nextValue.getValue();
+  }
+  
+  /** Allocate the next table row ID.
+  */
+  protected long allocateNewTableRow()
+    throws WHException
+  {
+    TableRowIDFactoryKey tlk = new TableRowIDFactoryKey(tableName);
+    LongValue tlv = (LongValue)ts.get(tlk);
+    if (tlv == null)
+      throw new WHDeadlockException();
+    long rval = tlv.getValue();
+    ts.put(tlk,new LongValue(rval+1L));
+    return rval;
+  }
+  
+
 }
\ No newline at end of file

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java?rev=1204298&r1=1204297&r2=1204298&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java
Mon Nov 21 00:17:08 2011
@@ -26,18 +26,16 @@ import java.util.*;
 /** Table accessor. */
 public class TableAccessor implements WHAccessor
 {
-  protected TableStore ts;
-  protected String tableName;
+  protected Table table;
   /** This is the next row to be returned. */
   protected long currentRowID;
     
   /** Constructor */
-  public TableAccessor(TableStore ts, String tableName, long firstRowID)
+  public TableAccessor(Table table)
     throws WHException
   {
-    this.ts = ts;
-    this.tableName = tableName;
-    this.currentRowID = firstRowID;
+    this.table = table;
+    this.currentRowID = table.readFirstTableRowID();
   }
     
   /** Are there any more rows?
@@ -56,7 +54,7 @@ public class TableAccessor implements WH
     long rval = currentRowID;
     if (currentRowID != -1L)
     {
-      currentRowID = ts.readNextTableRowID(tableName,currentRowID);
+      currentRowID = table.readNextTableRowID(currentRowID);
     }
     return rval;
   }

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java?rev=1204298&r1=1204297&r2=1204298&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
Mon Nov 21 00:17:08 2011
@@ -249,121 +249,6 @@ public class TableStore implements WHTab
     return false;
   }
 
-  /** Add a table row to the linked list for that table.
-  * We add it at the end, although technically we could just as well add at the
-  * beginning.
-  */
-  public void addTableRow(String tableName, long rowID)
-    throws WHException
-  {
-    TableTailKey tailKey = new TableTailKey(tableName);
-    LongValue tailValue = (LongValue)currentTransaction.get(tailKey);
-    if (tailValue == null)
-    {
-      // First row.  Set the head.
-      TableHeadKey headKey = new TableHeadKey(tableName);
-      currentTransaction.put(headKey,new LongValue(rowID));
-    }
-    else
-    {
-      // Set the next pointer for last row.
-      TableRowNextKey nextKey = new TableRowNextKey(tableName,tailValue.getValue());
-      currentTransaction.put(nextKey,new LongValue(rowID));
-    }
-    // Set the tail pointer to the new record
-    currentTransaction.put(tailKey,new LongValue(rowID));
-  }
-  
-  /** Remove a table row from the linked list for that table.
-  */
-  public void removeTableRow(String tableName, long rowID)
-    throws WHException
-  {
-    TableRowPrevKey prevKey = new TableRowPrevKey(tableName,rowID);
-    TableRowNextKey nextKey = new TableRowNextKey(tableName,rowID);
-    LongValue prevValue = (LongValue)currentTransaction.get(prevKey);
-    LongValue nextValue = (LongValue)currentTransaction.get(nextKey);
-    // Fix up the previous pointer reference
-    if (prevValue == null)
-    {
-      TableHeadKey headKey = new TableHeadKey(tableName);
-      currentTransaction.put(headKey,nextValue);
-    }
-    else
-    {
-      TableRowNextKey prevNextKey = new TableRowNextKey(tableName,prevValue.getValue());
-      currentTransaction.put(prevNextKey,nextValue);
-    }
-    // Fix up the next pointer reference
-    if (nextValue == null)
-    {
-      TableTailKey tailKey = new TableTailKey(tableName);
-      currentTransaction.put(tailKey,prevValue);
-    }
-    else
-    {
-      TableRowPrevKey nextPrevKey = new TableRowPrevKey(tableName,nextValue.getValue());
-      currentTransaction.put(nextPrevKey,prevValue);
-    }
-  }
-  
-  /** Set a table column value.
-  */
-  public void setTableColumnValue(String tableName, long rowID, String columnName, WHValue
value)
-    throws WHException
-  {
-    TableColumnKey key = new TableColumnKey(tableName,rowID,columnName);
-    currentTransaction.put(key,value);
-  }
-  
-  /** Get a table column value.
-  */
-  public WHValue getTableColumnValue(String tableName, long rowID, String columnName)
-    throws WHException
-  {
-    TableColumnKey key = new TableColumnKey(tableName,rowID,columnName);
-    return currentTransaction.get(key);
-  }
-  
-  /** Read the first table row ID.
-  */
-  public long readFirstTableRowID(String tableName)
-    throws WHException
-  {
-    TableHeadKey headKey = new TableHeadKey(tableName);
-    LongValue headValue = (LongValue)currentTransaction.get(headKey);
-    if (headValue == null)
-      return -1L;
-    return headValue.getValue();
-  }
-  
-  /** Reade the next table row ID.
-  */
-  public long readNextTableRowID(String tableName, long currentRowID)
-    throws WHException
-  {
-    // Read the row's next pointer
-    TableRowNextKey nextKey = new TableRowNextKey(tableName,currentRowID);
-    LongValue nextValue = (LongValue)currentTransaction.get(nextKey);
-    if (nextValue == null)
-      return -1L;
-    return nextValue.getValue();
-  }
-  
-  /** Allocate the next table row ID.
-  */
-  public long allocateNewTableRow(String tableName)
-    throws WHException
-  {
-    TableRowIDFactoryKey tlk = new TableRowIDFactoryKey(tableName);
-    LongValue tlv = (LongValue)currentTransaction.get(tlk);
-    if (tlv == null)
-      throw new WHDeadlockException();
-    long rval = tlv.getValue();
-    currentTransaction.put(tlk,new LongValue(rval+1L));
-    return rval;
-  }
-  
   // Protected classes and methods
 
   /** Delete a table definition.



Mime
View raw message