manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1202571 - in /incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog: common/ tablestore/
Date Wed, 16 Nov 2011 08:06:55 GMT
Author: kwright
Date: Wed Nov 16 08:06:54 2011
New Revision: 1202571

URL: http://svn.apache.org/viewvc?rev=1202571&view=rev
Log:
Add beginnings of tablestore, table, and index implementations

Added:
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
  (with props)
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
  (with props)
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
  (with props)
Modified:
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java?rev=1202571&r1=1202570&r2=1202571&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java
Wed Nov 16 08:06:54 2011
@@ -23,7 +23,7 @@ import org.apache.warthog.interfaces.*;
 
 /** Integer value, serializable.
 */
-public class IntegerValue implements WHValue
+public class IntegerValue implements WHKey
 {
   int value;
   
@@ -53,6 +53,19 @@ public class IntegerValue implements WHV
     return value;
   }
   
+  public int hashCode()
+  {
+    return (value << 4) ^ (value >> 1);
+  }
+  
+  public boolean equals(Object o)
+  {
+    if (!(o instanceof IntegerValue))
+      return false;
+    IntegerValue other = (IntegerValue)o;
+    return value == other.value;
+  }
+
   public static int readObject(BufferPointer bp)
   {
     int value = (((int)bp.readValue()) & 0xff);

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java?rev=1202571&r1=1202570&r2=1202571&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java
Wed Nov 16 08:06:54 2011
@@ -23,7 +23,7 @@ import org.apache.warthog.interfaces.*;
 
 /** Long value, serializable.
 */
-public class LongValue implements WHValue
+public class LongValue implements WHKey
 {
   long value;
   
@@ -52,7 +52,21 @@ public class LongValue implements WHValu
   {
     return value;
   }
+
+  public int hashCode()
+  {
+    return new Long(value).hashCode();
+  }
   
+  public boolean equals(Object o)
+  {
+    if (!(o instanceof LongValue))
+      return false;
+    LongValue other = (LongValue)o;
+    return value == other.value;
+  }
+
+
   public static long readObject(BufferPointer bp)
   {
     long value = (((long)bp.readValue()) & 0xffL);

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java?rev=1202571&r1=1202570&r2=1202571&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java
Wed Nov 16 08:06:54 2011
@@ -23,7 +23,7 @@ import org.apache.warthog.interfaces.*;
 
 /** This object represents a string that can be stored in the key/value store.
 */
-public class StringValue implements WHValue
+public class StringValue implements WHKey
 {
   protected String value;
   
@@ -54,6 +54,19 @@ public class StringValue implements WHVa
     return rval;
   }
 
+  public int hashCode()
+  {
+    return value.hashCode();
+  }
+  
+  public boolean equals(Object o)
+  {
+    if (!(o instanceof StringValue))
+      return false;
+    StringValue other = (StringValue)o;
+    return value.equals(other.value);
+  }
+  
   public static String readObject(BufferPointer bp)
   {
     char[] array = CharacterArray.readObject(bp);

Added: 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=1202571&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
(added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
Wed Nov 16 08:06:54 2011
@@ -0,0 +1,97 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.warthog.tablestore;
+
+import org.apache.warthog.interfaces.*;
+
+/** This is the standard implementation of WHIndex.
+*/
+public class Index implements WHIndex
+{
+  protected TableStore ts;
+  protected Table table;
+  protected String indexName;
+  
+  /** Constructor */
+  public Index(TableStore ts, Table table, String indexName)
+  {
+    this.ts = ts;
+    this.table = table;
+    this.indexName = indexName;
+  }
+  
+  /** Get the table the index applies to.
+  */
+  public WHTable getTable()
+    throws WHException
+  {
+    return table;
+  }
+  
+  /** Get the columns that are indexed
+  */
+  public String[] getColumnNames()
+    throws WHException
+  {
+    // MHL
+    return null;
+  }
+
+  /** Create an accessor based on this index which uses the provided criteria.  The
+  * criteria must align with the index's columns.  Null values are permitted where
+  * no criteria are present.
+  */
+  public WHAccessor buildAccessor(IndexCriteria[] criteria)
+  {
+    // MHL
+    return null;
+  }
+  
+  // Below this line are methods that are not meant to be used for general purposes,
+  // which may be moved to implementation classes.
+  
+  /** Get the comparators corresponding to the columns.
+  * Effectively also returns the index order for each of those columns
+  * (as determined by the comparator).
+  */
+  public WHComparator[] getComparators()
+    throws WHException
+  {
+    // MHL
+    return null;
+  }
+  
+  /** Add a new row to the index.
+  */
+  public void addNewRow(int rowNumber)
+    throws WHException
+  {
+    // MHL
+  }
+  
+  /** Remove a row from the index.  The row must currently exist.
+  */
+  public void deleteRow(int rowNumber)
+    throws WHException
+  {
+    // MHL
+  }
+  
+}

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 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=1202571&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
(added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
Wed Nov 16 08:06:54 2011
@@ -0,0 +1,110 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.warthog.tablestore;
+
+import org.apache.warthog.interfaces.*;
+
+/** This is the standard implementation of WHTable.
+*/
+public class Table implements WHTable
+{
+  protected TableStore ts;
+  protected String tableName;
+  
+  /** Constructor */
+  public Table(TableStore ts, String tableName)
+  {
+    this.ts = ts;
+    this.tableName = tableName;
+  }
+  
+  /** Get the column names.
+  */
+  public String[] getColumnNames()
+    throws WHException
+  {
+    // MHL
+    return null;
+  }
+  
+  /** Compact the table.
+  */
+  public void compact()
+    throws WHException
+  {
+    // MHL
+  }
+  
+  /** Insert a row */
+  public void insertRow(String[] columns, WHValue[] values)
+    throws WHException
+  {
+    // MHL
+  }
+  
+  /** Update row(s) */
+  public void updateRows(String[] columns, WHValue[] values,
+    WHAccessor accessor, WHFilter filter)
+    throws WHException
+  {
+    // MHL
+  }
+    
+  /** Delete row(s) */
+  public void deleteRows(WHAccessor accessor, WHFilter filter)
+    throws WHException
+  {
+    // MHL
+  }
+  
+  // Below this point is the 'non-public' part of the API, which may eventually be moved
into implementation classes.
+  
+  /** Get the row count */
+  public int getRowCount()
+    throws WHException
+  {
+    // MHL
+    return -1;
+  }
+  
+  /** Get the max row number, plus one */
+  public int getMaxRowNumber()
+    throws WHException
+  {
+    // MHL
+    return -1;
+  }
+    
+  /** Get the data for a given row # and column. */
+  public WHValue getValue(int rowNumber, String columnName)
+    throws WHException
+  {
+    // MHL
+    return null;
+  }
+
+  /** Build an accessor that simply scans all the rows in the table */
+  public WHAccessor buildAccessor()
+  {
+    // MHL
+    return null;
+  }
+
+}
\ No newline at end of file

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 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=1202571&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
(added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
Wed Nov 16 08:06:54 2011
@@ -0,0 +1,212 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.warthog.tablestore;
+
+import org.apache.warthog.interfaces.*;
+import org.apache.warthog.common.*;
+import java.util.*;
+
+/** This is the standard implementation of WHTableStore.
+*/
+public class TableStore implements WHTableStore
+{
+  protected WHTransactionalStore transactionalStore;
+  protected WHTransaction currentTransaction = null;
+  
+  protected Map<String,Table> tables = null;
+  protected Map<String,Index> indexes = null;
+  
+  /** Constructor */
+  public TableStore(WHTransactionalStore transactionalStore)
+  {
+    this.transactionalStore = transactionalStore;
+  }
+  
+  /** Begin a transaction */
+  public void beginTransaction()
+    throws WHException
+  {
+    if (currentTransaction != null)
+      throw new WHException("Already in a transaction");
+    currentTransaction = transactionalStore.createTransaction();
+    tables = new HashMap<String,Table>();
+    indexes = new HashMap<String,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;
+  }
+  
+  /** Abandon a transaction */
+  public void abandonTransaction()
+    throws WHException
+  {
+    if (currentTransaction == null)
+      throw new WHException("No transaction to abandon");
+    currentTransaction = null;
+    tables = null;
+    indexes = null;
+  }
+  
+  /** Lookup table */
+  public WHTable lookupTable(String name)
+    throws WHException
+  {
+    if (currentTransaction == null)
+      throw new WHException("Must be in a transaction");
+    return findTable(name);
+  }
+  
+  protected Table findTable(String name)
+    throws WHException
+  {
+    Table t = tables.get(name);
+    if (t != null)
+      return t;
+    if (currentTransaction.get(new TableKey(name)) == null)
+      throw new WHException("No such table '"+name+"'");
+    t = new Table(this,name);
+    tables.put(name,t);
+    return t;
+  }
+  
+  /** Create a table */
+  public WHTable createTable(String name, String[] columnNames)
+    throws WHException
+  {
+    if (currentTransaction == null)
+      throw new WHException("Must be in a transaction");
+    // MHL
+    return null;
+  }
+  
+  /** Drop a table */
+  public void dropTable(String name)
+    throws WHException
+  {
+    if (currentTransaction == null)
+      throw new WHException("Must be in a transaction");
+    // MHL
+  }
+  
+  /** Find an index */
+  public WHIndex lookupIndex(String name)
+    throws WHException
+  {
+    if (currentTransaction == null)
+      throw new WHException("Must be in a transaction");
+    Index i = indexes.get(name);
+    if (i != null)
+      return i;
+    IndexValue indexValue = (IndexValue)currentTransaction.get(new IndexKey(name));
+    if (indexValue == null)
+      throw new WHException("No such index '"+name+"'");
+    i = new Index(this,findTable(indexValue.getTableName()),name);
+    indexes.put(name,i);
+    return i;
+  }
+    
+  /** Create an index */
+  public WHIndex createIndex(String name, String tableName, String[] columnNames, String[]
comparatorClasses, boolean unique)
+    throws WHException
+  {
+    if (currentTransaction == null)
+      throw new WHException("Must be in a transaction");
+    // MHL
+    return null;
+  }
+    
+  /** Drop an index */
+  public void dropIndex(String name)
+    throws WHException
+  {
+    if (currentTransaction == null)
+      throw new WHException("Must be in a transaction");
+    // MHL
+  }
+    
+  /** Perform a query */
+  public WHQueryResult performQuery(QueryDescription specification)
+    throws WHException
+  {
+    if (currentTransaction == null)
+      throw new WHException("Must be in a transaction");
+    // MHL
+    return null;
+  }
+  
+  // Protected classes and methods
+  
+  protected static class TableKey extends StringValue
+  {
+    /** Constructor */
+    public TableKey(String name)
+    {
+      super(name);
+    }
+    
+    public TableKey(byte[] data)
+    {
+      super(data);
+    }
+    
+  }
+  
+  protected static class IndexKey extends StringValue
+  {
+    /** Constructor */
+    public IndexKey(String name)
+    {
+      super(name);
+    }
+    
+    public IndexKey(byte[] data)
+    {
+      super(data);
+    }
+  }
+  
+  protected static class IndexValue extends StringValue
+  {
+    /** Constructor */
+    public IndexValue(String tableName)
+    {
+      super(tableName);
+    }
+    
+    public IndexValue(byte[] data)
+    {
+      super(data);
+    }
+    
+    public String getTableName()
+    {
+      return getValue();
+    }
+  }
+}

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message