incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1203188 - in /incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog: interfaces/WHIndex.java tablestore/Index.java tablestore/Table.java tablestore/TableStore.java
Date Thu, 17 Nov 2011 13:49:40 GMT
Author: kwright
Date: Thu Nov 17 13:49:39 2011
New Revision: 1203188

URL: http://svn.apache.org/viewvc?rev=1203188&view=rev
Log:
More work coordinating indexes with tables

Modified:
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHIndex.java
    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/Table.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/interfaces/WHIndex.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHIndex.java?rev=1203188&r1=1203187&r2=1203188&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHIndex.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHIndex.java
Thu Nov 17 13:49:39 2011
@@ -57,14 +57,4 @@ public interface WHIndex
   public WHComparator[] getComparators()
     throws WHException;
   
-  /** Add a new row to the index.
-  */
-  public void addNewRow(int rowNumber)
-    throws WHException;
-  
-  /** Remove a row from the index.  The row must currently exist.
-  */
-  public void deleteRow(int rowNumber)
-    throws WHException;
-  
 }

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=1203188&r1=1203187&r2=1203188&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
Thu Nov 17 13:49:39 2011
@@ -56,8 +56,7 @@ public class Index implements WHIndex
   public String[] getColumnNames()
     throws WHException
   {
-    // MHL
-    return null;
+    return columnNames;
   }
 
   /** Create an accessor based on this index which uses the provided criteria.  The

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=1203188&r1=1203187&r2=1203188&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
Thu Nov 17 13:49:39 2011
@@ -108,4 +108,22 @@ public class Table implements WHTable
     return null;
   }
 
+  // Protected methods
+  
+  /** Delete a specified table row from all indexes attached to the table.
+  */
+  protected void deleteRowFromIndexes(int rowNumber)
+    throws WHException
+  {
+    ts.deleteIndexRow(tableName,rowNumber);
+  }
+  
+  /** Add a specified table row to all indexes attached to the table.
+  */
+  protected void addRowToIndexes(int rowNumber)
+    throws WHException
+  {
+    ts.addIndexRow(tableName,rowNumber);
+  }
+  
 }
\ No newline at end of file

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=1203188&r1=1203187&r2=1203188&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
Thu Nov 17 13:49:39 2011
@@ -32,6 +32,7 @@ public class TableStore implements WHTab
   
   protected Map<String,Table> tables = null;
   protected Map<String,Index> indexes = null;
+  protected Map<String,Index[]> indexesPerTable = null;
   
   /** Constructor */
   public TableStore(WHTransactionalStore transactionalStore)
@@ -48,6 +49,7 @@ public class TableStore implements WHTab
     currentTransaction = transactionalStore.createTransaction();
     tables = new HashMap<String,Table>();
     indexes = new HashMap<String,Index>();
+    indexesPerTable = new HashMap<String,Index[]>();
   }
   
   /** Commit a transaction */
@@ -60,6 +62,7 @@ public class TableStore implements WHTab
     currentTransaction = null;
     tables = null;
     indexes = null;
+    indexesPerTable = null;
   }
   
   /** Abandon a transaction */
@@ -82,20 +85,6 @@ public class TableStore implements WHTab
     return findTable(name);
   }
   
-  protected Table findTable(String name)
-    throws WHException
-  {
-    Table t = tables.get(name);
-    if (t != null)
-      return t;
-    TableValue tv = (TableValue)currentTransaction.get(new TableKey(name));
-    if (tv == null)
-      throw new WHException("No such table '"+name+"'");
-    t = new Table(this,name,tv.getColumns());
-    tables.put(name,t);
-    return t;
-  }
-  
   /** Create a table */
   public WHTable createTable(String name, String[] columnNames)
     throws WHException
@@ -121,17 +110,9 @@ public class TableStore implements WHTab
   {
     if (currentTransaction == null)
       throw new WHException("Must be in a transaction");
-    Index i = indexes.get(name);
-    if (i != null)
-      return i;
-    IndexValue indexValue = (IndexValue)currentTransaction.get(new IndexKey(name));
-    if (indexValue == null)
-      throw new WHException("No such index '"+name+"'");
-    i = new Index(this,findTable(indexValue.getTableName()),name,
-      indexValue.getColumnNames(),indexValue.getComparatorClassNames(),indexValue.getUnique());
-    indexes.put(name,i);
-    return i;
+    return findIndex(name);
   }
