You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2011/12/18 09:26:34 UTC

svn commit: r1220349 [4/6] - in /incubator/lcf/branches/CONNECTORS-286/warthog-reimport: ./ lib/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/warthog/ src/main/java/org/apache/warthog/api/ src/main...

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeColumnKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeColumnKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeColumnKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeColumnKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,39 @@
+/* $Id: IndexNodeColumnKey.java 1209929 2011-12-03 15:06:22Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Index node next column pointer key */
+public class IndexNodeColumnKey extends IndexNodeKey
+{
+  /** Constructor */
+  public IndexNodeColumnKey(long indexID, long rowID, long columnID)
+  {
+    super(indexID,rowID,columnID);
+  }
+    
+  public IndexNodeColumnKey(byte[] data)
+  {
+    super(data);
+  }
+}
\ No newline at end of file

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeEqualsKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeEqualsKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeEqualsKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeEqualsKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,39 @@
+/* $Id: IndexNodeEqualsKey.java 1209929 2011-12-03 15:06:22Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Index node equals pointer key */
+public class IndexNodeEqualsKey extends IndexNodeKey
+{
+  /** Constructor */
+  public IndexNodeEqualsKey(long indexID, long rowID, long columnID)
+  {
+    super(indexID,rowID,columnID);
+  }
+    
+  public IndexNodeEqualsKey(byte[] data)
+  {
+    super(data);
+  }
+}
\ No newline at end of file

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeGreaterKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeGreaterKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeGreaterKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeGreaterKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,39 @@
+/* $Id: IndexNodeGreaterKey.java 1209929 2011-12-03 15:06:22Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Index node greater pointer key */
+public class IndexNodeGreaterKey extends IndexNodeKey
+{
+  /** Constructor */
+  public IndexNodeGreaterKey(long indexID, long rowID, long columnID)
+  {
+    super(indexID,rowID,columnID);
+  }
+    
+  public IndexNodeGreaterKey(byte[] data)
+  {
+    super(data);
+  }
+}
\ No newline at end of file

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,96 @@
+/* $Id: IndexNodeKey.java 1209929 2011-12-03 15:06:22Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Base class for node lesser/greater keys */
+public class IndexNodeKey implements WHKey
+{
+  protected long indexID;
+  protected long rowID;
+  protected long columnID;
+  
+  /** Constructor */
+  public IndexNodeKey(long indexID, long rowID, long columnID)
+  {
+    this.indexID = indexID;
+    this.rowID = rowID;
+    this.columnID = columnID;
+  }
+    
+  public IndexNodeKey(byte[] data)
+  {
+    BufferPointer bp = new BufferPointer(data);
+    this.indexID = LongKey.readObject(bp);
+    this.rowID = LongKey.readObject(bp);
+    this.columnID = LongKey.readObject(bp);
+  }
+
+  public byte[] serializeObject()
+  {
+    byte[] rval = new byte[LongKey.sizeObject()+
+      LongKey.sizeObject() + LongKey.sizeObject()];
+    BufferPointer bp = new BufferPointer(rval);
+    LongKey.writeObject(bp,indexID);
+    LongKey.writeObject(bp,rowID);
+    LongKey.writeObject(bp,columnID);
+    return rval;
+  }
+    
+  public long getHashCode()
+  {
+    return calculateHashCode(indexID,rowID,columnID);
+  }
+  
+  public static long calculateHashCode(long indexID, long rowID, long columnID)
+  {
+    return LongKey.calculateHashCode(indexID) + LongKey.calculateHashCode(rowID) +
+      LongKey.calculateHashCode(columnID);
+  }
+    
+  public boolean isEquals(WHKeyValue o)
+  {
+    IndexNodeKey key = (IndexNodeKey)o;
+    return key.indexID == indexID &&
+      key.rowID == rowID &&
+      key.columnID == columnID;
+  }
+
+  public int hashCode()
+  {
+    return ((int)((indexID << 5) ^ (indexID >> 3))) +
+      ((int)((rowID << 5) ^ (rowID >> 3))) +
+      ((int)((columnID << 5) ^ (columnID >> 3)));
+  }
+  
+  public boolean equals(Object o)
+  {
+    if (o.getClass() != getClass())
+      return false;
+    IndexNodeKey other = (IndexNodeKey)o;
+    return other.indexID == indexID &&
+      other.rowID == rowID &&
+      other.columnID == columnID;
+  }
+  
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeLesserKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeLesserKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeLesserKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeLesserKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,39 @@
+/* $Id: IndexNodeLesserKey.java 1209929 2011-12-03 15:06:22Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Index node lesser pointer key */
+public class IndexNodeLesserKey extends IndexNodeKey
+{
+  /** Constructor */
+  public IndexNodeLesserKey(long indexID, long rowID, long columnID)
+  {
+    super(indexID,rowID,columnID);
+  }
+    
+  public IndexNodeLesserKey(byte[] data)
+  {
+    super(data);
+  }
+}
\ No newline at end of file

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeParentKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeParentKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeParentKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexNodeParentKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,40 @@
+/* $Id: IndexNodeParentKey.java 1209929 2011-12-03 15:06:22Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Key for the btree link to its parent reference (NOT node; WHKey).  This allows
+* us to perform fast in-context deletions. */
+public class IndexNodeParentKey extends IndexNodeKey
+{
+  /** Constructor */
+  public IndexNodeParentKey(long indexID, long rowID, long columnID)
+  {
+    super(indexID,rowID,columnID);
+  }
+    
+  public IndexNodeParentKey(byte[] data)
+  {
+    super(data);
+  }
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexRootKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexRootKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexRootKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexRootKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,39 @@
+/* $Id: IndexRootKey.java 1207727 2011-11-29 01:12:13Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Key for the btree root node link */
+public class IndexRootKey extends LongKey
+{
+  /** Constructor */
+  public IndexRootKey(long indexID)
+  {
+    super(indexID);
+  }
+    
+  public IndexRootKey(byte[] data)
+  {
+    super(data);
+  }
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexValue.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexValue.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexValue.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/IndexValue.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,119 @@
+/* $Id: IndexValue.java 1209929 2011-12-03 15:06:22Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** An index definition value */
+public class IndexValue implements WHKeyValue
+{
+  protected long tableID;
+  protected long[] columnIDs;
+  protected String[] comparatorClassNames;
+  protected boolean unique;
+    
+  /** Constructor */
+  public IndexValue(long tableID, long[] columnIDs, String[] comparatorClassNames, boolean unique)
+  {
+    this.tableID = tableID;
+    this.columnIDs = columnIDs;
+    this.comparatorClassNames = comparatorClassNames;
+    this.unique = unique;
+  }
+    
+  public IndexValue(byte[] data)
+  {
+    BufferPointer bp = new BufferPointer(data);
+    tableID = LongValue.readObject(bp);
+    columnIDs = LongArray.readObject(bp);
+    comparatorClassNames = StringArray.readObject(bp);
+    unique = BooleanValue.readObject(bp);
+  }
+    
+  public byte[] serializeObject()
+  {
+    byte[] rval = new byte[LongValue.sizeObject() +
+      LongArray.sizeObject(columnIDs.length) +
+      StringArray.sizeObject(comparatorClassNames) +
+      BooleanValue.sizeObject()];
+    BufferPointer bp = new BufferPointer(rval);
+    LongValue.writeObject(bp,tableID);
+    LongArray.writeObject(bp,columnIDs);
+    StringArray.writeObject(bp,comparatorClassNames);
+    BooleanValue.writeObject(bp,unique);
+    return rval;
+  }
+
+  /** Check if equals (classes must already agree) */
+  public boolean isEquals(WHKeyValue value)
+  {
+    IndexValue other = (IndexValue)value;
+    return other.tableID == this.tableID &&
+      LongArray.compareObject(other.columnIDs,this.columnIDs) &&
+      StringArray.compareObject(other.comparatorClassNames,this.comparatorClassNames) &&
+      other.unique == this.unique;
+  }
+  
+  public long getTableID()
+  {
+    return tableID;
+  }
+  
+  public long[] getColumnIDs()
+  {
+    return columnIDs;
+  }
+    
+  public String[] getComparatorClassNames()
+  {
+    return comparatorClassNames;
+  }
+    
+  public boolean getUnique()
+  {
+    return unique;
+  }
+  
+  public int hashCode()
+  {
+    int rval = (int)((tableID << 5) ^ (tableID >> 3));
+    for (int i = 0 ; i < columnIDs.length ; i++)
+    {
+      rval += (int)((columnIDs[i] << 5) ^ (columnIDs[i] >> 3));
+      rval += comparatorClassNames[i].hashCode();
+    }
+    rval += (unique?87245:31);
+    return rval;
+  }
+  
+  public boolean equals(Object o)
+  {
+    if (this.getClass() != o.getClass())
+      return false;
+    IndexValue other = (IndexValue)o;
+    return other.tableID == tableID &&
+      LongArray.compareObject(other.columnIDs,this.columnIDs) &&
+      StringArray.compareObject(other.comparatorClassNames,this.comparatorClassNames) &&
+      other.unique == this.unique;
+  }
+  
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/Table.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/Table.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/Table.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/Table.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,308 @@
+/* $Id: Table.java 1209929 2011-12-03 15:06:22Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+import java.util.*;
+
+/** This is the standard implementation of WHTable.
+*/
+public class Table implements WHTable
+{
+  protected TableStore ts;
+  protected LongValue tableID;
+  protected long tableIDValue;
+  protected String[] columns;
+  protected long[] columnIDs;
+  protected long nextColumnID;
+  protected Map<String,Integer> columnLookup = new HashMap<String,Integer>();
+  
+  protected static final int maxInstanceCount = 128;
+  protected static final int maxInstanceMask = maxInstanceCount-1;
+  
+  /** Constructor */
+  public Table(TableStore ts, LongValue tableID, String[] columns, long[] columnIDs, long nextColumnID)
+    throws WHException
+  {
+    if (columnIDs.length != columns.length)
+      throw new WHException("Number of column names must match number of column IDs");
+    this.ts = ts;
+    this.tableID = tableID;
+    this.tableIDValue = tableID.getValue();
+    this.columns = columns;
+    this.columnIDs = columnIDs;
+    this.nextColumnID = nextColumnID;
+    for (int i = 0 ; i < columns.length ; i++)
+    {
+      columnLookup.put(columns[i],new Integer(i));
+    }
+  }
+  
+  /** Get the column names.
+  */
+  public String[] getColumnNames()
+    throws WHException
+  {
+    return columns;
+  }
+  
+  /** Insert a row */
+  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
+    LongValue rowID = ts.allocateNewTableRow(tableID);
+    // Set the values
+    for (int i = 0 ; i < columns.length ; i++)
+    {
+      setTableColumnValue(rowID,getColumnID(columns[i]),(WHKeyValue)values[i]);
+    }
+    // Add to all indices
+    ts.addIndexRow(tableID,rowID,null);
+    // Last, link in the row.  Do it last to reduce chances of collision.
+    addTableRow(rowID);
+  }
+  
+  /** Update row(s) */
+  public void updateRows(String[] columns, WHValue[] values,
+    WHAccessor accessor)
+    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<Long> columnSet = new HashSet<Long>();
+    for (int i = 0 ; i < columns.length ; i++)
+    {
+      columnSet.add(new Long(columnIDs[i]));
+    }
+    
+    // Update the rows one at a time
+    while (true)
+    {
+      LongValue rowID = (LongValue)accessor.getCurrentRowID();
+      if (rowID == null)
+        break;
+      
+      // 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
+      // index accessor it may be the case that the changed row appears in the update list at a new
+      // place after the modification, and thus can technically be visited more than once.  We
+      // currently do nothing to detect such conditions or attempt to stop them.
+      
+      // Delete the row from all indexes which can potentially intersect the changes
+      ts.deleteIndexRow(tableID,rowID,columnSet);
+      // Change the values as specified
+      for (int i = 0 ; i < columns.length ; i++)
+      {
+        setTableColumnValue(rowID,getColumnID(columns[i]),(WHKeyValue)values[i]);
+      }
+      // Add the row back to all indexes which can potentially intersect the changes
+      ts.addIndexRow(tableID,rowID,columnSet);
+      accessor.advance();
+    }
+  }
+    
+  /** Delete row(s) */
+  public void deleteRows(WHAccessor accessor)
+    throws WHException
+  {
+    // Read the rows one at a time
+    while (true)
+    {
+      LongValue rowID = (LongValue)accessor.getCurrentRowID();
+      if (rowID == null)
+        break;
+      // Delete the row from all indexes
+      ts.deleteIndexRow(tableID,rowID,null);
+      // Delete all values
+      for (int i = 0 ; i < columnIDs.length ; i++)
+      {
+        setTableColumnValue(rowID,columnIDs[i],null);
+      }
+      // Unlink the row in the linked list
+      removeTableRow(rowID);
+      accessor.advance();
+    }
+  }
+  
+  /** Build an accessor that simply scans all the rows in the table */
+  public WHAccessor buildAccessor()
+    throws WHException
+  {
+    return new TableAccessor(this);
+  }
+
+  // Protected methods
+  
+  /** Get identifier */
+  protected LongValue getID()
+  {
+    return tableID;
+  }
+  
+  protected long getIDValue()
+  {
+    return tableIDValue;
+  }
+  
+  protected long[] getColumnIDs()
+  {
+    return columnIDs;
+  }
+  
+  protected long getColumnID(String columnName)
+    throws WHException
+  {
+    Integer i = columnLookup.get(columnName);
+    if (i == null)
+      throw new WHException("No such column: "+columnName);
+    return columnIDs[i.intValue()];
+  }
+  
+  /** Remove all rows.
+  * WARNING: This effectively causes the entire table to have to fit into memory!
+  * It is better to delete rows piecemeal in separate transactions.
+  */
+  protected void remove()
+    throws WHException
+  {
+    deleteRows(buildAccessor());
+  }
+
+  /** Add a table row to the linked list for that table.
+  */
+  protected void addTableRow(LongValue rowID)
+    throws WHException
+  {
+    int instanceNumber = rowID.hashCode() & maxInstanceMask;
+    
+    if (ts.randomDecision())
+    {
+      TableTailKey tailKey = new TableTailKey(tableIDValue,instanceNumber);
+      LongValue tailValue = (LongValue)ts.get(tailKey);
+      if (tailValue == null)
+      {
+        // First row.  Set the head.
+        ts.put(new TableHeadKey(tableIDValue,instanceNumber),rowID);
+      }
+      else
+      {
+        // Set the next pointer for last row.
+        ts.put(new TableRowNextKey(tableIDValue,tailValue.getValue()),rowID);
+        ts.put(new TableRowPrevKey(tableIDValue,rowID.getValue()),tailValue);
+      }
+      // Set the tail pointer to the new record
+      ts.put(tailKey,rowID);
+    }
+    else
+    {
+      TableHeadKey headKey = new TableHeadKey(tableIDValue,instanceNumber);
+      LongValue headValue = (LongValue)ts.get(headKey);
+      if (headValue == null)
+      {
+        // First row.  Set the tail.
+        ts.put(new TableTailKey(tableIDValue,instanceNumber),rowID);
+      }
+      else
+      {
+        // Set the prev pointer for first row.
+        ts.put(new TableRowPrevKey(tableIDValue,headValue.getValue()),rowID);
+        ts.put(new TableRowNextKey(tableIDValue,rowID.getValue()),headValue);
+      }
+      // Set the tail pointer to the new record
+      ts.put(headKey,rowID);
+    }
+  }
+  
+  /** Remove a table row from the linked list for that table.
+  */
+  protected void removeTableRow(LongValue rowID)
+    throws WHException
+  {
+    int instanceNumber = rowID.hashCode() & maxInstanceMask;
+
+    LongValue prevValue = (LongValue)ts.get(new TableRowPrevKey(tableIDValue,rowID.getValue()));
+    LongValue nextValue = (LongValue)ts.get(new TableRowNextKey(tableIDValue,rowID.getValue()));
+    // Fix up the previous pointer reference
+    if (prevValue == null)
+    {
+      ts.put(new TableHeadKey(tableIDValue,instanceNumber),nextValue);
+    }
+    else
+    {
+      ts.put(new TableRowNextKey(tableIDValue,prevValue.getValue()),nextValue);
+    }
+    // Fix up the next pointer reference
+    if (nextValue == null)
+    {
+      ts.put(new TableTailKey(tableIDValue,instanceNumber),prevValue);
+    }
+    else
+    {
+      ts.put(new TableRowPrevKey(tableIDValue,nextValue.getValue()),prevValue);
+    }
+  }
+  
+  /** Set a table column value.
+  */
+  protected void setTableColumnValue(LongValue rowID, long columnID, WHKeyValue value)
+    throws WHException
+  {
+    ts.put(new TableColumnKey(tableIDValue,rowID.getValue(),columnID),value);
+  }
+  
+  /** Get a table column value.
+  */
+  protected WHKeyValue getTableColumnValue(LongValue rowID, long columnID)
+    throws WHException
+  {
+    return ts.get(new TableColumnKey(tableIDValue,rowID.getValue(),columnID));
+  }
+
+  /** Get the max number of instances.
+  */
+  protected int getMaxInstanceNumber()
+  {
+    return maxInstanceCount;
+  }
+  
+  /** Read the first table row ID.
+  */
+  protected LongValue readFirstTableRowID(int instanceNumber)
+    throws WHException
+  {
+    return (LongValue)ts.get(new TableHeadKey(tableIDValue,instanceNumber));
+  }
+  
+  /** Reade the next table row ID.
+  */
+  protected LongValue readNextTableRowID(LongValue currentRowID)
+    throws WHException
+  {
+    // Read the row's next pointer
+    return (LongValue)ts.get(new TableRowNextKey(tableIDValue,currentRowID.getValue()));
+  }
+  
+}
\ No newline at end of file

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableAccessor.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableAccessor.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableAccessor.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableAccessor.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,100 @@
+/* $Id: TableAccessor.java 1209929 2011-12-03 15:06:22Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+import java.util.*;
+
+/** Table accessor. */
+public class TableAccessor implements WHAccessor
+{
+  protected Table table;
+  /** This is the current row to be returned. */
+  protected LongValue currentRowID;
+  /** This is the current instance number */
+  protected int currentInstanceNumber;
+    
+  /** Constructor */
+  public TableAccessor(Table table)
+    throws WHException
+  {
+    this.table = table;
+    currentInstanceNumber = 0;
+    currentRowID = null;
+    goToNextLegalRow();
+  }
+  
+  protected void goToNextLegalRow()
+    throws WHException
+  {
+    while (true)
+    {
+      if (currentRowID == null)
+      {
+        currentRowID = table.readFirstTableRowID(currentInstanceNumber);
+      }
+      else
+      {
+        currentRowID = table.readNextTableRowID(currentRowID);
+      }
+      if (currentRowID == null)
+      {
+        currentInstanceNumber++;
+        if (currentInstanceNumber == table.getMaxInstanceNumber())
+          return;
+      }
+      else
+        return;
+    }
+  }
+    
+  /** Advance to the next row.
+  */
+  public void advance()
+    throws WHException
+  {
+    if (currentRowID != null)
+    {
+      goToNextLegalRow();
+    }
+  }
+  
+  /** Read the current relationship row ID,  Null will be returned if we are
+  * at the end of the sequence.
+  */
+  public WHRowID getCurrentRowID()
+    throws WHException
+  {
+    return currentRowID;
+  }
+	
+  /** Get the data for the current row and specified column. 
+  */
+  public WHValue getValue(String columnName)
+    throws WHException
+  {
+    if (currentRowID != null)
+      return (WHValue)table.getTableColumnValue(currentRowID,table.getColumnID(columnName));
+    throw new WHException("Can't read beyond end of accessor");
+  }
+
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableBaseKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableBaseKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableBaseKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableBaseKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,88 @@
+/* $Id: TableBaseKey.java 1208927 2011-12-01 01:18:07Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Base class for table row prev/next keys */
+public class TableBaseKey implements WHKey
+{
+  protected long tableID;
+  protected int instanceNumber;
+  
+  /** Constructor */
+  public TableBaseKey(long tableID, int instanceNumber)
+  {
+    this.tableID = tableID;
+    this.instanceNumber = instanceNumber;
+  }
+    
+  public TableBaseKey(byte[] data)
+  {
+    BufferPointer bp = new BufferPointer(data);
+    this.tableID = LongKey.readObject(bp);
+    this.instanceNumber = IntegerKey.readObject(bp);
+  }
+
+  public byte[] serializeObject()
+  {
+    byte[] rval = new byte[LongKey.sizeObject()+
+      IntegerKey.sizeObject()];
+    BufferPointer bp = new BufferPointer(rval);
+    LongKey.writeObject(bp,tableID);
+    IntegerKey.writeObject(bp,instanceNumber);
+    return rval;
+  }
+    
+  public long getHashCode()
+  {
+    return calculateHashCode(tableID,instanceNumber);
+  }
+  
+  public static long calculateHashCode(long tableID, int instanceNumber)
+  {
+    return LongKey.calculateHashCode(tableID) + IntegerKey.calculateHashCode(instanceNumber);
+  }
+    
+  public boolean isEquals(WHKeyValue o)
+  {
+    TableBaseKey key = (TableBaseKey)o;
+    return key.tableID == tableID &&
+      key.instanceNumber == instanceNumber;
+  }
+
+  public int hashCode()
+  {
+    return ((int)((tableID << 5) ^ (tableID >> 3))) +
+      ((instanceNumber << 5) ^ (instanceNumber >> 3));
+  }
+  
+  public boolean equals(Object o)
+  {
+    if (getClass() != o.getClass())
+      return false;
+    TableBaseKey other = (TableBaseKey)o;
+    return other.tableID == tableID &&
+      other.instanceNumber == instanceNumber;
+  }
+  
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableColumnKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableColumnKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableColumnKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableColumnKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,95 @@
+/* $Id: TableColumnKey.java 1209929 2011-12-03 15:06:22Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+public class TableColumnKey implements WHKey
+{
+  protected long tableID;
+  protected long rowID;
+  protected long columnID;
+  
+  /** Constructor */
+  public TableColumnKey(long tableID, long rowID, long columnID)
+  {
+    this.tableID = tableID;
+    this.rowID = rowID;
+    this.columnID = columnID;
+  }
+    
+  public TableColumnKey(byte[] data)
+  {
+    BufferPointer bp = new BufferPointer(data);
+    this.tableID = LongKey.readObject(bp);
+    this.rowID = LongKey.readObject(bp);
+    this.columnID = LongKey.readObject(bp);
+  }
+
+  public byte[] serializeObject()
+  {
+    byte[] rval = new byte[LongKey.sizeObject()+
+      LongKey.sizeObject() + LongKey.sizeObject()];
+    BufferPointer bp = new BufferPointer(rval);
+    LongKey.writeObject(bp,tableID);
+    LongKey.writeObject(bp,rowID);
+    LongKey.writeObject(bp,columnID);
+    return rval;
+  }
+    
+  public long getHashCode()
+  {
+    return calculateHashCode(tableID,rowID,columnID);
+  }
+  
+  public static long calculateHashCode(long tableID, long rowID, long columnID)
+  {
+    return LongKey.calculateHashCode(tableID) + LongKey.calculateHashCode(rowID)
+      + LongKey.calculateHashCode(columnID);
+  }
+    
+  public boolean isEquals(WHKeyValue o)
+  {
+    TableColumnKey key = (TableColumnKey)o;
+    return key.tableID == tableID &&
+      key.rowID == rowID &&
+      key.columnID == columnID;
+  }
+  
+  public int hashCode()
+  {
+    return ((int)((tableID << 5) ^ (tableID >>3))) +
+      ((int)((rowID << 5) ^ (rowID >> 3))) +
+      ((int)((columnID << 5) ^ (columnID >> 3)));
+  }
+  
+  public boolean equals(Object o)
+  {
+    if (getClass() != o.getClass())
+      return false;
+    TableColumnKey other = (TableColumnKey)o;
+    return other.tableID == tableID &&
+      other.rowID == rowID &&
+      other.columnID == columnID;
+  }
+  
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableHeadKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableHeadKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableHeadKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableHeadKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,38 @@
+/* $Id: TableHeadKey.java 1208927 2011-12-01 01:18:07Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+public class TableHeadKey extends TableBaseKey
+{
+  /** Constructor */
+  public TableHeadKey(long tableID, int instanceNumber)
+  {
+    super(tableID,instanceNumber);
+  }
+    
+  public TableHeadKey(byte[] data)
+  {
+    super(data);
+  }
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableIndexKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableIndexKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableIndexKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableIndexKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,39 @@
+/* $Id: TableIndexKey.java 1207727 2011-11-29 01:12:13Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Key for accessing indexes that index a table */
+public class TableIndexKey extends LongKey
+{
+  /** Constructor */
+  public TableIndexKey(long tableID)
+  {
+    super(tableID);
+  }
+    
+  public TableIndexKey(byte[] data)
+  {
+    super(data);
+  }
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,39 @@
+/* $Id: TableKey.java 1207727 2011-11-29 01:12:13Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Key class for accessing table definition data given a table identifier */
+public class TableKey extends LongKey
+{
+  /** Constructor */
+  public TableKey(long tableID)
+  {
+    super(tableID);
+  }
+    
+  public TableKey(byte[] data)
+  {
+    super(data);
+  }
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableLookupKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableLookupKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableLookupKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableLookupKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,39 @@
+/* $Id: TableLookupKey.java 1207727 2011-11-29 01:12:13Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Key class for accessing table ID given table name */
+public class TableLookupKey extends StringKey
+{
+  /** Constructor */
+  public TableLookupKey(String name)
+  {
+    super(name);
+  }
+    
+  public TableLookupKey(byte[] data)
+  {
+    super(data);
+  }
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableNameKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableNameKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableNameKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableNameKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,39 @@
+/* $Id: TableNameKey.java 1207727 2011-11-29 01:12:13Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Key class for accessing table name given ID */
+public class TableNameKey extends LongKey
+{
+  /** Constructor */
+  public TableNameKey(long tableID)
+  {
+    super(tableID);
+  }
+    
+  public TableNameKey(byte[] data)
+  {
+    super(data);
+  }
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowIDFactoryKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowIDFactoryKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowIDFactoryKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowIDFactoryKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,40 @@
+/* $Id: TableRowIDFactoryKey.java 1207727 2011-11-29 01:12:13Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Key for accessing each table's row ID factory */
+public class TableRowIDFactoryKey extends LongKey
+{
+  /** Constructor */
+  public TableRowIDFactoryKey(long tableID)
+  {
+    super(tableID);
+  }
+    
+  public TableRowIDFactoryKey(byte[] data)
+  {
+    super(data);
+  }
+
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,92 @@
+/* $Id: TableRowKey.java 1208149 2011-11-29 23:47:56Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Base class for table row prev/next keys */
+public class TableRowKey implements WHKey
+{
+  protected long tableID;
+  protected long rowID;
+  
+  protected long hashCodeValue;
+  
+  /** Constructor */
+  public TableRowKey(long tableID, long rowID)
+  {
+    this.tableID = tableID;
+    this.rowID = rowID;
+    //hashCodeValue = calculateHashCode(tableID,rowID);
+  }
+    
+  public TableRowKey(byte[] data)
+  {
+    BufferPointer bp = new BufferPointer(data);
+    this.tableID = LongKey.readObject(bp);
+    this.rowID = LongKey.readObject(bp);
+    //hashCodeValue = calculateHashCode(tableID,rowID);
+  }
+
+  public byte[] serializeObject()
+  {
+    byte[] rval = new byte[LongKey.sizeObject()+
+      LongKey.sizeObject()];
+    BufferPointer bp = new BufferPointer(rval);
+    LongKey.writeObject(bp,tableID);
+    LongKey.writeObject(bp,rowID);
+    return rval;
+  }
+    
+  public long getHashCode()
+  {
+    return hashCodeValue;
+  }
+  
+  public static long calculateHashCode(long tableID, long rowID)
+  {
+    return LongKey.calculateHashCode(tableID) + LongKey.calculateHashCode(rowID);
+  }
+    
+  public boolean isEquals(WHKeyValue o)
+  {
+    TableRowKey key = (TableRowKey)o;
+    return key.tableID == tableID &&
+      key.rowID == rowID;
+  }
+
+  public int hashCode()
+  {
+    return ((int)((tableID << 5) ^ (tableID >> 3))) +
+      ((int)((rowID << 5) ^ (rowID >> 3)));
+  }
+  
+  public boolean equals(Object o)
+  {
+    if (getClass() != o.getClass())
+      return false;
+    TableRowKey other = (TableRowKey)o;
+    return other.tableID == tableID &&
+      other.rowID == rowID;
+  }
+  
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowNextKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowNextKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowNextKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowNextKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,39 @@
+/* $Id: TableRowNextKey.java 1207727 2011-11-29 01:12:13Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Table row next pointer key */
+public class TableRowNextKey extends TableRowKey
+{
+  /** Constructor */
+  public TableRowNextKey(long tableID, long rowID)
+  {
+    super(tableID,rowID);
+  }
+    
+  public TableRowNextKey(byte[] data)
+  {
+    super(data);
+  }
+}
\ No newline at end of file

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowPrevKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowPrevKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowPrevKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableRowPrevKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,39 @@
+/* $Id: TableRowPrevKey.java 1207727 2011-11-29 01:12:13Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** Table row previous pointer key */
+public class TableRowPrevKey extends TableRowKey
+{
+  /** Constructor */
+  public TableRowPrevKey(long tableID, long rowID)
+  {
+    super(tableID,rowID);
+  }
+    
+  public TableRowPrevKey(byte[] data)
+  {
+    super(data);
+  }
+}
\ No newline at end of file

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableStore.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableStore.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableStore.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableStore.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,520 @@
+/* $Id: TableStore.java 1209929 2011-12-03 15:06:22Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+import java.util.*;
+
+/** This is the standard implementation of WHTableStore.
+*/
+public class TableStore implements WHTableStore
+{
+  /** The underlying transactional store */
+  protected WHTransactionalStore transactionalStore;
+  
+  /** The current transaction, if any */
+  protected WHTransaction currentTransaction = null;
+  
+  /** Map of tableID to table object, good for the current transaction */
+  protected Map<LongValue,Table> tables = null;
+  /** Map of tableID to index object, good for the current transaction */
+  protected Map<LongValue,Index> indexes = null;
+  /** Map of table ID to index set, good for the current transaction */
+  protected Map<LongValue,Index[]> indexesPerTable = null;
+  
+  /** Random number generator for this table store instance */
+  protected Random randomGenerator;
+  
+  /** Constructor */
+  public TableStore(WHTransactionalStore transactionalStore)
+  {
+    this.transactionalStore = transactionalStore;
+    randomGenerator = new Random();
+  }
+  
+  /** Constructor */
+  public TableStore(WHTransactionalStore transactionalStore, int seed)
+  {
+    this.transactionalStore = transactionalStore;
+    randomGenerator = new Random(seed);
+  }
+  
+  /** Begin a transaction */
+  public void beginTransaction()
+    throws WHException
+  {
+    if (currentTransaction != null)
+      throw new WHException("Already in a transaction");
+    currentTransaction = transactionalStore.createTransaction();
+    tables = new HashMap<LongValue,Table>();
+    indexes = new HashMap<LongValue,Index>();
+    indexesPerTable = new HashMap<LongValue,Index[]>();
+  }
+  
+  /** Commit a transaction */
+  public void commitTransaction()
+    throws WHException
+  {
+    if (currentTransaction == null)
+      throw new WHException("Not in a transaction");
+    currentTransaction.commit();
+    currentTransaction = null;
+    tables = null;
+    indexes = null;
+    indexesPerTable = null;
+  }
+  
+  /** Abandon any transaction in progress */
+  public void abandonTransaction()
+    throws WHException
+  {
+    if (currentTransaction == null)
+      return;
+    // As a nicety, tell the transaction we're done.
+    currentTransaction.abandon();
+    currentTransaction = null;
+    tables = null;
+    indexes = null;
+    indexesPerTable = null;
+  }
+  
+  /** Lookup table */
+  public WHTable lookupTable(String name)
+    throws WHException
+  {
+    if (currentTransaction == null)
+      throw new WHException("Must be in a transaction");
+    return findTable(name);
+  }
+  
+  /** Create a table */
+  public WHTable createTable(String name, String[] columnNames)
+    throws WHException
+  {
+    if (currentTransaction == null)
+      throw new WHException("Must be in a transaction");
+    if (currentTransaction.get(new TableLookupKey(name)) != null)
+      throw new WHException("Table already exists");
+    LongValue tableIDValue = allocateNewGeneralID();
+    setTableName(tableIDValue,name);
+    long[] columnIDs = new long[columnNames.length];
+    for (int i = 0 ; i < columnIDs.length ; i++)
+    {
+      columnIDs[i] = (long)i;
+    }
+    currentTransaction.put(new TableKey(tableIDValue.getValue()),new TableValue(columnNames,columnIDs,(long)columnNames.length));
+    Table t = new Table(this,tableIDValue,columnNames,columnIDs,(long)columnNames.length);
+    tables.put(tableIDValue,t);
+    currentTransaction.put(new TableIndexKey(tableIDValue.getValue()),new LongArray(new long[0]));
+    currentTransaction.put(new TableRowIDFactoryKey(tableIDValue.getValue()),new LongValue(0L));
+    return t;
+  }
+  
+  /** Drop a table */
+  public void dropTable(String name)
+    throws WHException
+  {
+    if (currentTransaction == null)
+      throw new WHException("Must be in a transaction");
+    Table t = findTable(name);
+    if (t == null)
+      throw new WHException("Table does not exist");
+    deleteTable(t);
+  }
+  
+  /** Find an index */
+  public WHIndex lookupIndex(String name)
+    throws WHException
+  {
+    if (currentTransaction == null)
+      throw new WHException("Must be in a transaction");
+    return findIndex(name);
+  }
+  
+    
+  /** Create an index */
+  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");
+    Table t = (Table)table;
+    if (currentTransaction.get(new IndexLookupKey(name)) != null)
+      throw new WHException("Index already exists");
+    LongValue indexID = allocateNewGeneralID();
+    long[] columnIDs = new long[columnNames.length];
+    for (int i = 0 ; i < columnIDs.length ; i++)
+    {
+      columnIDs[i] = t.getColumnID(columnNames[i]);
+    }
+    setIndexName(indexID,name);
+    currentTransaction.put(new IndexKey(indexID.getValue()),new IndexValue(t.getIDValue(),columnIDs,comparatorClasses,unique));
+    Index i = new Index(this,indexID,t,columnIDs,comparatorClasses,unique);
+    indexes.put(indexID,i);
+    TableIndexKey tik = new TableIndexKey(t.getIDValue());
+    LongArray tiv = (LongArray)currentTransaction.get(tik);
+    if (tiv == null)
+      throw new WHConcurrencyException();
+    long[] indexList = tiv.getValue();
+    long[] newIndexList = new long[indexList.length + 1];
+    for (int j = 0 ; j < indexList.length ; j++)
+    {
+      newIndexList[j] = indexList[j];
+    }
+    newIndexList[indexList.length] = indexID.getValue();
+    currentTransaction.put(tik,new LongArray(newIndexList));
+    indexesPerTable.remove(t.getID());
+    i.initialize();
+    return i;
+  }
+    
+  /** Drop an index */
+  public void dropIndex(String name)
+    throws WHException
+  {
+    if (currentTransaction == null)
+      throw new WHException("Must be in a transaction");
+    Index i = findIndex(name);
+    if (i == null)
+      throw new WHException("Index does not exist");
+    deleteIndex(i);
+  }
+  
+  // Non-interface public methods
+  
+  protected Map<LongValue,LongValue> startMap = new HashMap<LongValue,LongValue>();
+  protected Map<LongValue,LongValue> endMap = new HashMap<LongValue,LongValue>();
+  
+  /** Allocate a new row ID */
+  public LongValue allocateNewTableRow(LongValue tableID)
+    throws WHException
+  {
+    LongValue start = startMap.get(tableID);
+    LongValue end = endMap.get(tableID);
+    
+    if (start != null && start.getValue() < end.getValue())
+    {
+      startMap.put(tableID,new LongValue(start.getValue()+1L));
+      return start;
+    }
+    
+    // We always do this in our own transaction to limit the deadlock potential,
+    // and we retry until we get the ID.  We only throw a concurrency exception
+    // if it seems clear that the table is gone.
+    TableRowIDFactoryKey tlk = new TableRowIDFactoryKey(tableID.getValue());
+
+    while (true)
+    {
+      WHTransaction allocateTransaction = transactionalStore.createTransaction();
+      try
+      {
+        LongValue tlv = (LongValue)allocateTransaction.get(tlk);
+        if (tlv == null)
+          break;
+        LongValue newValue = new LongValue(tlv.getValue()+100L);
+        allocateTransaction.put(tlk,newValue);
+        allocateTransaction.commit();
+        startMap.put(tableID,new LongValue(tlv.getValue()+1L));
+        endMap.put(tableID,newValue);
+        return tlv;
+      }
+      catch (WHConcurrencyException e)
+      {
+        Thread.yield();
+      }
+      finally
+      {
+        allocateTransaction.abandon();
+      }
+    }
+    throw new WHConcurrencyException();
+  }
+
+  /** Allocate a new general ID */
+  public LongValue allocateNewGeneralID()
+    throws WHException
+  {
+    // We always do this in our own transaction to limit the deadlock potential,
+    // and we retry until we get the ID.
+    GeneralIDFactoryKey tlk = new GeneralIDFactoryKey();
+
+    while (true)
+    {
+      WHTransaction allocateTransaction = transactionalStore.createTransaction();
+      try
+      {
+        LongValue tlv = (LongValue)allocateTransaction.get(tlk);
+        if (tlv == null)
+          tlv = new LongValue(0L);
+        allocateTransaction.put(tlk,new LongValue(tlv.getValue()+1L));
+        allocateTransaction.commit();
+        return tlv;
+      }
+      catch (WHConcurrencyException e)
+      {
+        Thread.yield();
+      }
+      finally
+      {
+        allocateTransaction.abandon();
+      }
+    }
+  }
+  
+  /** Random boolean decision */
+  protected boolean randomDecision()
+  {
+    return randomGenerator.nextBoolean();
+  }
+  
+  /** Read a value from current transaction.
+  */
+  protected WHKeyValue get(WHKey key)
+    throws WHException
+  {
+    return currentTransaction.get(key);
+  }
+  
+  /** Write a value to current transaction.
+  */
+  protected void put(WHKey key, WHKeyValue value)
+    throws WHException
+  {
+    currentTransaction.put(key,value);
+  }
+  
+  /** Delete a table row from all the indexes that are based on a table.
+  */
+  protected void deleteIndexRow(LongValue tableID, LongValue rowID, Set<Long> columns)
+    throws WHException
+  {
+    Index[] indexes = findIndexes(tableID);
+    for (int i = 0 ; i < indexes.length ; i++)
+    {
+      if (indexAffectedBy(indexes[i],columns))
+        indexes[i].deleteRow(rowID);
+    }
+  }
+  
+  /** Add a table row to all the indexes that are based on a table.
+  */
+  protected void addIndexRow(LongValue tableID, LongValue rowID, Set<Long> columns)
+    throws WHException
+  {
+    Index[] indexes = findIndexes(tableID);
+    for (int i = 0 ; i < indexes.length ; i++)
+    {
+      if (indexAffectedBy(indexes[i],columns))
+        indexes[i].addNewRow(rowID);
+    }
+  }
+
+  protected boolean indexAffectedBy(Index index, Set<Long> columns)
+    throws WHException
+  {
+    if (columns == null)
+      return true;
+    long[] indexColumnIDs = index.getIndexColumnIDs();
+    for (int i = 0 ; i < indexColumnIDs.length ; i++)
+    {
+      if (columns.contains(new Long(indexColumnIDs[i])))
+        return true;
+    }
+    return false;
+  }
+  
+  /** Delete a table definition.
+  * Also deletes associated indexes.
+  */
+  protected void deleteTable(Table t)
+    throws WHException
+  {
+    // First, remove indexes associated with this table
+    Index[] indexes = findIndexes(t.getID());
+    for (int i = 0 ; i < indexes.length ; i++)
+    {
+      deleteIndex(indexes[i]);
+    }
+    
+    // Now that the indexes are gone, delete all the table rows
+    t.remove();
+
+    // Delete the keys that belong to the table, and clean up cached values
+    tables.remove(t.getID());
+    indexesPerTable.remove(t.getID());
+    currentTransaction.put(new TableIndexKey(t.getIDValue()),null);
+    currentTransaction.put(new TableRowIDFactoryKey(t.getIDValue()),null);
+    removeTableName(t.getID());
+  }
+  
+  /** Delete an index definition.
+  */
+  protected void deleteIndex(Index i)
+    throws WHException
+  {
+    // First, remove this index from the indexes stored for each table
+    Table t = (Table)i.getTable();
+    Index[] indexList = findIndexes(t.getID());
+    if (indexList.length == 0)
+      throw new WHConcurrencyException();
+    long[] newIndexList = new long[indexList.length - 1];
+    int k = 0;
+    for (int j = 0 ; j < indexList.length ; j++)
+    {
+      if (indexList[j].getIDValue() != i.getIDValue())
+      {
+        newIndexList[k++] = indexList[j].getIDValue();
+        if (k == newIndexList.length)
+          break;
+      }
+    }
+    if (k != newIndexList.length)
+      throw new WHConcurrencyException();
+    currentTransaction.put(new TableIndexKey(t.getIDValue()),new LongArray(newIndexList));
+    indexesPerTable.remove(t.getID());
+
+    i.remove();
+
+    // Clean out the index definition and other associated keys, and blow away cached copies
+    indexes.remove(i.getID());
+    removeIndexName(i.getID());
+  }
+    
+  /** Find a table definition given its name.
+  */
+  protected Table findTable(String name)
+    throws WHException
+  {
+    LongValue tid = (LongValue)currentTransaction.get(new TableLookupKey(name));
+    if (tid == null)
+      return null;
+    return findTable(tid);
+  }
+  
+  protected Table findTable(LongValue tid)
+    throws WHException
+  {
+    Table t = tables.get(tid);
+    if (t != null)
+      return t;
+    TableValue tv = (TableValue)currentTransaction.get(new TableKey(tid.getValue()));
+    if (tv == null)
+      throw new WHConcurrencyException();
+    t = new Table(this,tid,tv.getColumnNames(),tv.getColumnIdentifiers(),tv.getNextColumnIdentifier());
+    tables.put(tid,t);
+    return t;
+  }
+  
+  /** Find an index definition given its name.
+  */
+  protected Index findIndex(String name)
+    throws WHException
+  {
+    LongValue indexID = (LongValue)currentTransaction.get(new IndexLookupKey(name));
+    if (indexID == null)
+      return null;
+    return findIndex(indexID);
+  }
+  
+  protected Index findIndex(LongValue indexID)
+    throws WHException
+  {
+    Index i = indexes.get(indexID);
+    if (i != null)
+      return i;
+    IndexValue indexValue = (IndexValue)currentTransaction.get(new IndexKey(indexID.getValue()));
+    if (indexValue == null)
+      throw new WHConcurrencyException();
+    Table t = findTable(new LongValue(indexValue.getTableID()));
+    if (t == null)
+      throw new WHConcurrencyException();
+    i = new Index(this,indexID,t,indexValue.getColumnIDs(),indexValue.getComparatorClassNames(),
+      indexValue.getUnique());
+    indexes.put(indexID,i);
+    return i;
+  }
+  
+  /** Find a set of associated index definitions given a table name.
+  */
+  protected Index[] findIndexes(LongValue tableID)
+    throws WHException
+  {
+    Index[] indexes = indexesPerTable.get(tableID);
+    if (indexes == null)
+    {
+      LongArray tiv = (LongArray)currentTransaction.get(new TableIndexKey(tableID.getValue()));
+      if (tiv == null)
+        throw new WHConcurrencyException();
+      long[] indexIDs = tiv.getValue();
+      indexes = new Index[indexIDs.length];
+      for (int i = 0; i < indexes.length ; i++)
+      {
+        indexes[i] = findIndex(new LongValue(indexIDs[i]));
+        if (indexes[i] == null)
+          throw new WHConcurrencyException();
+      }
+      indexesPerTable.put(tableID,indexes);
+    }
+    return indexes;
+  }
+  
+  /** Set a reference from table name to id and visa versa.  Presumes nothing has been set yet for this table ID. */
+  protected void setTableName(LongValue tableID, String tableName)
+    throws WHException
+  {
+    currentTransaction.put(new TableNameKey(tableID.getValue()),new StringValue(tableName));
+    currentTransaction.put(new TableLookupKey(tableName),tableID);
+  }
+  
+  /** Remove a table name reference.  Presumed to exist. */
+  protected void removeTableName(LongValue tableID)
+    throws WHException
+  {
+    TableNameKey tnk = new TableNameKey(tableID.getValue());
+    StringValue value = (StringValue)currentTransaction.get(tnk);
+    if (value == null)
+      throw new WHConcurrencyException();
+    currentTransaction.put(tnk,null);
+    currentTransaction.put(new TableLookupKey(value.getValue()),null);
+  }
+
+  /** Set a reference from index name to id and visa versa.  Presumes nothing has been set yet for this index ID. */
+  protected void setIndexName(LongValue indexID, String indexName)
+    throws WHException
+  {
+    currentTransaction.put(new IndexNameKey(indexID.getValue()),new StringValue(indexName));
+    currentTransaction.put(new IndexLookupKey(indexName),indexID);
+  }
+  
+  /** Remove an index name reference.  Presumed to exist. */
+  protected void removeIndexName(LongValue indexID)
+    throws WHException
+  {
+    IndexNameKey tnk = new IndexNameKey(indexID.getValue());
+    StringValue value = (StringValue)currentTransaction.get(tnk);
+    if (value == null)
+      throw new WHConcurrencyException();
+    currentTransaction.put(tnk,null);
+    currentTransaction.put(new IndexLookupKey(value.getValue()),null);
+  }
+  
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableTailKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableTailKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableTailKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableTailKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,40 @@
+/* $Id: TableTailKey.java 1208927 2011-12-01 01:18:07Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+public class TableTailKey extends TableBaseKey
+{
+  /** Constructor */
+  public TableTailKey(long tableID, int instanceNumber)
+  {
+    super(tableID,instanceNumber);
+  }
+  
+  public TableTailKey(byte[] data)
+  {
+    super(data);
+  }
+
+}
+

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableValue.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableValue.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableValue.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/keyvaluetablestore/TableValue.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,104 @@
+/* $Id: TableValue.java 1209929 2011-12-03 15:06:22Z kwright $ */
+
+/**
+* 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.keyvaluetablestore;
+
+import org.apache.warthog.api.*;
+import org.apache.warthog.transactionalkeyvaluestore.*;
+import org.apache.warthog.common.*;
+
+/** An index definition value */
+public class TableValue implements WHKeyValue
+{
+  protected String[] columnNames;
+  protected long[] columnIdentifiers;
+  protected long nextColumnIdentifier;
+    
+  /** Constructor */
+  public TableValue(String[] columnNames, long[] columnIdentifiers, long nextColumnIdentifier)
+  {
+    this.columnNames = columnNames;
+    this.columnIdentifiers = columnIdentifiers;
+    this.nextColumnIdentifier = nextColumnIdentifier;
+  }
+    
+  public TableValue(byte[] data)
+  {
+    BufferPointer bp = new BufferPointer(data);
+    columnNames = StringArray.readObject(bp);
+    columnIdentifiers = LongArray.readObject(bp);
+    nextColumnIdentifier = LongValue.readObject(bp);
+  }
+    
+  public byte[] serializeObject()
+  {
+    byte[] rval = new byte[StringArray.sizeObject(columnNames)+
+      LongArray.sizeObject(columnIdentifiers.length)+
+      LongValue.sizeObject()
+      ];
+    BufferPointer bp = new BufferPointer(rval);
+    StringArray.writeObject(bp,columnNames);
+    LongArray.writeObject(bp,columnIdentifiers);
+    LongValue.writeObject(bp,nextColumnIdentifier);
+    return rval;
+  }
+
+  /** Check if equals (classes must already agree) */
+  public boolean isEquals(WHKeyValue value)
+  {
+    TableValue other = (TableValue)value;
+    return StringArray.compareObject(other.columnNames,this.columnNames) &&
+      LongArray.compareObject(other.columnIdentifiers,this.columnIdentifiers) &&
+      other.nextColumnIdentifier == this.nextColumnIdentifier;
+  }
+  
+  public String[] getColumnNames()
+  {
+    return columnNames;
+  }
+
+  public long[] getColumnIdentifiers()
+  {
+    return columnIdentifiers;
+  }
+  
+  public long getNextColumnIdentifier()
+  {
+    return nextColumnIdentifier;
+  }
+  
+  public int hashCode()
+  {
+    int rval = 0;
+    for (int i = 0 ; i < columnNames.length ; i++)
+    {
+      rval += columnNames[i].hashCode();
+    }
+    return rval;
+  }
+  
+  public boolean equals(Object o)
+  {
+    if (this.getClass() != o.getClass())
+      return false;
+    TableValue other = (TableValue)o;
+    return StringArray.compareObject(other.columnNames,this.columnNames);
+  }
+  
+}

Added: incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/transactionalkeyvaluestore/WHKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/transactionalkeyvaluestore/WHKey.java?rev=1220349&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/transactionalkeyvaluestore/WHKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog-reimport/src/main/java/org/apache/warthog/transactionalkeyvaluestore/WHKey.java Sun Dec 18 08:26:30 2011
@@ -0,0 +1,30 @@
+/* $Id: WHKey.java 1205831 2011-11-24 13:57:15Z kwright $ */
+
+/**
+* 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.transactionalkeyvaluestore;
+
+/** This object represents a key in a transactional key/value store.
+* Pretty much any (serializable) object can be used, provided there
+* is an available hash function and equals method.
+*/
+public interface WHKey extends WHKeyValue
+{
+  /** Calculate the hash function. */
+  public long getHashCode();
+}