incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1206460 [2/2] - in /incubator/lcf/branches/CONNECTORS-286/warthog: ./ src/main/java/org/apache/warthog/atomicserialization/ src/main/java/org/apache/warthog/atomictransaction/ src/main/java/org/apache/warthog/common/ src/main/java/org/apac...
Date Sat, 26 Nov 2011 15:27:45 GMT
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=1206460&r1=1206459&r2=1206460&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 Sat Nov 26 15:27:37 2011
@@ -47,18 +47,18 @@ public class IndexAccessor implements WH
   protected NodeQueue queue = new NodeQueue();
   
   /** The current (matching) rowID, to be returned */
-  protected long nextRowID = -1L;
+  protected WHRowID nextRowID = null;
   
   /** Constructor */
   public IndexAccessor(Index index, IndexCriteria[] indexCriteria)
     throws WHException
   {
     this.index = index;
-    this.indexColumns = index.getColumnNames();
+    this.indexColumns = index.getIndexColumns();
     this.comparators = index.getComparators();
     this.indexCriteria = indexCriteria;
-    long rootRowID = index.readIndexRootNode();
-    if (rootRowID != -1L)
+    LongValue rootRowID = index.readIndexRootNode();
+    if (rootRowID != null)
       queue.pushNeedsAnalysis(rootRowID,0);
   }
     
@@ -67,24 +67,24 @@ public class IndexAccessor implements WH
   public boolean hasNext()
     throws WHException
   {
-    return getNextRowID() != -1L;
+    return getNextRowID() != null;
   }
     
   /** Read the next matching relationship row ID,
   */
-  public long getNext()
+  public WHRowID getNext()
     throws WHException
   {
-    long rowID = getNextRowID();
-    nextRowID = -1L;
+    WHRowID rowID = getNextRowID();
+    nextRowID = null;
     return rowID;
   }
   
   /** Get the next row ID */