+  
     
   /** Create an index */
   public WHIndex createIndex(String name, String tableName, String[] columnNames, String[]
comparatorClasses, boolean unique)
@@ -161,8 +142,89 @@ public class TableStore implements WHTab
     // MHL
     return null;
   }
+
+  // Non-interface methods
+  
+  /** Delete a table row from all the indexes that are based on a table.
+  */
+  public void deleteIndexRow(String tableName, int rowNumber)
+    throws WHException
+  {
+    Index[] indexes = findIndexes(tableName);
+    for (int i = 0 ; i < indexes.length ; i++)
+    {
+      indexes[i].deleteRow(rowNumber);
+    }
+  }
+  
+  /** Add a table row to all the indexes that are based on a table.
+  */
+  public void addIndexRow(String tableName, int rowNumber)
+    throws WHException
+  {
+    Index[] indexes = findIndexes(tableName);
+    for (int i = 0 ; i < indexes.length ; i++)
+    {
+      indexes[i].addNewRow(rowNumber);
+    }
+  }
   
   // Protected classes and methods
+
+  protected Table findTable(String name)
+    throws WHException
+  {
+    Table t = tables.get(name);
+    if (t != null)
+      return t;
+    TableValue tv = (TableValue)currentTransaction.get(new TableKey(name));
+    if (tv == null)
+      return null;
+    t = new Table(this,name,tv.getColumns());
+    tables.put(name,t);
+    return t;
+  }
+  
+  protected Index findIndex(String name)
+    throws WHException
+  {
+    Index i = indexes.get(name);
+    if (i != null)
+      return i;
+    IndexValue indexValue = (IndexValue)currentTransaction.get(new IndexKey(name));
+    if (indexValue == null)
+      return null;
+    Table t = findTable(indexValue.getTableName());
+    if (t == null)
+      throw new WHDeadlockException();
+    i = new Index(this,t,name,indexValue.getColumnNames(),indexValue.getComparatorClassNames(),
+      indexValue.getUnique());
+    indexes.put(name,i);
+    return i;
+  }
+  
+  protected Index[] findIndexes(String tableName)
+    throws WHException
+  {
+    Index[] indexes = indexesPerTable.get(tableName);
+    if (indexes == null)
+    {
+      TableIndexKey tik = new TableIndexKey(tableName);
+      TableIndexValue tiv = (TableIndexValue)currentTransaction.get(tik);
+      if (tiv == null)
+        throw new WHDeadlockException();
+      String[] indexNames = tiv.getIndexes();
+      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();
+      }
+      indexesPerTable.put(tableName,indexes);
+    }
+    return indexes;
+  }
   
   protected static class TableKey extends StringValue
   {
@@ -176,13 +238,18 @@ public class TableStore implements WHTab
     {
       super(data);
     }
-    
+
+    public boolean equals(Object o)
+    {
+      if (!(o instanceof TableKey))
+        return false;
+      return super.equals(o);
+    }
+
   }
   
   protected static class TableValue extends StringArray
   {
-    protected String[] columns;
-    
     /** Constructor */
     public TableValue(String[] columns)
     {
@@ -191,7 +258,7 @@ public class TableStore implements WHTab
     
     public TableValue(byte[] data)
     {
-      columns = StringArray.readObject(new BufferPointer(data));
+      super(data);
     }
     
     public String[] getColumns()
@@ -200,6 +267,47 @@ public class TableStore implements WHTab
     }
   }
   
+  protected static class TableIndexKey extends StringValue
+  {
+    /** Constructor */
+    public TableIndexKey(String name)
+    {
+      super(name);
+    }
+    
+    public TableIndexKey(byte[] data)
+    {
+      super(data);
+    }
+    
+    public boolean equals(Object o)
+    {
+      if (!(o instanceof TableIndexKey))
+        return false;
+      return super.equals(o);
+    }
+
+  }
+  
+  protected static class TableIndexValue extends StringArray
+  {
+    /** Constructor */
+    public TableIndexValue(String[] indexes)
+    {
+      super(indexes);
+    }
+    
+    public TableIndexValue(byte[] data)
+    {
+      super(data);
+    }
+    
+    public String[] getIndexes()
+    {
+      return getValue();
+    }
+  }
+  
   protected static class IndexKey extends StringValue
   {
     /** Constructor */
@@ -212,6 +320,13 @@ public class TableStore implements WHTab
     {
       super(data);
     }
+    
+    public boolean equals(Object o)
+    {
+      if (!(o instanceof IndexKey))
+        return false;
+      return super.equals(o);
+    }
   }
   
   protected static class IndexValue implements WHValue



Mime
View raw message