incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1203333 - in /incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog: interfaces/WHTableStore.java tablestore/Index.java tablestore/Table.java tablestore/TableStore.java
Date Thu, 17 Nov 2011 19:09:47 GMT
Author: kwright
Date: Thu Nov 17 19:09:46 2011
New Revision: 1203333

URL: http://svn.apache.org/viewvc?rev=1203333&view=rev
Log:
Add table/index create/drop code

Modified:
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTableStore.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/WHTableStore.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTableStore.java?rev=1203333&r1=1203332&r2=1203333&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTableStore.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTableStore.java
Thu Nov 17 19:09:46 2011
@@ -55,7 +55,7 @@ public interface WHTableStore
     throws WHException;
     
   /** Create an index */
-  public WHIndex createIndex(String name, String tableName, String[] columnNames, String[]
comparatorClasses, boolean unique)
+  public WHIndex createIndex(String name, WHTable table, String[] columnNames, String[] comparatorClasses,
boolean unique)
     throws WHException;
     
   /** Drop an index */

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=1203333&r1=1203332&r2=1203333&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 19:09:46 2011
@@ -99,4 +99,25 @@ public class Index implements WHIndex
     // MHL
   }
   
+  /** Get the index name */
+  public String getName()
+    throws WHException
+  {
+    return indexName;
+  }
+  
+  /** Create the index */
+  public void create()
+    throws WHException
+  {
+    // MHL
+  }
+
+  /** Drop the index */
+  public void drop()
+    throws WHException
+  {
+    // MHL
+  }
+
 }

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=1203333&r1=1203332&r2=1203333&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 19:09:46 2011
@@ -108,6 +108,26 @@ public class Table implements WHTable
     return null;
   }
 
+  /** Get name */
+  public String getName()
+  {
+    return tableName;
+  }
+  
+  /** Create the table */
+  public void create()
+    throws WHException
+  {
+    // MHL
+  }
+
+  /** Drop the table */
+  public void drop()
+    throws WHException
+  {
+    // MHL
+  }
+  
   // Protected methods
   
   /** Delete a specified table row from all indexes attached to the table.

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=1203333&r1=1203332&r2=1203333&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 19:09:46 2011
@@ -91,8 +91,19 @@ public class TableStore implements WHTab
   {
     if (currentTransaction == null)
       throw new WHException("Must be in a transaction");
-    // MHL
-    return null;
+    Table t = findTable(name);
+    if (t != null)
+      throw new WHException("Table already exists");
+    TableKey tk = new TableKey(name);
+    TableValue tv = new TableValue(columnNames);
+    t = new Table(this,name,columnNames);
+    currentTransaction.put(tk,tv);
+    tables.put(name,t);
+    TableIndexKey tik = new TableIndexKey(name);
+    TableIndexValue tiv = new TableIndexValue(new String[0]);
+    currentTransaction.put(tik,tiv);
+    t.create();
+    return t;
   }
   
   /** Drop a table */
@@ -101,7 +112,10 @@ public class TableStore implements WHTab
   {
     if (currentTransaction == null)
       throw new WHException("Must be in a transaction");
-    // MHL
+    Table t = findTable(name);
+    if (t == null)
+      throw new WHException("Table does not exist");
+    deleteTable(t);
   }
   
   /** Find an index */
@@ -115,13 +129,36 @@ public class TableStore implements WHTab
   
     
   /** Create an index */
-  public WHIndex createIndex(String name, String tableName, String[] columnNames, String[]
comparatorClasses, boolean unique)
+  public WHIndex createIndex(String name, WHTable table, String[] columnNames, String[] comparatorClasses,
boolean unique)
     throws WHException
   {
     if (currentTransaction == null)
       throw new WHException("Must be in a transaction");
-    // MHL
-    return null;
+    Table t = (Table)table;
+    Index i = findIndex(name);
+    if (i != null)
+      throw new WHException("Index already exists");
+    IndexKey ik = new IndexKey(name);
+    IndexValue iv = new IndexValue(name,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());
+    TableIndexValue tiv = (TableIndexValue)currentTransaction.get(tik);
+    if (tiv == null)
+      throw new WHDeadlockException();
+    String[] indexList = tiv.getIndexes();
+    String[] newIndexList = new String[indexList.length + 1];
+    for (int j = 0 ; j < indexList.length ; j++)
+    {
+      newIndexList[j] = indexList[j];
+    }
+    newIndexList[indexList.length] = name;
+    tiv = new TableIndexValue(newIndexList);
+    currentTransaction.put(tik,tiv);
+    indexesPerTable.remove(t.getName());
+    i.create();
+    return i;
   }
     
   /** Drop an index */
@@ -130,9 +167,12 @@ public class TableStore implements WHTab
   {
     if (currentTransaction == null)
       throw new WHException("Must be in a transaction");
-    // MHL
+    Index i = findIndex(name);
+    if (i == null)
+      throw new WHException("Index does not exist");
+    deleteIndex(i);
   }
-    
+  
   /** Perform a query */
   public WHQueryResult performQuery(QueryDescription specification)
     throws WHException
@@ -171,6 +211,60 @@ public class TableStore implements WHTab
   
   // Protected classes and methods
 
+  protected void deleteTable(Table t)
+    throws WHException
+  {
+    tables.remove(t.getName());
+    TableIndexKey tik = new TableIndexKey(t.getName());
+    TableIndexValue tiv = (TableIndexValue)currentTransaction.get(tik);
+    if (tiv == null)
+      throw new WHDeadlockException();
+    String[] indexes = tiv.getIndexes();
+    for (int i = 0 ; i < indexes.length ; i++)
+    {
+      Index index = findIndex(indexes[i]);
+      if (index == null)
+        throw new WHDeadlockException();
+      deleteIndex(index);
+    }
+    currentTransaction.put(tik,null);
+    
+    TableKey tk = new TableKey(t.getName());
+    currentTransaction.put(tk,null);
+    t.drop();
+  }
+  
+  protected void deleteIndex(Index i)
+    throws WHException
+  {
+    indexes.remove(i.getName());
+    Table t = (Table)i.getTable();
+    TableIndexKey tik = new TableIndexKey(t.getName());
+    TableIndexValue tiv = (TableIndexValue)currentTransaction.get(tik);
+    if (tiv == null)
+      throw new WHDeadlockException();
+    String[] indexList = tiv.getIndexes();
+    if (indexList.length == 0)
+      throw new WHDeadlockException();
+    String[] newIndexList = new String[indexList.length - 1];
+    int k = 0;
+    for (int j = 0 ; j < indexList.length ; j++)
+    {
+      if (!indexList[j].equals(i.getName()))
+      {
+        newIndexList[k++] = indexList[j];
+        if (k == indexList.length)
+          break;
+      }
+    }
+    tiv = new TableIndexValue(newIndexList);
+    currentTransaction.put(tik,tiv);
+    indexesPerTable.remove(t.getName());
+    IndexKey ik = new IndexKey(i.getName());
+    currentTransaction.put(ik,null);
+    i.drop();
+  }
+    
   protected Table findTable(String name)
     throws WHException
   {



Mime
View raw message