-  protected long getNextRowID()
+  protected WHRowID getNextRowID()
     throws WHException
   {
-    if (nextRowID != -1L)
+    if (nextRowID != null)
       return nextRowID;
     
     while (true)
@@ -92,7 +92,7 @@ public class IndexAccessor implements WH
       // Find the next node, using the queue
       Node node = queue.pop();
       if (node == null)
-        return -1L;
+        return null;
 
       if (node.getAction() == ACTION_DEREFERENCE)
       {
@@ -103,12 +103,12 @@ public class IndexAccessor implements WH
       if (node.getAction() == ACTION_CHASE_EQUALS)
       {
         // We can skip all analysis, and just chase the equals chain.
-        long chaseRowID = node.getRowID();
+        LongValue chaseRowID = node.getRowID();
         // Push the rowID, then chase the equals chain.
         queue.pushNeedsDereference(chaseRowID);
         // Now find the next node in the equals chain.
-        long nextEqualsNode = index.readIndexNodeEqualsNode(chaseRowID,indexColumns[indexColumns.length-1]);
-        if (nextEqualsNode != -1L)
+        LongValue nextEqualsNode = index.readIndexNodeEqualsNode(chaseRowID,indexColumns[indexColumns.length-1]);
+        if (nextEqualsNode != null)
         {
           // Because it's equals chain, we know that it is unnecessary to evaluate its fields, so note that when
           // we queue it.
@@ -119,7 +119,7 @@ public class IndexAccessor implements WH
       
       // This node needs analysis.
       int columnIndex = node.getColumnIndex();
-      long rowID = node.getRowID();
+      LongValue rowID = node.getRowID();
       
       // Evaluate the node, pushing its descendents, and make a decision whether to
       // use the row or not.
@@ -144,8 +144,8 @@ public class IndexAccessor implements WH
       if ((criteria & IndexCriteria.SIGNAL_GREATER) != 0)
       {
         // Dereference the greater child for this column and push that node for analysis
-        long childRowID = index.readIndexNodeGreaterNode(rowID,indexColumns[columnIndex]);
-        if (childRowID != -1L)
+        LongValue childRowID = index.readIndexNodeGreaterNode(rowID,indexColumns[columnIndex]);
+        if (childRowID != null)
           queue.pushNeedsAnalysis(childRowID,columnIndex);
       }
       // Do the equals children next
@@ -161,8 +161,8 @@ public class IndexAccessor implements WH
       if ((criteria & IndexCriteria.SIGNAL_LESSER) != 0)
       {
         // Dereference the lesser child for this column and push that node for analysis
-        long childRowID = index.readIndexNodeLesserNode(rowID,indexColumns[columnIndex]);
-        if (childRowID != -1L)
+        LongValue childRowID = index.readIndexNodeLesserNode(rowID,indexColumns[columnIndex]);
+        if (childRowID != null)
           queue.pushNeedsAnalysis(childRowID,columnIndex);
       }
     }
@@ -185,17 +185,17 @@ public class IndexAccessor implements WH
     {
     }
     
-    public void pushNeedsAnalysis(long rowID, int columnIndex)
+    public void pushNeedsAnalysis(LongValue rowID, int columnIndex)
     {
       nodeList.add(new Node(rowID,columnIndex,ACTION_FULL_ANALYSIS));
     }
     
-    public void pushChaseEquals(long rowID)
+    public void pushChaseEquals(LongValue rowID)
     {
       nodeList.add(new Node(rowID,-1,ACTION_CHASE_EQUALS));
     }
     
-    public void pushNeedsDereference(long rowID)
+    public void pushNeedsDereference(LongValue rowID)
     {
       nodeList.add(new Node(rowID,-1,ACTION_DEREFERENCE));
     }
@@ -211,12 +211,12 @@ public class IndexAccessor implements WH
   /** A node in the queue */
   protected static class Node
   {
-    protected long rowID;
+    protected LongValue rowID;
     protected int columnIndex;
     protected int action;
     
     /** Constructor */
-    public Node(long rowID, int columnIndex, int action)
+    public Node(LongValue rowID, int columnIndex, int action)
     {
       this.rowID = rowID;
       this.columnIndex = columnIndex;
@@ -225,7 +225,7 @@ public class IndexAccessor implements WH
     
     /** Get the node id.
     */
-    public long getRowID()
+    public LongValue getRowID()
     {
       return rowID;
     }

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeKey.java?rev=1206460&r1=1206459&r2=1206460&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeKey.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeKey.java Sat Nov 26 15:27:37 2011
@@ -28,6 +28,8 @@ public class IndexNodeKey implements WHK
   protected String indexName;
   protected long rowID;
   protected String columnName;
+  
+  protected long hashCodeValue;
     
   /** Constructor */
   public IndexNodeKey(String indexName, long rowID, String columnName)
@@ -35,6 +37,7 @@ public class IndexNodeKey implements WHK
     this.indexName = indexName;
     this.rowID = rowID;
     this.columnName = columnName;
+    hashCodeValue = calculateHashCode(indexName,rowID,columnName);
   }
     
   public IndexNodeKey(byte[] data)
@@ -43,6 +46,7 @@ public class IndexNodeKey implements WHK
     this.indexName = StringKey.readObject(bp);
     this.rowID = LongKey.readObject(bp);
     this.columnName = StringKey.readObject(bp);
+    hashCodeValue = calculateHashCode(indexName,rowID,columnName);
   }
 
   public byte[] serializeObject()
@@ -58,6 +62,11 @@ public class IndexNodeKey implements WHK
     
   public long getHashCode()
   {
+    return hashCodeValue;
+  }
+  
+  public static long calculateHashCode(String indexName, long rowID, String columnName)
+  {
     return StringKey.calculateHashCode(indexName) + LongKey.calculateHashCode(rowID) +
       StringKey.calculateHashCode(columnName);
   }

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=1206460&r1=1206459&r2=1206460&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 Sat Nov 26 15:27:37 2011
@@ -51,8 +51,10 @@ public class Table implements WHTable
   public void insertRow(String[] columns, WHValue[] values)
     throws WHException
   {
+    if (columns.length != values.length)
+      throw new WHException("Column count must agree with value count");
     // Allocate the row
-    long rowID = allocateNewTableRow();
+    LongValue rowID = allocateNewTableRow();
     // Link in the row
     addTableRow(rowID);
     // Set the values
@@ -69,17 +71,19 @@ public class Table implements WHTable
     WHAccessor accessor, WHFilter filter)
     throws WHException
   {
+    if (columns.length != values.length)
+      throw new WHException("Column count must agree with value count");
     // Convert the columns to a set, for convenience later
     Set<String> columnSet = new HashSet<String>();
     for (int i = 0 ; i < columns.length ; i++)
     {
       columnSet.add(columns[i]);
     }
-    WHAccessor fa = new FilterAccessor(accessor,new TableRelationship(this),filter);
+    WHAccessor fa = new FilterAccessor(accessor,this,filter);
     // Update the rows one at a time
     while (fa.hasNext())
     {
-      long rowID = fa.getNext();
+      LongValue rowID = (LongValue)fa.getNext();
       
       // Note: The problem with this loop is that I cannot guarantee that the accessor will continue
       // to work right after I delete and re-add the row to/from the indexes.  If the accessor is an
@@ -103,11 +107,11 @@ public class Table implements WHTable
   public void deleteRows(WHAccessor accessor, WHFilter filter)
     throws WHException
   {
-    WHAccessor fa = new FilterAccessor(accessor,new TableRelationship(this),filter);
+    WHAccessor fa = new FilterAccessor(accessor,this,filter);
     // Read the rows one at a time
     while (fa.hasNext())
     {
-      long rowID = fa.getNext();
+      LongValue rowID = (LongValue)fa.getNext();
       // Delete the row from all indexes
       ts.deleteIndexRow(tableName,rowID,null);
       // Delete all values
@@ -121,10 +125,10 @@ public class Table implements WHTable
   }
   
   /** Get the data for a given row and column. */
-  public WHValue getValue(long rowID, String columnName)
+  public WHValue getValue(WHRowID rowID, String columnName)
     throws WHException
   {
-    return getTableColumnValue(rowID,columnName);
+    return getTableColumnValue((LongValue)rowID,columnName);
   }
 
   /** Build an accessor that simply scans all the rows in the table */
@@ -157,7 +161,7 @@ public class Table implements WHTable
   * We add it at the end, although technically we could just as well add at the
   * beginning.
   */
-  protected void addTableRow(long rowID)
+  protected void addTableRow(LongValue rowID)
     throws WHException
   {
     TableTailKey tailKey = new TableTailKey(tableName);
@@ -166,25 +170,25 @@ public class Table implements WHTable
     {
       // First row.  Set the head.
       TableHeadKey headKey = new TableHeadKey(tableName);
-      ts.put(headKey,new LongValue(rowID));
+      ts.put(headKey,rowID);
     }
     else
     {
       // Set the next pointer for last row.
       TableRowNextKey nextKey = new TableRowNextKey(tableName,tailValue.getValue());
-      ts.put(nextKey,new LongValue(rowID));
+      ts.put(nextKey,rowID);
     }
     // Set the tail pointer to the new record
-    ts.put(tailKey,new LongValue(rowID));
+    ts.put(tailKey,rowID);
   }
   
   /** Remove a table row from the linked list for that table.
   */
-  protected void removeTableRow(long rowID)
+  protected void removeTableRow(LongValue rowID)
     throws WHException
   {
-    TableRowPrevKey prevKey = new TableRowPrevKey(tableName,rowID);
-    TableRowNextKey nextKey = new TableRowNextKey(tableName,rowID);
+    TableRowPrevKey prevKey = new TableRowPrevKey(tableName,rowID.getValue());
+    TableRowNextKey nextKey = new TableRowNextKey(tableName,rowID.getValue());
     LongValue prevValue = (LongValue)ts.get(prevKey);
     LongValue nextValue = (LongValue)ts.get(nextKey);
     // Fix up the previous pointer reference
@@ -213,60 +217,53 @@ public class Table implements WHTable
   
   /** Set a table column value.
   */
-  protected void setTableColumnValue(long rowID, String columnName, WHValue value)
+  protected void setTableColumnValue(LongValue rowID, String columnName, WHValue value)
     throws WHException
   {
-    TableColumnKey key = new TableColumnKey(tableName,rowID,columnName);
+    TableColumnKey key = new TableColumnKey(tableName,rowID.getValue(),columnName);
     ts.put(key,value);
   }
   
   /** Get a table column value.
   */
-  protected WHValue getTableColumnValue(long rowID, String columnName)
+  protected WHValue getTableColumnValue(LongValue rowID, String columnName)
     throws WHException
   {
-    TableColumnKey key = new TableColumnKey(tableName,rowID,columnName);
+    TableColumnKey key = new TableColumnKey(tableName,rowID.getValue(),columnName);
     return ts.get(key);
   }
 
   
   /** Read the first table row ID.
   */
-  protected long readFirstTableRowID()
+  protected LongValue readFirstTableRowID()
     throws WHException
   {
     TableHeadKey headKey = new TableHeadKey(tableName);
-    LongValue headValue = (LongValue)ts.get(headKey);
-    if (headValue == null)
-      return -1L;
-    return headValue.getValue();
+    return (LongValue)ts.get(headKey);
   }
   
   /** Reade the next table row ID.
   */
-  protected long readNextTableRowID(long currentRowID)
+  protected LongValue readNextTableRowID(LongValue 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();
+    TableRowNextKey nextKey = new TableRowNextKey(tableName,currentRowID.getValue());
+    return (LongValue)ts.get(nextKey);
   }
   
   /** Allocate the next table row ID.
   */
-  protected long allocateNewTableRow()
+  protected LongValue 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;
+      throw new WHConcurrencyException();
+    ts.put(tlk,new LongValue(tlv.getValue()+1L));
+    return tlv;
   }
   
 

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=1206460&r1=1206459&r2=1206460&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 Sat Nov 26 15:27:37 2011
@@ -28,14 +28,14 @@ public class TableAccessor implements WH
 {
   protected Table table;
   /** This is the next row to be returned. */
-  protected long currentRowID;
+  protected LongValue currentRowID;
     
   /** Constructor */
   public TableAccessor(Table table)
     throws WHException
   {
     this.table = table;
-    this.currentRowID = table.readFirstTableRowID();
+    currentRowID = table.readFirstTableRowID();
   }
     
   /** Are there any more rows?
@@ -43,16 +43,16 @@ public class TableAccessor implements WH
   public boolean hasNext()
     throws WHException
   {
-    return currentRowID != -1L;
+    return currentRowID != null;
   }
     
   /** Read the next matching relationship row ID,
   */
-  public long getNext()
+  public WHRowID getNext()
     throws WHException
   {
-    long rval = currentRowID;
-    if (currentRowID != -1L)
+    WHRowID rval = currentRowID;
+    if (currentRowID != null)
     {
       currentRowID = table.readNextTableRowID(currentRowID);
     }

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableColumnKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableColumnKey.java?rev=1206460&r1=1206459&r2=1206460&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableColumnKey.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableColumnKey.java Sat Nov 26 15:27:37 2011
@@ -28,12 +28,15 @@ public class TableColumnKey implements W
   protected long rowID;
   protected String columnName;
     
+  protected long hashCodeValue;
+  
   /** Constructor */
   public TableColumnKey(String tableName, long rowID, String columnName)
   {
     this.tableName = tableName;
     this.rowID = rowID;
     this.columnName = columnName;
+    hashCodeValue = calculateHashCode(tableName,rowID,columnName);
   }
     
   public TableColumnKey(byte[] data)
@@ -42,6 +45,7 @@ public class TableColumnKey implements W
     this.tableName = StringKey.readObject(bp);
     this.rowID = LongKey.readObject(bp);
     this.columnName = StringKey.readObject(bp);
+    hashCodeValue = calculateHashCode(tableName,rowID,columnName);
   }
 
   public byte[] serializeObject()
@@ -57,6 +61,11 @@ public class TableColumnKey implements W
     
   public long getHashCode()
   {
+    return hashCodeValue;
+  }
+  
+  public static long calculateHashCode(String tableName, long rowID, String columnName)
+  {
     return StringKey.calculateHashCode(tableName) + LongKey.calculateHashCode(rowID)
       + StringKey.calculateHashCode(columnName);
   }

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableRowKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableRowKey.java?rev=1206460&r1=1206459&r2=1206460&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableRowKey.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableRowKey.java Sat Nov 26 15:27:37 2011
@@ -27,12 +27,15 @@ public class TableRowKey implements WHKe
 {
   protected String tableName;
   protected long rowID;
-    
+  
+  protected long hashCodeValue;
+  
   /** Constructor */
   public TableRowKey(String tableName, long rowID)
   {
     this.tableName = tableName;
     this.rowID = rowID;
+    hashCodeValue = calculateHashCode(tableName,rowID);
   }
     
   public TableRowKey(byte[] data)
@@ -40,6 +43,7 @@ public class TableRowKey implements WHKe
     BufferPointer bp = new BufferPointer(data);
     this.tableName = StringKey.readObject(bp);
     this.rowID = LongKey.readObject(bp);
+    hashCodeValue = calculateHashCode(tableName,rowID);
   }
 
   public byte[] serializeObject()
@@ -54,6 +58,11 @@ public class TableRowKey implements WHKe
     
   public long getHashCode()
   {
+    return hashCodeValue;
+  }
+  
+  public static long calculateHashCode(String tableName, long rowID)
+  {
     return StringKey.calculateHashCode(tableName) + LongKey.calculateHashCode(rowID);
   }
     

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=1206460&r1=1206459&r2=1206460&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 Sat Nov 26 15:27:37 2011
@@ -148,14 +148,14 @@ public class TableStore implements WHTab
     if (i != null)
       throw new WHException("Index already exists");
     IndexKey ik = new IndexKey(name);
-    IndexValue iv = new IndexValue(name,columnNames,comparatorClasses,unique);
+    IndexValue iv = new IndexValue(t.getName(),columnNames,comparatorClasses,unique);
     i = new Index(this,t,name,columnNames,comparatorClasses,unique);
     currentTransaction.put(ik,iv);
     indexes.put(name,i);
     TableIndexKey tik = new TableIndexKey(t.getName());
     StringArray tiv = (StringArray)currentTransaction.get(tik);
     if (tiv == null)
-      throw new WHDeadlockException();
+      throw new WHConcurrencyException();
     String[] indexList = tiv.getValue();
     String[] newIndexList = new String[indexList.length + 1];
     for (int j = 0 ; j < indexList.length ; j++)
@@ -183,7 +183,7 @@ public class TableStore implements WHTab
   }
   
   /** Perform a query */
-  public WHQueryResult performQuery(QueryDescription specification)
+  public WHRelationship performQuery(QueryDescription specification)
     throws WHException
   {
     if (currentTransaction == null)
@@ -212,7 +212,7 @@ public class TableStore implements WHTab
   
   /** Delete a table row from all the indexes that are based on a table.
   */
-  public void deleteIndexRow(String tableName, long rowID, Set<String> columns)
+  public void deleteIndexRow(String tableName, LongValue rowID, Set<String> columns)
     throws WHException
   {
     Index[] indexes = findIndexes(tableName);
@@ -225,7 +225,7 @@ public class TableStore implements WHTab
   
   /** Add a table row to all the indexes that are based on a table.
   */
-  public void addIndexRow(String tableName, long rowID, Set<String> columns)
+  public void addIndexRow(String tableName, LongValue rowID, Set<String> columns)
     throws WHException
   {
     Index[] indexes = findIndexes(tableName);
@@ -285,7 +285,7 @@ public class TableStore implements WHTab
     Table t = (Table)i.getTable();
     Index[] indexList = findIndexes(t.getName());
     if (indexList.length == 0)
-      throw new WHDeadlockException();
+      throw new WHConcurrencyException();
     String[] newIndexList = new String[indexList.length - 1];
     int k = 0;
     for (int j = 0 ; j < indexList.length ; j++)
@@ -298,7 +298,7 @@ public class TableStore implements WHTab
       }
     }
     if (k != newIndexList.length)
-      throw new WHDeadlockException();
+      throw new WHConcurrencyException();
     currentTransaction.put(new TableIndexKey(t.getName()),new StringArray(newIndexList));
     indexesPerTable.remove(t.getName());
 
@@ -338,7 +338,7 @@ public class TableStore implements WHTab
       return null;
     Table t = findTable(indexValue.getTableName());
     if (t == null)
-      throw new WHDeadlockException();
+      throw new WHConcurrencyException();
     i = new Index(this,t,name,indexValue.getColumnNames(),indexValue.getComparatorClassNames(),
       indexValue.getUnique());
     indexes.put(name,i);
@@ -356,14 +356,14 @@ public class TableStore implements WHTab
       TableIndexKey tik = new TableIndexKey(tableName);
       StringArray tiv = (StringArray)currentTransaction.get(tik);
       if (tiv == null)
-        throw new WHDeadlockException();
+        throw new WHConcurrencyException();
       String[] indexNames = tiv.getValue();
       indexes = new Index[indexNames.length];
       for (int i = 0; i < indexes.length ; i++)
       {
         indexes[i] = findIndex(indexNames[i]);
         if (indexes[i] == null)
-          throw new WHDeadlockException();
+          throw new WHConcurrencyException();
       }
       indexesPerTable.put(tableName,indexes);
     }

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemAtomicKeyValueStore.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemAtomicKeyValueStore.java?rev=1206460&r1=1206459&r2=1206460&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemAtomicKeyValueStore.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemAtomicKeyValueStore.java Sat Nov 26 15:27:37 2011
@@ -26,11 +26,12 @@ import java.util.*;
 */
 public class InMemAtomicKeyValueStore implements WHAtomicKeyValueStore
 {
-  protected Map<WrappedKey,WHValue> database = new HashMap<WrappedKey,WHValue>();
+  protected Map<WrappedKey,WHValue> database;
   
   /** Constructor */
-  public InMemAtomicKeyValueStore()
+  public InMemAtomicKeyValueStore(int initialSize)
   {
+    database = new HashMap<WrappedKey,WHValue>(initialSize);
   }
   
   /** Get a value */
@@ -59,9 +60,11 @@ public class InMemAtomicKeyValueStore im
         WrappedKey wrappedKey = new WrappedKey(key);
         WHValue value = database.get(wrappedKey);
         WHValue otherValue = checkValues.get(key);
+	if (value == null && otherValue == null)
+          continue;
         if (value != null && otherValue != null && value.isEquals(otherValue))
           continue;
-        throw new WHDeadlockException();
+        throw new WHConcurrencyException();
       }
     }
   }

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemTransactionImpl.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemTransactionImpl.java?rev=1206460&r1=1206459&r2=1206460&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemTransactionImpl.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemTransactionImpl.java Sat Nov 26 15:27:37 2011
@@ -75,7 +75,10 @@ public class InMemTransactionImpl implem
   public void commit()
     throws WHException
   {
-    underlyingStore.setAll(checkData,localData);
+    if (localData != null)
+      underlyingStore.setAll(checkData,localData);
+    else
+      underlyingStore.check(checkData);
   }
   
   /** Abandon this transaction.

Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/PerformanceTest.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/PerformanceTest.java?rev=1206460&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/PerformanceTest.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/PerformanceTest.java Sat Nov 26 15:27:37 2011
@@ -0,0 +1,294 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.warthog.tests;
+
+import org.apache.warthog.interfaces.*;
+import org.apache.warthog.common.*;
+import org.apache.warthog.tablestore.*;
+import org.junit.*;
+import static org.junit.Assert.*;
+import java.util.*;
+
+public class PerformanceTest
+{
+
+  @Test
+  public void singleThreadRowCreateTest()
+    throws Exception
+  {
+    WHTableStore ts = new TableStore(new InMemTransactionalStoreImpl(new InMemAtomicKeyValueStore(10000000)));
+
+    ts.beginTransaction();
+    ts.createTable("testtable",new String[]{"colA","colB","colC","colD","colE","colF","colG","colH","colI","colJ"});
+    ts.commitTransaction();
+
+    ts.beginTransaction();
+    WHTable table = ts.lookupTable("testtable");
+    ts.createIndex("testindex1",table,
+      new String[]{"colB","colA"},
+      new String[]{"org.apache.warthog.common.StringComparatorAscending",
+        "org.apache.warthog.common.LongComparatorAscending"},false);
+    ts.createIndex("testindex2",table,
+      new String[]{"colD","colC"},
+      new String[]{"org.apache.warthog.common.StringComparatorAscending",
+        "org.apache.warthog.common.LongComparatorAscending"},false);
+    ts.createIndex("testindex3",table,
+      new String[]{"colF","colE"},
+      new String[]{"org.apache.warthog.common.StringComparatorAscending",
+        "org.apache.warthog.common.LongComparatorAscending"},false);
+    ts.createIndex("testindex4",table,
+      new String[]{"colH","colG"},
+      new String[]{"org.apache.warthog.common.StringComparatorAscending",
+        "org.apache.warthog.common.LongComparatorAscending"},false);
+    ts.createIndex("testindex5",table,
+      new String[]{"colJ","colI"},
+      new String[]{"org.apache.warthog.common.StringComparatorAscending",
+        "org.apache.warthog.common.LongComparatorAscending"},false);
+    ts.commitTransaction();
+
+    int rowCount = 10000;
+    Random r = new Random();
+    String[] str1Values = new String[rowCount];
+    long[] long1Values = new long[rowCount];
+    String[] str2Values = new String[rowCount];
+    long[] long2Values = new long[rowCount];
+    String[] str3Values = new String[rowCount];
+    long[] long3Values = new long[rowCount];
+    String[] str4Values = new String[rowCount];
+    long[] long4Values = new long[rowCount];
+    String[] str5Values = new String[rowCount];
+    long[] long5Values = new long[rowCount];
+    for (int i = 0 ; i < rowCount ; i++)
+    {
+      str1Values[i] = randomString(r);
+      long1Values[i] = randomLong(r);
+      str2Values[i] = randomString(r);
+      long2Values[i] = randomLong(r);
+      str3Values[i] = randomString(r);
+      long3Values[i] = randomLong(r);
+      str4Values[i] = randomString(r);
+      long4Values[i] = randomLong(r);
+      str5Values[i] = randomString(r);
+      long5Values[i] = randomLong(r);
+    }
+    long startTime = System.currentTimeMillis();
+    for (int i = 0 ; i < rowCount ; i++)
+    {
+      ts.beginTransaction();
+      table = ts.lookupTable("testtable");
+      table.insertRow(new String[]{"colA","colB","colC","colD","colE","colF","colG","colH","colI","colJ"},
+        new WHValue[]{
+          new LongValue(long1Values[i]),new StringValue(str1Values[i]),
+          new LongValue(long2Values[i]),new StringValue(str2Values[i]),
+          new LongValue(long3Values[i]),new StringValue(str3Values[i]),
+          new LongValue(long4Values[i]),new StringValue(str4Values[i]),
+          new LongValue(long5Values[i]),new StringValue(str5Values[i])});
+      ts.commitTransaction();
+    }
+    System.out.println("Create of "+Integer.toString(rowCount)+" rows took "+new Long(System.currentTimeMillis() - startTime).toString()+" ms");
+  }
+  
+  @Test
+  public void multiThreadWriteQueryTest()
+    throws Exception
+  {
+    WHAtomicKeyValueStore store = new InMemAtomicKeyValueStore(10000000);
+    
+    WHTableStore ts = new TableStore(new InMemTransactionalStoreImpl(store));
+
+    ts.beginTransaction();
+    ts.createTable("testtable",new String[]{"colA","colB","colC","colD","colE","colF","colG","colH","colI","colJ"});
+    ts.commitTransaction();
+
+    ts.beginTransaction();
+    WHTable table = ts.lookupTable("testtable");
+    ts.createIndex("testindex1",table,
+      new String[]{"colB","colA"},
+      new String[]{"org.apache.warthog.common.StringComparatorAscending",
+        "org.apache.warthog.common.LongComparatorAscending"},false);
+    ts.createIndex("testindex2",table,
+      new String[]{"colD","colC"},
+      new String[]{"org.apache.warthog.common.StringComparatorAscending",
+        "org.apache.warthog.common.LongComparatorAscending"},false);
+    ts.createIndex("testindex3",table,
+      new String[]{"colF","colE"},
+      new String[]{"org.apache.warthog.common.StringComparatorAscending",
+        "org.apache.warthog.common.LongComparatorAscending"},false);
+    ts.createIndex("testindex4",table,
+      new String[]{"colH","colG"},
+      new String[]{"org.apache.warthog.common.StringComparatorAscending",
+        "org.apache.warthog.common.LongComparatorAscending"},false);
+    ts.createIndex("testindex5",table,
+      new String[]{"colJ","colI"},
+      new String[]{"org.apache.warthog.common.StringComparatorAscending",
+        "org.apache.warthog.common.LongComparatorAscending"},false);
+    ts.commitTransaction();
+
+    int threadCount = 8;
+    TaskThread[] threads = new TaskThread[threadCount];
+    for (int i = 0 ; i < threadCount ; i++)
+    {
+      threads[i] = new TaskThread("Worker thread "+i,store);
+    }
+    
+    long startTime = System.currentTimeMillis();
+    for (int i = 0 ; i < threadCount ; i++)
+    {
+      threads[i].start();
+    }
+    
+    // Join at the end
+    
+    int contentions = 0;
+    for (int i = 0 ; i < threadCount ; i++)
+    {
+      threads[i].join();
+      Throwable e = threads[i].getException();
+      if (e != null)
+      {
+        if (e instanceof Error)
+          throw (Error)e;
+        if (e instanceof RuntimeException)
+          throw (RuntimeException)e;
+        throw (Exception)e;
+      }
+      contentions += threads[i].getContentions();
+    }
+
+    System.out.println("Task took "+new Long(System.currentTimeMillis()-startTime)+" ms and had "+Integer.toString(contentions)+" contention retries");
+  }
+  
+  // Protected methods
+  
+  protected static String randomString(Random r)
+  {
+    return new Long(randomLong(r)).toString();
+  }
+  
+  protected static long randomLong(Random r)
+  {
+    return r.nextLong();
+  }
+  
+  protected static class TaskThread extends Thread
+  {
+    protected int contentions = 0;
+    protected WHAtomicKeyValueStore store;
+    protected Throwable exception;
+    protected Random r = new Random();
+    
+    public TaskThread(String name, WHAtomicKeyValueStore store)
+    {
+      super();
+      this.store = store;
+      setName(name);
+    }
+    
+    public void run()
+    {
+      try
+      {
+        WHTableStore ts = new TableStore(new InMemTransactionalStoreImpl(store));
+        performTask(ts);
+      }
+      catch (Throwable e)
+      {
+        exception = e;
+      }
+    }
+    
+    public Throwable getException()
+    {
+      return exception;
+    }
+    
+    public int getContentions()
+    {
+      return contentions;
+    }
+    
+    protected void backOff()
+      throws InterruptedException
+    {
+      contentions++;
+      //Thread.sleep(r.next(500));
+      Thread.yield();
+    }
+    
+    protected void performTask(WHTableStore ts)
+      throws InterruptedException, WHException
+    {
+      // Task consists of a certain number of inserts, deletes, modifies, and queries
+      int repeatCount = 1000;
+      for (int i = 0 ; i < repeatCount ; i++)
+      {
+        // Add a row
+        while (true)
+        {
+          ts.beginTransaction();
+          try
+          {
+            WHTable table = ts.lookupTable("testtable");
+            table.insertRow(new String[]{"colA","colB","colC","colD","colE","colF","colG","colH","colI","colJ"},
+              new WHValue[]{
+                new LongValue(randomLong(r)),new StringValue(randomString(r)),
+                new LongValue(randomLong(r)),new StringValue(randomString(r)),
+                new LongValue(randomLong(r)),new StringValue(randomString(r)),
+                new LongValue(randomLong(r)),new StringValue(randomString(r)),
+                new LongValue(randomLong(r)),new StringValue(randomString(r))});
+            ts.commitTransaction();
+            break;
+          }
+          catch (WHConcurrencyException e)
+          {
+            ts.abandonTransaction();
+            backOff();
+            continue;
+          }
+        }
+        
+        // Do a query
+        while (true)
+        {
+          ts.beginTransaction();
+          try
+          {
+            WHIndex index = ts.lookupIndex("testindex1");
+            WHAccessor accessor = index.buildAccessor(new IndexCriteria[]{
+              new CriteriaBetween(new StringValue("1"),new StringValue("2")),
+              null});
+            while (accessor.hasNext())
+              accessor.getNext();
+            ts.commitTransaction();
+            break;
+          }
+          catch (WHConcurrencyException e)
+          {
+            ts.abandonTransaction();
+            backOff();
+            continue;
+          }
+        }
+
+      }
+    }
+    
+  }
+  
+}
\ No newline at end of file

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/PerformanceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/PerformanceTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/SanityTest.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/SanityTest.java?rev=1206460&r1=1206459&r2=1206460&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/SanityTest.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/SanityTest.java Sat Nov 26 15:27:37 2011
@@ -19,18 +19,489 @@
 package org.apache.warthog.tests;
 
 import org.apache.warthog.interfaces.*;
+import org.apache.warthog.common.*;
+import org.apache.warthog.tablestore.*;
 import org.junit.*;
 import static org.junit.Assert.*;
+import java.util.*;
 
 public class SanityTest
 {
 
   @Test
-  public void writeAndQuery()
+  public void basicTable()
     throws Exception
   {
-    // MHL
-    //assertEquals(resolved.toASCIIString(),"http://bar.com");
+    WHTableStore ts = createInMemTableStore();
+    
+    ts.beginTransaction();
+    ts.createTable("testtable",new String[]{"colA","colB","colC"});
+    ts.commitTransaction();
+    
+    ts.beginTransaction();
+    WHTable table = ts.lookupTable("testtable");
+    table.insertRow(new String[]{"colA","colC"},new WHValue[]{new LongValue(123L),new StringValue("hello")});
+    ts.commitTransaction();
+    
+    ts.beginTransaction();
+    table = ts.lookupTable("testtable");
+    table.insertRow(new String[]{"colA","colC","colB"},new WHValue[]{new LongValue(456L),new StringValue("goodbye"),new BooleanValue(true)});
+    ts.commitTransaction();
+
+    ts.beginTransaction();
+    table = ts.lookupTable("testtable");
+    WHAccessor accessor = table.buildAccessor();
+    boolean seen123 = false;
+    boolean seen456 = false;
+    while (accessor.hasNext())
+    {
+      WHRowID rowID = accessor.getNext();
+      WHValue value = table.getValue(rowID,"colA");
+      assertNotNull(value);
+      assertEquals(value.getClass().getName(),"org.apache.warthog.common.LongValue");
+      LongValue lv = (LongValue)value;
+      if (lv.getValue() == 123L)
+        seen123 = true;
+      else if (lv.getValue() == 456L)
+        seen456 = true;
+      else
+        throw new Exception("Unexpected value: "+new Long(lv.getValue()).toString());
+    }
+    if (seen123 == false || seen456 == false)
+      throw new Exception("Missing rows");
+    ts.abandonTransaction();
+    
+    ts.beginTransaction();
+    table = ts.lookupTable("testtable");
+    table.updateRows(new String[]{"colC"},new WHValue[]{new StringValue("abcdefg")},table.buildAccessor(),null);
+    ts.commitTransaction();
+    
+    ts.beginTransaction();
+    table = ts.lookupTable("testtable");
+    accessor = table.buildAccessor();
+    while (accessor.hasNext())
+    {
+      WHRowID rowID = accessor.getNext();
+      WHValue value = table.getValue(rowID,"colC");
+      assertNotNull(value);
+      assertEquals("org.apache.warthog.common.StringValue",value.getClass().getName());
+      assertEquals("abcdefg",((StringValue)value).getValue());
+    }
+    ts.abandonTransaction();
+    
+    ts.beginTransaction();
+    ts.dropTable("testtable");
+    ts.commitTransaction();
+  }
+  
+  @Test
+  public void basicTableIndex()
+    throws Exception
+  {
+    WHTableStore ts = createInMemTableStore();
+  
+    buildNonOverlappingTestTable(ts);
+    
+    // Now build a one-column unique index on colA
+    ts.beginTransaction();
+    WHTable table = ts.lookupTable("testtable");
+    ts.createIndex("testindex",table,new String[]{"colA"},new String[]{"org.apache.warthog.common.LongComparatorAscending"},true);
+    ts.commitTransaction();
+    
+    // Read in index order
+    ts.beginTransaction();
+    WHIndex index = ts.lookupIndex("testindex");
+    WHAccessor accessor = index.buildAccessor();
+    assertEquals(accessor.hasNext(),true);
+    WHRowID rowID = accessor.getNext();
+    assertNotNull(rowID);
+    WHValue value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(111L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(123L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(124L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(456L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),false);
+    ts.abandonTransaction();
+    
+    // Now add a row while the index is set up to see if it appears
+    ts.beginTransaction();
+    table = ts.lookupTable("testtable");
+    table.insertRow(new String[]{"colA","colB"},new WHValue[]{new LongValue(333L),new StringValue("><")});
+    ts.commitTransaction();
+    
+    // Read in index order
+    ts.beginTransaction();
+    index = ts.lookupIndex("testindex");
+    accessor = index.buildAccessor();
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(111L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(123L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(124L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(333L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(456L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),false);
+    ts.abandonTransaction();
+    
+    // Build a bunch of accessors and see if they do what we expect
+    ts.beginTransaction();
+    index = ts.lookupIndex("testindex");
+    accessor = index.buildAccessor(new IndexCriteria[]{new CriteriaEquals(new LongValue(124L))});
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(124L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),false);
+    ts.abandonTransaction();
+
+    ts.beginTransaction();
+    index = ts.lookupIndex("testindex");
+    accessor = index.buildAccessor(new IndexCriteria[]{new CriteriaEqualsOrBefore(new LongValue(124L))});
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(111L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(123L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(124L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),false);
+    ts.abandonTransaction();
+
+    ts.beginTransaction();
+    index = ts.lookupIndex("testindex");
+    accessor = index.buildAccessor(new IndexCriteria[]{new CriteriaEqualsOrAfter(new LongValue(124L))});
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(124L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(333L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(456L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),false);
+    ts.abandonTransaction();
+
+    ts.beginTransaction();
+    index = ts.lookupIndex("testindex");
+    accessor = index.buildAccessor(new IndexCriteria[]{new CriteriaBefore(new LongValue(124L))});
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(111L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(123L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),false);
+    ts.abandonTransaction();
+
+    ts.beginTransaction();
+    index = ts.lookupIndex("testindex");
+    accessor = index.buildAccessor(new IndexCriteria[]{new CriteriaAfter(new LongValue(124L))});
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(333L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(456L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),false);
+    ts.abandonTransaction();
+    
+    ts.beginTransaction();
+    index = ts.lookupIndex("testindex");
+    accessor = index.buildAccessor(new IndexCriteria[]{new CriteriaEqualsMultiple(new WHValue[]{new LongValue(123L),new LongValue(333L)})});
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(123L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(333L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),false);
+    ts.abandonTransaction();
+
+    // Delete a table row and see if it goes away from the index
+    ts.beginTransaction();
+    table = ts.lookupTable("testtable");
+    index = ts.lookupIndex("testindex");
+    table.deleteRows(index.buildAccessor(new IndexCriteria[]{new CriteriaEquals(new LongValue(124L))}),null);
+    ts.commitTransaction();
+
+    // Go through the iterator to see if it's gone
+    ts.beginTransaction();
+    index = ts.lookupIndex("testindex");
+    accessor = index.buildAccessor();
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(111L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(123L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(333L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(456L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),false);
+    ts.abandonTransaction();
+
+    ts.beginTransaction();
+    ts.dropIndex("testindex");
+    ts.commitTransaction();
+    
+  }
+  
+  @Test
+  public void twoColumnIndex()
+    throws Exception
+  {
+    WHTableStore ts = createInMemTableStore();
+  
+    buildOverlappingTestTable(ts);
+    
+    // Now build a two-column unique index on colA
+    ts.beginTransaction();
+    WHTable table = ts.lookupTable("testtable");
+    ts.createIndex("testindex",table,
+      new String[]{"colB","colA"},
+      new String[]{"org.apache.warthog.common.StringComparatorAscending",
+        "org.apache.warthog.common.LongComparatorAscending"},true);
+    ts.commitTransaction();
+    
+    // Read in index order
+    ts.beginTransaction();
+    WHIndex index = ts.lookupIndex("testindex");
+    WHAccessor accessor = index.buildAccessor();
+    assertEquals(accessor.hasNext(),true);
+    WHRowID rowID = accessor.getNext();
+    assertNotNull(rowID);
+    WHValue value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(124L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(456L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(111L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(123L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),false);
+    ts.abandonTransaction();
+
+    ts.beginTransaction();
+    index = ts.lookupIndex("testindex");
+    accessor = index.buildAccessor(new IndexCriteria[]{
+      new CriteriaEquals(new StringValue("hello")),
+      new CriteriaBefore(new LongValue(123L))});
+    assertEquals(accessor.hasNext(),true);
+    rowID = accessor.getNext();
+    assertNotNull(rowID);
+    value = index.getValue(rowID,"colA");
+    assertNotNull(value);
+    assertEquals("org.apache.warthog.common.LongValue",value.getClass().getName());
+    assertEquals(111L,((LongValue)value).getValue());
+    assertEquals(accessor.hasNext(),false);
+    ts.abandonTransaction();
+
+    ts.beginTransaction();
+    ts.dropIndex("testindex");
+    ts.commitTransaction();
+
+  }
+  
+  // Protected methods
+  
+  protected WHTableStore createInMemTableStore()
+    throws WHException
+  {
+    return new TableStore(new InMemTransactionalStoreImpl(new InMemAtomicKeyValueStore(10000)));
+  }
+    
+  protected void buildNonOverlappingTestTable(WHTableStore ts)
+    throws WHException
+  {
+    ts.beginTransaction();
+    ts.createTable("testtable",new String[]{"colA","colB"});
+    ts.commitTransaction();
+    
+    ts.beginTransaction();
+    WHTable table = ts.lookupTable("testtable");
+    table.insertRow(new String[]{"colA","colB"},new WHValue[]{new LongValue(123L),new StringValue("hello")});
+    ts.commitTransaction();
+    
+    ts.beginTransaction();
+    table = ts.lookupTable("testtable");
+    table.insertRow(new String[]{"colA","colB"},new WHValue[]{new LongValue(456L),new StringValue("goodbye")});
+    ts.commitTransaction();
+
+    ts.beginTransaction();
+    table = ts.lookupTable("testtable");
+    table.insertRow(new String[]{"colA","colB"},new WHValue[]{new LongValue(124L),new StringValue("...")});
+    ts.commitTransaction();
+
+    ts.beginTransaction();
+    table = ts.lookupTable("testtable");
+    table.insertRow(new String[]{"colA","colB"},new WHValue[]{new LongValue(111L),new StringValue("<>")});
+    ts.commitTransaction();
+  }
+
+  protected void buildOverlappingTestTable(WHTableStore ts)
+    throws WHException
+  {
+    ts.beginTransaction();
+    ts.createTable("testtable",new String[]{"colA","colB"});
+    ts.commitTransaction();
+    
+    ts.beginTransaction();
+    WHTable table = ts.lookupTable("testtable");
+    table.insertRow(new String[]{"colA","colB"},new WHValue[]{new LongValue(123L),new StringValue("hello")});
+    ts.commitTransaction();
+    
+    ts.beginTransaction();
+    table = ts.lookupTable("testtable");
+    table.insertRow(new String[]{"colA","colB"},new WHValue[]{new LongValue(456L),new StringValue("goodbye")});
+    ts.commitTransaction();
+
+    ts.beginTransaction();
+    table = ts.lookupTable("testtable");
+    table.insertRow(new String[]{"colA","colB"},new WHValue[]{new LongValue(124L),new StringValue("...")});
+    ts.commitTransaction();
+
+    ts.beginTransaction();
+    table = ts.lookupTable("testtable");
+    table.insertRow(new String[]{"colA","colB"},new WHValue[]{new LongValue(111L),new StringValue("hello")});
+    ts.commitTransaction();
   }
 
 }
\ No newline at end of file



Mime
View raw message