You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by ka...@apache.org on 2009/01/06 21:25:59 UTC

svn commit: r732099 [1/2] - in /labs/bananadb: ./ trunk/ trunk/src/ trunk/src/main/ trunk/src/main/java/ trunk/src/main/java/org/ trunk/src/main/java/org/apache/ trunk/src/main/java/org/apache/labs/ trunk/src/main/java/org/apache/labs/bananadb/ trunk/s...

Author: kalle
Date: Tue Jan  6 12:25:58 2009
New Revision: 732099

URL: http://svn.apache.org/viewvc?rev=732099&view=rev
Log:
BananaDB, initial import.


Added:
    labs/bananadb/
    labs/bananadb/trunk/
    labs/bananadb/trunk/LICENSE.txt
    labs/bananadb/trunk/README.txt
    labs/bananadb/trunk/TODO.txt
    labs/bananadb/trunk/doap.rdf
    labs/bananadb/trunk/pom.xml
    labs/bananadb/trunk/src/
    labs/bananadb/trunk/src/main/
    labs/bananadb/trunk/src/main/java/
    labs/bananadb/trunk/src/main/java/org/
    labs/bananadb/trunk/src/main/java/org/apache/
    labs/bananadb/trunk/src/main/java/org/apache/labs/
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/AbstractIndex.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/Entity.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/EntityCursor.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/EntityStore.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/PrimaryIndex.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/PrimaryKey.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/SecondaryIndex.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/SecondaryKey.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/EntityClassHandler.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/Hashtable.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/HashtableAccessor.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/KeyClassHandler.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/BooleanHandler.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/ByteHandler.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/CharHandler.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/DoubleHandler.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/FloatHandler.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/IntegerHandler.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/LongHandler.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/ShortHandler.java
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/StringValueHandler.java
    labs/bananadb/trunk/src/test/
    labs/bananadb/trunk/src/test/java/
    labs/bananadb/trunk/src/test/java/org/
    labs/bananadb/trunk/src/test/java/org/apache/
    labs/bananadb/trunk/src/test/java/org/apache/labs/
    labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/
    labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/
    labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/City.java
    labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/Country.java
    labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/EntityStore.java
    labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/hashtable/
    labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/hashtable/TestHashtable.java

Added: labs/bananadb/trunk/LICENSE.txt
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/LICENSE.txt?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/LICENSE.txt (added)
+++ labs/bananadb/trunk/LICENSE.txt Tue Jan  6 12:25:58 2009
@@ -0,0 +1,202 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+

Added: labs/bananadb/trunk/README.txt
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/README.txt?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/README.txt (added)
+++ labs/bananadb/trunk/README.txt Tue Jan  6 12:25:58 2009
@@ -0,0 +1,5 @@
+This is BananaDB, a hashtable (Map<K, V>) located on filesystem and *not* in memory.
+
+The aim is to add transactions, secondary indices and a top level annotation API. An abstract API for this is already available in the source folder, it is however only the hashtable code that works.
+
+kalle@apache.org 

Added: labs/bananadb/trunk/TODO.txt
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/TODO.txt?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/TODO.txt (added)
+++ labs/bananadb/trunk/TODO.txt Tue Jan  6 12:25:58 2009
@@ -0,0 +1,17 @@
+= Hashtable =
+
+== Write lock mechanism ==
+
+File write lock for hashtable file, entities file, and one per partition file.
+
+Would it be possible to lock a specific area of the file for writing so that multiple accessors
+could write at the same time but at different places?
+
+== Growing hashtable file ==
+
+Currently the capacity of a hashtable is static. Should this be growable? Or should one combine multiple hashfiles
+using a technique similar to the Lucene MultiReader and merge/optimization?
+
+= Transactions =
+
+= Annotation API =

Added: labs/bananadb/trunk/doap.rdf
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/doap.rdf?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/doap.rdf (added)
+++ labs/bananadb/trunk/doap.rdf Tue Jan  6 12:25:58 2009
@@ -0,0 +1,39 @@
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://usefulinc.com/ns/doap#"
+         xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:labs="http://labs.apache.org/doap-ext/1.0#"
+         xmlns:projects="http://projects.apache.org/ns/asfext#">
+  <Project rdf:about="http://labs.apache.org/labs#bananadb">
+    <name>BananaDB</name>
+    <shortname>bananadb</shortname>
+    <shortdesc xml:lang="en">Filesystem based hashtable</shortdesc>
+    <description xml:lang="en">Map&lt;K, V> living in the filesystem rather than in RAM. Aims at becoming a general
+      embedded key/value pair DB with transactions, secondary indices and annotational API.
+    </description>
+    <homepage rdf:resource="http://labs.apache.org/bananadb/"/>
+    <license rdf:resource="http://usefulinc.com/doap/licenses/asl20"/>
+    <created>2009-1-3</created>
+    <labs:status>active</labs:status>
+    <maintainer>
+      <foaf:Person rdf:about="http://people.apache.org/~kalle/#me">
+        <foaf:name>Karl Wettin</foaf:name>
+        <foaf:homepage rdf:resource="http://people.apache.org/~kalle/"/>
+        <foaf:mbox_sha1sum>a3ec19ecb29678b7b6f009c038d734b09ea4ca8e</foaf:mbox_sha1sum>
+      </foaf:Person>
+    </maintainer>
+    <repository>
+      <SVNRepository>
+        <location rdf:resource="http://svn.apache.org/repos/asf/labs/bananadb/"/>
+        <browse rdf:resource="http://svn.apache.org/viewvc/labs/bananadb/"/>
+      </SVNRepository>
+    </repository>
+    <programming-language>Java</programming-language>
+    <projects:implements>
+      <projects:Standard>
+        <projects:id>RDF</projects:id>
+        <projects:title>Resource Description Language</projects:title>
+        <projects:body>W3C</projects:body>
+        <projects:url rdf:resource="http://www.w3.org/RDF/"/>
+      </projects:Standard>
+    </projects:implements>
+  </Project>
+</rdf:RDF>
+

Added: labs/bananadb/trunk/pom.xml
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/pom.xml?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/pom.xml (added)
+++ labs/bananadb/trunk/pom.xml Tue Jan  6 12:25:58 2009
@@ -0,0 +1,46 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.labs</groupId>
+  <artifactId>bananadb</artifactId>
+  <packaging>jar</packaging>
+  <version>0.1-SNAPSHOT</version>
+  <name>BananaDB</name>
+  <description>BananaDB, a hashtable living on filesystem and not in memory.</description>
+  <url>http://kodapan.se/bananadb</url>
+
+  <dependencies>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.1.1</version>
+    </dependency>
+
+  </dependencies>
+  <build>
+    <finalName>bananadb</finalName>
+
+    <plugins>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+
+    </plugins>
+
+  </build>
+</project>

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/AbstractIndex.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/AbstractIndex.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/AbstractIndex.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/AbstractIndex.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,34 @@
+package org.apache.labs.bananadb;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * User: kalle
+ * Date: 2008-jul-23
+ * Time: 02:34:19
+ */
+public abstract class AbstractIndex<K, T> {
+
+  public abstract EntityCursor<T> cursor();
+
+  public abstract EntityCursor<T> cursor(K start);
+
+  public abstract EntityCursor<T> cursor(K start, K end);
+
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/Entity.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/Entity.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/Entity.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/Entity.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,27 @@
+package org.apache.labs.bananadb;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * User: kalle
+ * Date: 2008-jul-24
+ * Time: 19:12:08
+ */
+public @interface Entity {
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/EntityCursor.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/EntityCursor.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/EntityCursor.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/EntityCursor.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,36 @@
+package org.apache.labs.bananadb;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * User: kalle
+ * Date: 2008-jul-23
+ * Time: 02:38:47
+ */
+public abstract class EntityCursor<T> {
+
+  public abstract boolean next();
+
+  public abstract T get();
+
+  public abstract void delete();
+
+  public abstract void close();
+
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/EntityStore.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/EntityStore.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/EntityStore.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/EntityStore.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,36 @@
+package org.apache.labs.bananadb;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * User: kalle
+ * Date: 2008-jul-23
+ * Time: 02:54:45
+ */
+public class EntityStore {
+
+  public <PK, T> PrimaryIndex<PK, T> getPrimaryIndex(Class primaryKeyClass, Class entityClass) {
+    return null;
+  }
+
+  public <PK, SK, T> SecondaryIndex<PK, SK, T> getSecondaryIndex(PrimaryIndex<PK, T> primaryIndex, Class secondaryKeyClass, String secondaryKeyAttributeName) {
+    return null;
+  }
+
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/PrimaryIndex.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/PrimaryIndex.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/PrimaryIndex.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/PrimaryIndex.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,51 @@
+package org.apache.labs.bananadb;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * User: kalle
+ * Date: 2008-jul-23
+ * Time: 02:33:45
+ */
+public class PrimaryIndex<PK, T> extends AbstractIndex<PK, T> {
+
+  public T get(PK key) {
+   return null;
+  }
+
+  public T put(T entity) {
+    return null;
+  }
+
+  public T remove(PK key) {
+   return null;
+  }
+
+  public EntityCursor<T> cursor() {
+    return null;
+  }
+
+  public EntityCursor<T> cursor(PK start) {
+    return null;
+  }
+
+  public EntityCursor<T> cursor(PK start, PK end) {
+    return null;
+  }
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/PrimaryKey.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/PrimaryKey.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/PrimaryKey.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/PrimaryKey.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,30 @@
+package org.apache.labs.bananadb;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * User: kalle
+ * Date: 2008-jul-23
+ * Time: 02:47:59
+ */
+public @interface PrimaryKey {
+
+  public String sequence() default "[unassigned]";
+
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/SecondaryIndex.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/SecondaryIndex.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/SecondaryIndex.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/SecondaryIndex.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,55 @@
+package org.apache.labs.bananadb;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * User: kalle
+ * Date: 2008-jul-23
+ * Time: 02:36:54
+ */
+public class SecondaryIndex<PK, SK, T> extends AbstractIndex<SK, T> {
+
+  private String secondaryKeyAttributeName;
+  private PrimaryIndex<PK, T> primaryIndex;
+
+  public SecondaryIndex(PrimaryIndex<PK, T> primaryIndex, String secondaryKeyAttributeName) {
+    this.primaryIndex = primaryIndex;
+    this.secondaryKeyAttributeName = secondaryKeyAttributeName;
+  }
+
+  public EntityCursor<T> cursor() {
+    return null;
+  }
+
+  public EntityCursor<T> cursor(SK start) {
+    return null;
+  }
+
+  public EntityCursor<T> cursor(SK start, SK end) {
+    return null;
+  }
+
+  public String getSecondaryKeyAttributeName() {
+    return secondaryKeyAttributeName;
+  }
+
+  public PrimaryIndex<PK, T> getPrimaryIndex() {
+    return primaryIndex;
+  }
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/SecondaryKey.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/SecondaryKey.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/SecondaryKey.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/SecondaryKey.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,30 @@
+package org.apache.labs.bananadb;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * User: kalle
+ * Date: 2008-jul-23
+ * Time: 02:49:08
+ */
+public @interface SecondaryKey {
+
+  public Class otherEndClass();
+
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/EntityClassHandler.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/EntityClassHandler.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/EntityClassHandler.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/EntityClassHandler.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,34 @@
+package org.apache.labs.bananadb.hashtable;
+
+/*
+ * 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.
+ */
+
+
+import java.io.*;
+
+/**
+ * User: kalle
+ * Date: 2009-jan-03
+ * Time: 04:13:29
+ */
+public interface EntityClassHandler<C> {
+
+  public abstract Class<C> getEntityClass();
+  public abstract void write(C entity, DataOutputStream out) throws IOException;
+  public abstract C read(DataInputStream in) throws IOException; 
+  
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/Hashtable.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/Hashtable.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/Hashtable.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/Hashtable.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,774 @@
+package org.apache.labs.bananadb.hashtable;
+
+/*
+ * 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.
+ */
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Map<K, V> that lives on local disk via random access file.
+ * It is not thread safe.
+ * It can not handle null keys.
+ * It is limited to a maximum number of entries, defined when opening (formatting) the map.
+ * The values can however be of any size.
+ * <p/>
+ * It will need a entries partitioning scheme similar to the the data partitioning scheme
+ * <p/>
+ * <p/>
+ * <p/>
+ * multiple files contains the values <pk, value>
+ * one file contains the entries <pk, key, pointer<above file, offset, length>, next entry position>
+ * one file contains the hashtable <key hash, first entry pos in previous file>
+ * <p/>
+ * <p/>
+ * hashtable.raw:
+ * byte   0 = null
+ * int    offset position to first entry with this hash
+ * <p/>
+ * entries: (hashtable entry)
+ * int    offset position in this file to the next entry with the same hash, -1 = null
+ * int    value partition number, -1 == value is null
+ * int    offset position in value partition, -1 == null
+ * int    key length in bytes, 0 = null
+ * key    writable key (if not null)
+ * int    key hash, used for rehashing
+ * <p/>
+ * data.[0-9]+:
+ * int    value length in bytes, 0 = null
+ * value  writable value
+ * <p/>
+ * <p/>
+ * <p/>
+ * Entries file contains metadata in the first 1024 bytes.
+ * <p/>
+ * at 0: integer> next entry offset
+ * at 4: integer> count
+ * <p/>
+ * <p/>
+ * todo: optimize
+ * todo: overwrite old value in data file if possible when replacing a value. keep track of unused positions
+ * todo: rehash()
+ * todo: use partitioned space for entries and not just for value data
+ */
+public class Hashtable<K, V> {
+
+  private Log log = LogFactory.getLog(Hashtable.class);
+
+  private static final int HASHTABLE_RECORD_BYTE_SIZE = 1 + 4;
+
+  /**
+   * the header contains meta data such as number of records, et c. todo factor out to new meta data file
+   */
+  private static final int ENTRIES_HEADER_BYTE_SIZE = 1024;
+
+  private File path;
+  private List<Partition> partitions = new ArrayList<Partition>();
+
+  private File hashtableFile;
+  private File entriesFile;
+
+//  private Class<K> keyClass;
+//  private Class<V> valueClass;
+
+
+  private int partitionSize = 10 * (1024 ^ 2);
+
+  private KeyClassHandler<K> keyClassHandler;
+
+  /**
+   * size of an entry in the hash file
+   */
+  private int entryByteSize;
+
+  private EntityClassHandler<V> valueClassHandler;
+
+
+  private int hashtableSize;
+  private int entryCount;
+  private int nextEntryOffset;
+
+
+  private void setNextEntryOffset(int nextEntryOffset) {
+    this.nextEntryOffset = nextEntryOffset;
+  }
+
+  private int getNextEntryOffset() {
+    return nextEntryOffset;
+  }
+
+//  // todo factor out RAF to new reader (transaction) class.
+//  private RandomAccessFile hashtableRAF;
+//  private RandomAccessFile entriesRAF;
+
+
+  private List<HashtableAccessor> accessors = new ArrayList<HashtableAccessor>();
+
+  public HashtableAccessor createAccessor(boolean readOnly) throws IOException {
+    return new HashtableAccessor(this, readOnly);
+  }
+
+  public Hashtable(File path, int capacity, KeyClassHandler<K> keyClassHandler, EntityClassHandler<V> valueClassHandler) throws IOException {
+
+    this.keyClassHandler = keyClassHandler;
+    this.valueClassHandler = valueClassHandler;
+
+    entryByteSize = 4 + 4 + 4 + 4 + 4 + keyClassHandler.getByteSize();
+
+    this.path = path;
+    if (!path.exists()) {
+      log.warn("Creating new path " + path.getAbsolutePath());
+      path.mkdirs();
+    }
+
+    hashtableFile = new File(path, "hashtable");
+    entriesFile = new File(path, "entries");
+
+    // open
+
+    File hashtableFile = new File(path, "hashtable");
+    if (!hashtableFile.exists()) {
+      format(hashtableFile, capacity * HASHTABLE_RECORD_BYTE_SIZE);
+    }
+
+    hashtableSize = (int) (hashtableFile.length() / HASHTABLE_RECORD_BYTE_SIZE);
+
+    File entriesFile = new File(path, "entries");
+    if (!entriesFile.exists()) {
+
+      log.info("Creating a new entries file");
+
+      format(entriesFile, ENTRIES_HEADER_BYTE_SIZE + (capacity * entryByteSize));
+      setNextEntryOffset(ENTRIES_HEADER_BYTE_SIZE);
+
+      RandomAccessFile entriesRAF = new RandomAccessFile(entriesFile, "rw");
+      entriesRAF.seek(0);
+      entriesRAF.writeInt(getNextEntryOffset());
+      entriesRAF.close();
+
+    } else {
+
+      RandomAccessFile entriesRAF = new RandomAccessFile(entriesFile, "r");
+      entriesRAF.seek(0);
+      setNextEntryOffset(entriesRAF.readInt());
+      entryCount = entriesRAF.readInt();
+      entriesRAF.close();
+
+    }
+
+    File[] valueFiles = path.listFiles(new FileFilter() {
+      public boolean accept(File file) {
+        return file.isFile() && file.getName().matches("data\\.[0-9]+");
+      }
+    });
+    Arrays.sort(valueFiles, new Comparator<File>() {
+      public int compare(File file, File file1) {
+        return file.getName().compareTo(file1.getName());
+      }
+    });
+    System.currentTimeMillis(); // todo check order
+
+    if (valueFiles.length > 0) {
+      for (int i = 0; i < valueFiles.length; i++) {
+        if (!valueFiles[i].getName().endsWith("." + i)) {
+          throw new FileNotFoundException("Exptected partition data." + i + " but found " + valueFiles[i].getName());
+        }
+        Partition partition = new Partition(i);
+        partition.open();
+      }
+    } else {
+
+      Partition partition = new Partition();
+      partition.format(partitionSize);
+      partition.open();
+
+    }
+
+
+  }
+
+  public V put(HashtableAccessor accessor, K key, V value) throws IOException {
+
+    // write key to buf
+    ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+    keyClassHandler.write(key, new DataOutputStream(baos));
+    byte[] keyBuf = baos.toByteArray();
+    baos.close();
+
+    // write value to buf
+    byte[] valueBuf = null;
+    if (value != null) {
+      baos = new ByteArrayOutputStream(1024); // todo
+      valueClassHandler.write(value, new DataOutputStream(baos));
+      valueBuf = baos.toByteArray();
+      baos.close();
+    }
+
+    V oldValue = null;
+
+    int keyHash = key.hashCode();
+    int index = keyHash & (hashtableSize - 1);
+    byte[] hashtableRecordBuf = new byte[HASHTABLE_RECORD_BYTE_SIZE];
+    accessor.getHashtableRAF().seek(index * HASHTABLE_RECORD_BYTE_SIZE);
+    accessor.getHashtableRAF().read(hashtableRecordBuf);
+    DataInput in = new DataInputStream(new ByteArrayInputStream(hashtableRecordBuf));
+
+    if (in.readByte() == 0) {
+      // create posting for hash
+
+      int entryOffset = getNextEntryOffset();
+      setNextEntryOffset(getNextEntryOffset() + entryByteSize);
+      accessor.getEntriesRAF().seek(0);
+      accessor.getEntriesRAF().writeInt(getNextEntryOffset());
+      accessor.getEntriesRAF().writeInt(++entryCount);
+
+      accessor.getEntriesRAF().seek(entryOffset);
+      writeEntry(accessor, -1, keyBuf, valueBuf, keyHash);
+
+      accessor.getHashtableRAF().seek(index * HASHTABLE_RECORD_BYTE_SIZE);
+      accessor.getHashtableRAF().writeByte(1);
+      accessor.getHashtableRAF().writeInt(entryOffset);
+
+      return null;
+
+    } else {
+
+      // already contains a posting for the hash
+
+      int firstEntryOffset = in.readInt();
+
+      K compareKey;
+
+      int previousEntryOffset = -1;
+      int nextEntryOffset = firstEntryOffset;
+      while (nextEntryOffset != -1) {
+        int entryOffset = nextEntryOffset;
+
+        accessor.getEntriesRAF().seek(entryOffset);
+
+        nextEntryOffset = accessor.getEntriesRAF().readInt();
+        int partitionNumber = accessor.getEntriesRAF().readInt();
+        int partitionOffset = accessor.getEntriesRAF().readInt();
+        int keySize = accessor.getEntriesRAF().readInt();
+        if (keySize > 0) {
+          byte[] compareKeyBuf = new byte[keySize];
+          accessor.getEntriesRAF().read(compareKeyBuf);
+          compareKey = keyClassHandler.read(new DataInputStream(new ByteArrayInputStream(compareKeyBuf)));
+          if (key.equals(compareKey)) {
+
+
+            if (partitionNumber != -1) {
+              // read old value
+              Partition partition = partitions.get(partitionNumber);
+              oldValue = partition.read(accessor, partitionOffset);
+            }
+
+            // over write old entry posting
+            accessor.getEntriesRAF().seek(entryOffset);
+            writeEntry(accessor, nextEntryOffset, keyBuf, valueBuf, keyHash);
+
+            return oldValue;
+          }
+        }
+
+        previousEntryOffset = entryOffset;
+
+      }
+
+      // this key instance did not exist in entries
+      // although it shares hash with some other keys in there.
+
+      // create new entry and point at it from the previous entry
+      int entryOffset = getNextEntryOffset();
+      setNextEntryOffset(getNextEntryOffset() + entryByteSize);
+
+      accessor.getEntriesRAF().seek(entryOffset);
+      writeEntry(accessor, -1, keyBuf, valueBuf, keyHash);
+
+      accessor.getEntriesRAF().seek(previousEntryOffset);
+      accessor.getEntriesRAF().writeInt(entryOffset);
+
+      accessor.getEntriesRAF().seek(4);
+      accessor.getEntriesRAF().writeInt(++entryCount);
+
+      return null;
+    }
+
+  }
+
+  private void writeEntry(HashtableAccessor accessor, int nextEntity, byte[] keyBuf, byte[] valueBuf, int keyHashCode) throws IOException {
+
+    int partitionNumber = -1;
+    long offset = -1;
+    if (valueBuf != null) {
+
+      Partition partition = partitions.get(partitions.size() - 1);
+      if (partition.bytesLeft < valueBuf.length) {
+        synchronized (this) {
+          partition = this.new Partition();
+        }
+        partition.format(partitionSize);
+
+        for (HashtableAccessor tmp : accessors) {
+          tmp.registerPartition(partition);
+        }
+      }
+      partitionNumber = partition.partitionNumber;
+
+      offset = partition.append(accessor, valueBuf);
+    }
+
+    // int    offset position in this file to the next entry with the same hash, -1 = null
+    accessor.getEntriesRAF().writeInt(nextEntity);
+
+    // int    value partition number, -1 == null
+    accessor.getEntriesRAF().writeInt(partitionNumber);
+
+    // int    offset position in value partition, -1 == null
+    accessor.getEntriesRAF().writeInt((int) offset);
+
+    // int    key length in bytes, 0 = null
+    if (keyBuf == null || keyBuf.length == 0) {
+      accessor.getEntriesRAF().writeInt(0);
+    } else {
+      accessor.getEntriesRAF().writeInt(keyBuf.length);
+
+      // key    writable key
+      accessor.getEntriesRAF().write(keyBuf);
+
+      // key    hash
+      accessor.getEntriesRAF().write(keyHashCode);
+    }
+
+  }
+
+  public V get(HashtableAccessor accessor, K key) throws IOException {
+
+    int keyHash = key.hashCode();
+    int index = keyHash & (hashtableSize - 1);
+    byte[] hashtableRecordBuf = new byte[HASHTABLE_RECORD_BYTE_SIZE];
+    accessor.getHashtableRAF().seek(index * HASHTABLE_RECORD_BYTE_SIZE);
+    accessor.getHashtableRAF().read(hashtableRecordBuf);
+    DataInput in = new DataInputStream(new ByteArrayInputStream(hashtableRecordBuf));
+    byte isnull = in.readByte();
+    if (isnull == 0) {
+      return null;
+    }
+
+    int firstEntryOffset = in.readInt();
+
+    K compareKey;
+
+    // there was some thought behind this attribute but I cant seem to recall what..
+    int previousEntryOffset = -1;
+
+    int nextEntryOffset = firstEntryOffset;
+    while (nextEntryOffset != -1) {
+      int entryOffset = nextEntryOffset;
+
+      accessor.getEntriesRAF().seek(entryOffset);
+      previousEntryOffset = entryOffset;
+
+      nextEntryOffset = accessor.getEntriesRAF().readInt();
+      int partitionNumber = accessor.getEntriesRAF().readInt();
+
+      if (partitionNumber == -1) {
+        return null;
+      }
+
+      int partitionOffset = accessor.getEntriesRAF().readInt();
+      int keySize = accessor.getEntriesRAF().readInt();
+      if (keySize > 0) {
+        byte[] compareKeyBuf = new byte[keySize];
+        accessor.getEntriesRAF().read(compareKeyBuf);
+        compareKey = keyClassHandler.read(new DataInputStream(new ByteArrayInputStream(compareKeyBuf)));
+        if (key.equals(compareKey)) {
+
+          V v;
+
+          Partition partition = partitions.get(partitionNumber);
+          v = partition.read(accessor, partitionOffset);
+
+          return v;
+        }
+      }
+    }
+
+    return null;
+  }
+
+  public V remove(HashtableAccessor accessor, K key) throws IOException {
+    // write key to buf
+    ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+    keyClassHandler.write(key, new DataOutputStream(baos));
+    byte[] keyBuf = baos.toByteArray();
+
+
+    int keyHash = key.hashCode();
+    int index = keyHash & (hashtableSize - 1);
+    byte[] hashtableRecordBuf = new byte[HASHTABLE_RECORD_BYTE_SIZE];
+    accessor.getHashtableRAF().seek(index * HASHTABLE_RECORD_BYTE_SIZE);
+    accessor.getHashtableRAF().read(hashtableRecordBuf);
+    DataInput in = new DataInputStream(new ByteArrayInputStream(hashtableRecordBuf));
+
+    byte isnull = in.readByte();
+
+    int firstEntryOffset = in.readInt();
+
+    K compareKey;
+
+    int previousEntryOffset = -1;
+    int nextEntryOffset = firstEntryOffset;
+    while (nextEntryOffset != -1) {
+      int entryOffset = nextEntryOffset;
+
+      accessor.getEntriesRAF().seek(entryOffset);
+
+      nextEntryOffset = accessor.getEntriesRAF().readInt();
+      int partitionNumber = accessor.getEntriesRAF().readInt();
+      int partitionOffset = accessor.getEntriesRAF().readInt();
+      int keySize = accessor.getEntriesRAF().readInt();
+      if (keySize > 0) {
+        byte[] compareKeyBuf = new byte[keySize];
+        accessor.getEntriesRAF().read(compareKeyBuf);
+        compareKey = keyClassHandler.read(new DataInputStream(new ByteArrayInputStream(compareKeyBuf)));
+        if (key.equals(compareKey)) {
+
+          V oldValue = null;
+
+
+          if (partitionNumber != -1) {
+            // read old value
+            Partition partition = partitions.get(partitionNumber);
+            oldValue = partition.read(accessor, partitionOffset);
+          }
+
+          if (previousEntryOffset != -1) {
+            // update offset in previous entry to point at next offset in removed entry
+            accessor.getEntriesRAF().seek(previousEntryOffset);
+            accessor.getEntriesRAF().writeInt(nextEntryOffset);
+          } else {
+            // remove posting in hashtable
+            accessor.getHashtableRAF().seek(index * HASHTABLE_RECORD_BYTE_SIZE);
+            accessor.getHashtableRAF().writeByte(0);
+          }
+
+          accessor.getEntriesRAF().seek(4);
+          accessor.getEntriesRAF().writeInt(--entryCount);
+
+          return oldValue;
+        }
+      }
+
+      previousEntryOffset = entryOffset;
+
+    }
+
+    throw new RuntimeException("Expected to find the value in data file!");
+  }
+
+
+  public class Partition {
+
+    private int partitionNumber;
+    private File file;
+
+    private long nextPosition = -1;
+    private long bytesLeft = -1;
+
+    private Partition() {
+      this(partitions.size());
+    }
+
+    private Partition(int partitionNumber) {
+      this.partitionNumber = partitionNumber;
+      file = new File(path, "data." + partitionNumber);
+      while (partitions.size() < partitionNumber) {
+        log.warn("Adding a null partition");
+        partitions.add(null);
+      }
+      partitions.add(partitionNumber, this);
+    }
+
+    public long append(HashtableAccessor accessor, byte[] bytes) throws IOException {
+      return append(accessor, bytes, bytes.length);
+    }
+
+    public long append(HashtableAccessor accessor, byte[] bytes, int length) throws IOException {
+
+      RandomAccessFile raf = accessor.getPartitionRAF(this);
+
+      long offset = nextPosition;
+      nextPosition += 4 + length;
+
+      raf.seek(0);
+      raf.writeLong(nextPosition);
+      raf.writeLong(bytesLeft);
+
+      raf.seek(offset);
+      raf.writeInt(length);
+      raf.write(bytes);
+
+      return offset;
+    }
+
+    public V read(HashtableAccessor accessor, long offset) throws IOException {
+
+      RandomAccessFile raf = accessor.getPartitionRAF(this);
+
+      raf.seek(offset);
+      int length = raf.readInt();
+      if (length > 0) {
+        byte[] buf = new byte[length];
+        raf.read(buf);
+        return valueClassHandler.read(new DataInputStream(new ByteArrayInputStream(buf)));
+      }
+      return null;
+    }
+
+    public void format(long sizeInBytes) throws IOException {
+      Hashtable.this.format(file, sizeInBytes);
+      nextPosition = 1024; // save 1K for partition header
+      bytesLeft = sizeInBytes;
+
+      RandomAccessFile raf = new RandomAccessFile(file, "rw");
+      raf.seek(0);
+      raf.writeLong(nextPosition);
+      raf.writeLong(bytesLeft);
+      raf.close();
+    }
+
+    public void open() throws IOException {
+
+      RandomAccessFile raf = new RandomAccessFile(file, "r");
+      raf.seek(0);
+      nextPosition = raf.readLong();
+      bytesLeft = raf.readLong();
+      raf.close();
+    }
+
+    public File getFile() {
+      return file;
+    }
+  }
+
+
+  public void format(File file, long size) throws IOException {
+
+    log.info("Formatting " + file.getAbsolutePath());
+
+    long ms = System.currentTimeMillis();
+
+    long leftToWrite = size;
+
+    FileOutputStream fos = new FileOutputStream(file);
+    byte[] bytes = new byte[32 * 1024];
+    while (leftToWrite > bytes.length) {
+      fos.write(bytes);
+      leftToWrite -= bytes.length;
+    }
+    fos.write(bytes, 0, (int) leftToWrite);
+    fos.close();
+
+    log.info("It took " + (System.currentTimeMillis() - ms) + " milliseconds to format " + file.getAbsolutePath());
+
+  }
+
+
+  public int size() {
+    return entryCount;
+  }
+
+
+  public Iterator<K> keys(final HashtableAccessor accessor) {
+    return new Iterator<K>() {
+
+      private Cursor cursor = new Cursor(accessor);
+
+      private K bufferedKey;
+      private K currentKey;
+
+      public boolean hasNext() {
+        if (bufferedKey != null) {
+          return true;
+        }
+        try {
+          if (cursor.next()) {
+            bufferedKey = cursor.key;
+            return true;
+          }
+        } catch (IOException ioe) {
+          throw new RuntimeException(ioe);
+        }
+        return false;
+      }
+
+      public K next() {
+        if (bufferedKey != null) {
+          currentKey = bufferedKey;
+          bufferedKey = null;
+        }
+        return currentKey;
+      }
+
+      public void remove() {
+        try {
+          Hashtable.this.remove(accessor, currentKey);
+        } catch (IOException ioe) {
+          throw new RuntimeException(ioe);
+        }
+      }
+    };
+  }
+
+  public Iterator<V> values(final HashtableAccessor accessor) {
+    return new Iterator<V>() {
+
+      private Cursor cursor = new Cursor(accessor);
+
+      boolean buffered = false;
+      private K k;
+      private V v;
+
+      public boolean hasNext() {
+        if (buffered) {
+          return true;
+        }
+        try {
+          buffered = cursor.next();
+          k = cursor.key();
+          v = cursor.value();
+        } catch (IOException ioe) {
+          throw new RuntimeException(ioe);
+        }
+        return buffered;
+      }
+
+      public V next() {
+        return v;
+      }
+
+      public void remove() {
+        try {
+          Hashtable.this.remove(accessor, k);
+        } catch (IOException ioe) {
+          throw new RuntimeException(ioe);
+        }
+      }
+    };
+  }
+
+  public class Cursor {
+
+    private HashtableAccessor accessor;
+
+    public Cursor(HashtableAccessor accessor) {
+      this.accessor = accessor;
+    }
+
+    private long hashtableCursor = 0;
+    private long entryCursor = -1;
+
+    private K key;
+    private V value;
+
+    public boolean next() throws IOException {
+      if (entryCursor != -1) {
+        accessor.getEntriesRAF().seek(entryCursor);
+        entryCursor = accessor.getEntriesRAF().readInt(); // next entry
+        if (entryCursor != -1) {
+          accessor.getEntriesRAF().seek(entryCursor + 4);
+          set();
+          return true;
+        }
+      }
+      while (hashtableCursor < (hashtableSize * HASHTABLE_RECORD_BYTE_SIZE)) {
+        accessor.getHashtableRAF().seek(hashtableCursor);
+        hashtableCursor += HASHTABLE_RECORD_BYTE_SIZE;
+        byte isnull = accessor.getHashtableRAF().readByte();
+        if (isnull != 0) {
+          entryCursor = accessor.getHashtableRAF().readInt();
+          accessor.getEntriesRAF().seek(entryCursor + 4);
+          set();
+
+          return true;
+        }
+      }
+
+      return false;
+    }
+
+    private void set() throws IOException {
+      int partitionNumber = accessor.getEntriesRAF().readInt();
+      int partitionOffset = accessor.getEntriesRAF().readInt();
+      byte[] keyBuf = new byte[accessor.getEntriesRAF().readInt()];
+      accessor.getEntriesRAF().read(keyBuf);
+      K key;
+      key = keyClassHandler.read(new DataInputStream(new ByteArrayInputStream(keyBuf)));
+      this.key = key;
+
+      V value;
+      value = partitions.get(partitionNumber).read(accessor, partitionOffset);
+      this.value = value;
+    }
+
+    public K key() {
+      // todo lazy load key
+      return key;
+    }
+
+    public V value() {
+      // todo lazy load value
+      return value;
+    }
+  }
+
+  public void optimize() throws IOException {
+    // todo
+  }
+
+  public KeyClassHandler<K> getKeyClassHandler() {
+    return keyClassHandler;
+  }
+
+  public EntityClassHandler<V> getValueClassHandler() {
+    return valueClassHandler;
+  }
+
+  public File getPath() {
+    return path;
+  }
+
+  public File getHashtableFile() {
+    return hashtableFile;
+  }
+
+  public File getEntriesFile() {
+    return entriesFile;
+  }
+
+  List<Partition> getPartitions() {
+    return partitions;
+  }
+
+}
+
+

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/HashtableAccessor.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/HashtableAccessor.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/HashtableAccessor.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/HashtableAccessor.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,80 @@
+package org.apache.labs.bananadb.hashtable;
+
+/*
+ * 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.
+ */
+
+
+import java.io.RandomAccessFile;
+import java.io.IOException;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * User: kalle
+ * Date: 2009-jan-03
+ * Time: 04:37:42
+ */
+public class HashtableAccessor {
+
+  private String access;
+  private RandomAccessFile hashtableRAF;
+  private RandomAccessFile entriesRAF;
+  private Map<Hashtable.Partition, RandomAccessFile> partitionRAFs = new HashMap<Hashtable.Partition, RandomAccessFile>();
+
+  public HashtableAccessor(Hashtable<?, ?> hashtable, boolean readOnly) throws IOException {
+    // todo open hashtableRAF, entriesRAF and all partitionRAFs
+
+    access = readOnly ? "r" : "rw";
+
+    hashtableRAF = new RandomAccessFile(hashtable.getHashtableFile(), access);
+    entriesRAF = new RandomAccessFile(hashtable.getEntriesFile(), access);
+
+    for (Hashtable.Partition partition : hashtable.getPartitions()) {
+      registerPartition(partition);
+    }
+  }
+
+  void registerPartition(Hashtable.Partition partition) throws IOException {
+    partitionRAFs.put(partition,  new RandomAccessFile(partition.getFile(), access));
+  }
+
+  RandomAccessFile getHashtableRAF() {
+    return hashtableRAF;
+  }
+
+  RandomAccessFile getEntriesRAF() {
+    return entriesRAF;
+  }
+
+  RandomAccessFile getPartitionRAF(Hashtable.Partition partition) {
+    RandomAccessFile partitionRAF = partitionRAFs.get(partition);
+    if (partitionRAF == null) {
+      // todo perhaps it was created by some other accessor? need to handle this
+      // todo but preferably without synchronizing the whole method!
+      throw new RuntimeException("Unknown partion!");
+    }
+    return partitionRAF;
+  }
+
+  public void close() throws IOException {
+    getHashtableRAF().close();
+    getEntriesRAF().close();
+    for (RandomAccessFile partitionRAF : partitionRAFs.values()) {
+      partitionRAF.close();
+    }
+  }
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/KeyClassHandler.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/KeyClassHandler.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/KeyClassHandler.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/KeyClassHandler.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,31 @@
+package org.apache.labs.bananadb.hashtable;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * User: kalle
+ * Date: 2009-jan-03
+ * Time: 04:18:04
+ */
+public interface KeyClassHandler<C> extends EntityClassHandler<C> {
+
+  /** A primary key needs to be of a static size for fast seeking in the hash table */
+  public int getByteSize();
+  
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/BooleanHandler.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/BooleanHandler.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/BooleanHandler.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/BooleanHandler.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,48 @@
+package org.apache.labs.bananadb.hashtable.handlers;
+
+import org.apache.labs.bananadb.hashtable.KeyClassHandler;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.DataInputStream;
+
+/*
+ * 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.
+ */
+
+/**
+ * User: kalle
+ * Date: 2009-jan-04
+ * Time: 01:03:30
+ */
+public class BooleanHandler implements KeyClassHandler<Boolean> {
+
+  public int getByteSize() {
+    return 1;
+  }
+
+  public Class<Boolean> getEntityClass() {
+    return Boolean.class;
+  }
+
+  public void write(Boolean entity, DataOutputStream out) throws IOException {
+    out.writeBoolean(entity);
+  }
+
+  public Boolean read(DataInputStream in) throws IOException {
+    return in.readBoolean();
+  }
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/ByteHandler.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/ByteHandler.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/ByteHandler.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/ByteHandler.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,48 @@
+package org.apache.labs.bananadb.hashtable.handlers;
+
+import org.apache.labs.bananadb.hashtable.KeyClassHandler;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.DataInputStream;
+
+/*
+ * 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.
+ */
+
+/**
+ * User: kalle
+ * Date: 2009-jan-04
+ * Time: 01:00:54
+ */
+public class ByteHandler implements KeyClassHandler<Byte> {
+
+  public int getByteSize() {
+    return 1;
+  }
+
+  public Class<Byte> getEntityClass() {
+    return Byte.class;
+  }
+
+  public void write(Byte entity, DataOutputStream out) throws IOException {
+    out.writeByte(entity);
+  }
+
+  public Byte read(DataInputStream in) throws IOException {
+    return in.readByte();
+  }
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/CharHandler.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/CharHandler.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/CharHandler.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/CharHandler.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,48 @@
+package org.apache.labs.bananadb.hashtable.handlers;
+
+import org.apache.labs.bananadb.hashtable.KeyClassHandler;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.DataInputStream;
+
+/*
+ * 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.
+ */
+
+/**
+ * User: kalle
+ * Date: 2009-jan-04
+ * Time: 01:03:44
+ */
+public class CharHandler implements KeyClassHandler<Character> {
+
+  public int getByteSize() {
+    return 2;
+  }
+
+  public Class<Character> getEntityClass() {
+    return Character.class;
+  }
+
+  public void write(Character entity, DataOutputStream out) throws IOException {
+    out.writeChar(entity);
+  }
+
+  public Character read(DataInputStream in) throws IOException {
+    return in.readChar();
+  }
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/DoubleHandler.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/DoubleHandler.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/DoubleHandler.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/DoubleHandler.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,47 @@
+package org.apache.labs.bananadb.hashtable.handlers;
+
+import org.apache.labs.bananadb.hashtable.KeyClassHandler;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.DataInputStream;
+
+/*
+ * 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.
+ */
+
+/**
+ * User: kalle
+ * Date: 2009-jan-04
+ * Time: 01:02:59
+ */
+public class DoubleHandler implements KeyClassHandler<Double> {
+  public int getByteSize() {
+    return 8;
+  }
+
+  public Class<Double> getEntityClass() {
+    return Double.class;
+  }
+
+  public void write(Double entity, DataOutputStream out) throws IOException {
+    out.writeDouble(entity);
+  }
+
+  public Double read(DataInputStream in) throws IOException {
+    return in.readDouble();
+  }
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/FloatHandler.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/FloatHandler.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/FloatHandler.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/FloatHandler.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,48 @@
+package org.apache.labs.bananadb.hashtable.handlers;
+
+import org.apache.labs.bananadb.hashtable.KeyClassHandler;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.DataInputStream;
+
+/*
+ * 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.
+ */
+
+/**
+ * User: kalle
+ * Date: 2009-jan-04
+ * Time: 01:02:50
+ */
+public class FloatHandler implements KeyClassHandler<Float> {
+
+  public int getByteSize() {
+    return 4;
+  }
+
+  public Class<Float> getEntityClass() {
+    return Float.class;
+  }
+
+  public void write(Float entity, DataOutputStream out) throws IOException {
+    out.writeFloat(entity);
+  }
+
+  public Float read(DataInputStream in) throws IOException {
+    return in.readFloat();
+  }
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/IntegerHandler.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/IntegerHandler.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/IntegerHandler.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/IntegerHandler.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,49 @@
+package org.apache.labs.bananadb.hashtable.handlers;
+
+/*
+ * 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.
+ */
+
+
+import org.apache.labs.bananadb.hashtable.KeyClassHandler;
+
+import java.io.DataOutputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+
+/**
+ * User: kalle
+ * Date: 2009-jan-03
+ * Time: 05:48:40
+ */
+public class IntegerHandler implements KeyClassHandler<Integer> {
+
+  public int getByteSize() {
+    return 4;
+  }
+
+  public Class<Integer> getEntityClass() {
+    return Integer.class;
+  }
+
+  public void write(Integer entity, DataOutputStream out) throws IOException {
+    out.writeInt(entity);
+  }
+
+  public Integer read(DataInputStream in) throws IOException {
+    return in.readInt();
+  }
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/LongHandler.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/LongHandler.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/LongHandler.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/LongHandler.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,48 @@
+package org.apache.labs.bananadb.hashtable.handlers;
+
+import org.apache.labs.bananadb.hashtable.KeyClassHandler;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.DataInputStream;
+
+/*
+ * 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.
+ */
+
+/**
+ * User: kalle
+ * Date: 2009-jan-04
+ * Time: 01:01:55
+ */
+public class LongHandler implements KeyClassHandler<Long> {
+
+  public int getByteSize() {
+    return 8;
+  }
+
+  public Class<Long> getEntityClass() {
+    return Long.class;
+  }
+
+  public void write(Long entity, DataOutputStream out) throws IOException {
+    out.writeLong(entity);
+  }
+
+  public Long read(DataInputStream in) throws IOException {
+    return in.readLong();
+  }
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/ShortHandler.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/ShortHandler.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/ShortHandler.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/ShortHandler.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,48 @@
+package org.apache.labs.bananadb.hashtable.handlers;
+
+import org.apache.labs.bananadb.hashtable.KeyClassHandler;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.DataInputStream;
+
+/*
+ * 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.
+ */
+
+/**
+ * User: kalle
+ * Date: 2009-jan-04
+ * Time: 00:59:49
+ */
+public class ShortHandler implements KeyClassHandler<Short> {
+
+  public int getByteSize() {
+    return 2;
+  }
+
+  public Class<Short> getEntityClass() {
+    return Short.class;
+  }
+
+  public void write(Short entity, DataOutputStream out) throws IOException {
+    out.writeShort(entity);
+  }
+
+  public Short read(DataInputStream in) throws IOException {
+    return in.readShort();
+  }
+}

Added: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/StringValueHandler.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/StringValueHandler.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/StringValueHandler.java (added)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/handlers/StringValueHandler.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,45 @@
+package org.apache.labs.bananadb.hashtable.handlers;
+
+/*
+ * 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.
+ */
+
+import org.apache.labs.bananadb.hashtable.EntityClassHandler;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.DataInputStream;
+
+/**
+ * User: kalle
+ * Date: 2009-jan-03
+ * Time: 05:52:33
+ */
+public class StringValueHandler implements EntityClassHandler<String> {
+
+  public Class<String> getEntityClass() {
+    return String.class;
+  }
+
+  public void write(String entity, DataOutputStream out) throws IOException {
+    out.writeUTF(entity);
+  }
+
+  public String read(DataInputStream in) throws IOException {
+    return in.readUTF();
+  }
+  
+}

Added: labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/City.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/City.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/City.java (added)
+++ labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/City.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,39 @@
+package org.apache.labs.bananadb.demo;
+
+/*
+ * 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.
+ */
+
+
+import org.apache.labs.bananadb.PrimaryKey;
+import org.apache.labs.bananadb.SecondaryKey;
+
+/**
+ * User: kalle
+ * Date: 2008-jul-23
+ * Time: 02:46:11
+ */
+public class City {
+
+    @PrimaryKey
+    private long primaryKey;
+
+    @SecondaryKey(otherEndClass=Country.class)
+    private String countryISO;
+    
+    private String name;
+
+}

Added: labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/Country.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/Country.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/Country.java (added)
+++ labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/Country.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,34 @@
+package org.apache.labs.bananadb.demo;
+
+/*
+ * 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.
+ */
+
+
+import org.apache.labs.bananadb.PrimaryKey;
+
+/**
+ * User: kalle
+ * Date: 2008-jul-23
+ * Time: 02:46:04
+ */
+public class Country {
+
+    @PrimaryKey
+    private String iso;
+    private String name;
+
+}

Added: labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/EntityStore.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/EntityStore.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/EntityStore.java (added)
+++ labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/demo/EntityStore.java Tue Jan  6 12:25:58 2009
@@ -0,0 +1,42 @@
+package org.apache.labs.bananadb.demo;
+
+/*
+ * 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.
+ */
+
+
+import org.apache.labs.bananadb.PrimaryIndex;
+import org.apache.labs.bananadb.SecondaryIndex;
+
+/**
+ * User: kalle
+ * Date: 2008-jul-23
+ * Time: 02:51:09
+ */
+public class EntityStore extends org.apache.labs.bananadb.EntityStore {
+
+    private PrimaryIndex<String, Country> countries;
+    private PrimaryIndex<Long, City> cities;
+    private SecondaryIndex<Long, String, City> citiesByCountry;
+
+    public EntityStore() {
+
+        countries = getPrimaryIndex(String.class, Country.class);
+        cities = getPrimaryIndex(Long.class, City.class);
+        citiesByCountry = getSecondaryIndex(cities, String.class, "countryISO");
+
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org