Skip to content
Browse files

Initial spike of a JNI library to access LevelDB. The basics get/put/…

…delete are working.
  • Loading branch information...
0 parents commit 3baf54199f413f78ee7c124d478c7bceaa91093e @chirino chirino committed Jul 31, 2011
13 .gitignore
@@ -0,0 +1,13 @@
+*~
+*.swp
+.idea
+.idea/*
+*.iml
+*.ipr
+*.iws
+target
+.DS_Store
+.project
+.classpath
+.settings
+eclipse-classes
241 license.txt
@@ -0,0 +1,241 @@
+ COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL)
+ Version 1.0
+
+
+1. Definitions.
+
+ 1.1. “Contributor” means each individual or entity that creates or contributes to the creation of Modifications.
+
+ 1.2. “Contributor Version” means the combination of the Original Software, prior Modifications used by a Contributor
+ (if any), and the Modifications made by that particular Contributor.
+
+ 1.3. “Covered Software” means (a) the Original Software, or (b) Modifications, or (c) the combination
+ of files containing Original Software with files containing Modifications, in each case including portions thereof.
+
+ 1.4. “Executable” means the Covered Software in any form other than Source Code.
+
+ 1.5. “Initial Developer” means the individual or entity that first makes Original Software available under this License.
+
+ 1.6. “Larger Work” means a work which combines Covered Software or portions thereof with code not governed by the terms
+ of this License.
+
+ 1.7. “License” means this document.
+
+ 1.8. “Licensable” means having the right to grant, to the maximum extent possible, whether at the time of the
+ initial grant or subsequently acquired, any and all of the rights conveyed herein.
+
+ 1.9. “Modifications” means the Source Code and Executable form of any of the following:
+ A. Any file that results from an addition to, deletion from or modification of the contents of a file
+ containing Original Software or previous Modifications;
+ B. Any new file that contains any part of the Original Software or previous Modification; or
+ C. Any new file that is contributed or otherwise made available under the terms of this License.
+
+ 1.10. “Original Software” means the Source Code and Executable form of computer software code that is originally
+ released under this License.
+
+ 1.11. “Patent Claims” means any patent claim(s), now owned or hereafter acquired, including without limitation,
+ method, process, and apparatus claims, in any patent Licensable by grantor.
+
+ 1.12. “Source Code” means (a) the common form of computer software code in which modifications are made and
+ (b) associated documentation included in or with such code.
+
+ 1.13. “You” (or “Your”) means an individual or a legal entity exercising rights under, and complying with all of
+ the terms of, this License. For legal entities, “You” includes any entity which controls, is controlled by, or is
+ under common control with You. For purposes of this definition, “control” means (a) the power, direct or indirect,
+ to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more
+ than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
+
+2. License Grants.
+
+ 2.1. The Initial Developer Grant.
+ Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims,
+ the Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license:
+
+ (a) under intellectual property rights (other than patent or trademark) Licensable by Initial Developer,
+ to use, reproduce, modify, display, perform, sublicense and distribute the Original Software (or portions
+ thereof), with or without Modifications, and/or as part of a Larger Work; and
+
+ (b) under Patent Claims infringed by the making, using or selling of Original Software, to make, have made,
+ use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Software (or portions thereof).
+
+ (c) The licenses granted in Sections 2.1(a) and (b) are effective on the date Initial Developer first
+ distributes or otherwise makes the Original Software available to a third party under the terms of this License.
+
+ (d) Notwithstanding Section 2.1(b) above, no patent license is granted: (1) for code that You delete from
+ the Original Software, or (2) for infringements caused by: (i) the modification of the Original Software,
+ or (ii) the combination of the Original Software with other software or devices.
+
+ 2.2. Contributor Grant.
+ Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims,
+ each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license:
+
+ (a) under intellectual property rights (other than patent or trademark) Licensable by Contributor to use,
+ reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor
+ (or portions thereof), either on an unmodified basis, with other Modifications, as Covered Software and/or
+ as part of a Larger Work; and
+
+ (b) under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor
+ either alone and/or in combination with its Contributor Version (or portions of such combination), to make,
+ use, sell, offer for sale, have made, and/or otherwise dispose of: (1) Modifications made by that Contributor
+ (or portions thereof); and (2) the combination of Modifications made by that Contributor with its Contributor
+ Version (or portions of such combination).
+
+ (c) The licenses granted in Sections 2.2(a) and 2.2(b) are effective on the date Contributor first distributes
+ or otherwise makes the Modifications available to a third party.
+
+ (d) Notwithstanding Section 2.2(b) above, no patent license is granted: (1) for any code that Contributor has
+ deleted from the Contributor Version; (2) for infringements caused by: (i) third party modifications of
+ Contributor Version, or (ii) the combination of Modifications made by that Contributor with other software
+ (except as part of the Contributor Version) or other devices; or (3) under Patent Claims infringed by Covered
+ Software in the absence of Modifications made by that Contributor.
+
+3. Distribution Obligations.
+
+ 3.1. Availability of Source Code.
+ Any Covered Software that You distribute or otherwise make available in Executable form must also be made available
+ in Source Code form and that Source Code form must be distributed only under the terms of this License. You must
+ include a copy of this License with every copy of the Source Code form of the Covered Software You distribute or
+ otherwise make available. You must inform recipients of any such Covered Software in Executable form as to how they
+ can obtain such Covered Software in Source Code form in a reasonable manner on or through a medium customarily used
+ for software exchange.
+
+ 3.2. Modifications.
+ The Modifications that You create or to which You contribute are governed by the terms of this License. You
+ represent that You believe Your Modifications are Your original creation(s) and/or You have sufficient rights to
+ grant the rights conveyed by this License.
+
+ 3.3. Required Notices.
+ You must include a notice in each of Your Modifications that identifies You as the Contributor of the Modification.
+ You may not remove or alter any copyright, patent or trademark notices contained within the Covered Software, or
+ any notices of licensing or any descriptive text giving attribution to any Contributor or the Initial Developer.
+
+ 3.4. Application of Additional Terms.
+ You may not offer or impose any terms on any Covered Software in Source Code form that alters or restricts the
+ applicable version of this License or the recipients’ rights hereunder. You may choose to offer, and to charge a
+ fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software.
+ However, you may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor.
+ You must make it absolutely clear that any such warranty, support, indemnity or liability obligation is offered
+ by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability
+ incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability
+ terms You offer.
+
+ 3.5. Distribution of Executable Versions.
+ You may distribute the Executable form of the Covered Software under the terms of this License or under the terms
+ of a license of Your choice, which may contain terms different from this License, provided that You are in compliance
+ with the terms of this License and that the license for the Executable form does not attempt to limit or alter
+ the recipient’s rights in the Source Code form from the rights set forth in this License. If You distribute the
+ Covered Software in Executable form under a different license, You must make it absolutely clear that any terms
+ which differ from this License are offered by You alone, not by the Initial Developer or Contributor. You hereby
+ agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer
+ or such Contributor as a result of any such terms You offer.
+
+ 3.6. Larger Works.
+ You may create a Larger Work by combining Covered Software with other code not governed by the terms of this License
+ and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this
+ License are fulfilled for the Covered Software.
+
+4. Versions of the License.
+
+ 4.1. New Versions.
+ Sun Microsystems, Inc. is the initial license steward and may publish revised and/or new versions of this License
+ from time to time. Each version will be given a distinguishing version number. Except as provided in Section 4.3,
+ no one other than the license steward has the right to modify this License.
+
+ 4.2. Effect of New Versions.
+ You may always continue to use, distribute or otherwise make the Covered Software available under the terms of
+ the version of the License under which You originally received the Covered Software. If the Initial Developer
+ includes a notice in the Original Software prohibiting it from being distributed or otherwise made available under
+ any subsequent version of the License, You must distribute and make the Covered Software available under the terms
+ of the version of the License under which You originally received the Covered Software. Otherwise, You may also
+ choose to use, distribute or otherwise make the Covered Software available under the terms of any subsequent version
+ of the License published by the license steward.
+
+ 4.3. Modified Versions.
+ When You are an Initial Developer and You want to create a new license for Your Original Software, You may create
+ and use a modified version of this License if You: (a) rename the license and remove any references to the name of
+ the license steward (except to note that the license differs from this License); and (b) otherwise make it clear that
+ the license contains terms which differ from this License.
+
+5. DISCLAIMER OF WARRANTY.
+
+COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN “AS IS” BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR
+IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A
+PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU.
+SHOULD ANY COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
+COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
+
+6. TERMINATION.
+
+ 6.1. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms
+ herein and fail to cure such breach within 30 days of becoming aware of the breach. Provisions which, by their
+ nature, must remain in effect beyond the termination of this License shall survive.
+
+ 6.2. If You assert a patent infringement claim (excluding declaratory judgment actions) against Initial Developer
+ or a Contributor (the Initial Developer or Contributor against whom You assert such claim is referred to as
+ “Participant”) alleging that the Participant Software (meaning the Contributor Version where the Participant
+ is a Contributor or the Original Software where the Participant is the Initial Developer) directly or
+ indirectly infringes any patent, then any and all rights granted directly or indirectly to You by such Participant,
+ the Initial Developer (if the Initial Developer is not the Participant) and all Contributors under Sections 2.1
+ and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively and automatically
+ at the expiration of such 60 day notice period, unless if within such 60 day period You withdraw Your claim with
+ respect to the Participant Software against such Participant either unilaterally or pursuant to a written agreement
+ with Participant.
+
+ 6.3. If You assert a patent infringement claim against Participant alleging that the Participant Software directly
+ or indirectly infringes any patent where such claim is resolved (such as by license or settlement) prior to the
+ initiation of patent infringement litigation, then the reasonable value of the licenses granted by such Participant
+ under Sections 2.1 or 2.2 shall be taken into account in determining the amount or value of any payment or license.
+
+ 6.4. In the event of termination under Sections 6.1 or 6.2 above, all end user licenses that have been validly granted
+ by You or any distributor hereunder prior to termination (excluding licenses granted to You by any distributor)
+ shall survive termination.
+
+7. LIMITATION OF LIABILITY.
+
+UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE
+INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR
+LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY
+SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL
+INJURY RESULTING FROM SUCH PARTY’S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
+EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
+
+8. U.S. GOVERNMENT END USERS.
+
+The Covered Software is a “commercial item,” as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of
+“commercial computer software” (as that term is defined at 48 C.F.R. § 252.227-7014(a)(1)) and “commercial computer software documentation”
+as such terms are used in 48 C.F.R. 12.212 Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
+all U.S. Government End Users acquire Covered Software with only those rights set forth herein. This U.S. Government Rights clause is in lieu of,
+and supersedes, any other FAR, DFAR, or other clause or provision that addresses Government rights in computer software under this License.
+
+9. MISCELLANEOUS.
+
+This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed
+by the law of the jurisdiction specified in a notice contained within the Original Software (except to the extent applicable law, if any,
+provides otherwise), excluding such jurisdiction’s conflict-of-law provisions. Any litigation relating to this License shall be subject
+to the jurisdiction of the courts located in the jurisdiction and venue specified in a notice contained within the Original Software, with the
+losing party responsible for costs, including, without limitation, court costs and reasonable attorneys’ fees and expenses. The application of
+the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that
+the language of a contract shall be construed against the drafter shall not apply to this License. You agree that You alone are responsible for
+compliance with the United States export administration regulations (and the export control laws and regulation of any other countries) when You use,
+distribute or otherwise make available any Covered Software.
+
+10. RESPONSIBILITY FOR CLAIMS.
+
+As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of
+its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on
+an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability.
+
+--------
+
+NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION
+LICENSE (CDDL)
+
+The OpenSolaris code released under the CDDL shall be governed by the laws
+of the State of California (excluding conflict-of-law provisions). Any
+litigation relating to this License shall be subject to the jurisdiction of
+the Federal Courts of the Northern District of California and the state
+courts of the State of California, with venue lying in Santa Clara County,
+California.
308 pom.xml
@@ -0,0 +1,308 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (C) 2011, FuseSource Corp. All rights reserved.
+
+ http://fusesource.com
+
+ The software in this package is published under the terms of the
+ CDDL license a copy of which has been included with this distribution
+ in the license.txt file.
+-->
+<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>
+ <parent>
+ <groupId>org.fusesource</groupId>
+ <artifactId>fusesource-pom</artifactId>
+ <version>1.7</version>
+ </parent>
+
+ <groupId>org.fusesource.leveldbjni</groupId>
+ <artifactId>leveldbjni</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <name>${project.artifactId}</name>
+ <description>leveldbjni is a jni library for acessing leveldb.</description>
+
+ <properties>
+ <forge-project-id>leveldbjni</forge-project-id>
+ <forge-project-id-uc>LEVELDBJNI</forge-project-id-uc>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <hawtjni-version>1.3-SNAPSHOT</hawtjni-version>
+ </properties>
+
+ <url>http://${forge-project-id}.fusesource.org</url>
+ <inceptionYear>2009</inceptionYear>
+
+ <issueManagement>
+ <system>github</system>
+ <url>https://github.com/fusesource/leveldbjni/issues</url>
+ </issueManagement>
+
+ <mailingLists>
+ <mailingList>
+ <name>${forge-project-id} dev</name>
+ <post>${forge-project-id}-dev@fusesource.org</post>
+ <subscribe>${forge-project-id}-dev-subscribe@fusesource.org</subscribe>
+ </mailingList>
+ <mailingList>
+ <name>${forge-project-id} commits</name>
+ <post>${forge-project-id}-commits@fusesource.org</post>
+ <subscribe>${forge-project-id}-commits-subscribe@fusesource.org</subscribe>
+ </mailingList>
+ </mailingLists>
+
+ <licenses>
+ <license>
+ <name>Common Development and Distribution License (CDDL)</name>
+ <url>http://www.opensource.org/licenses/cddl1</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <scm>
+ <connection>scm:git:git://github.com/fusesource/leveldbjni.git</connection>
+ <developerConnection>scm:git:git@github.com:fusesource/leveldbjni.git</developerConnection>
+ <url>https://github.com/fusesource/leveldbjni</url>
+ </scm>
+
+ <distributionManagement>
+ <site>
+ <id>website.fusesource.org</id>
+ <name>website</name>
+ <url>dav:http://fusesource.com/forge/dav/${forge-project-id}/maven/${project.version}</url>
+ </site>
+ </distributionManagement>
+
+ <developers>
+ <developer>
+ <id>chirino</id>
+ <name>Hiram Chirino</name>
+ <email>hiram@hiramchirino.com</email>
+ <url>http://hiramchirino.com</url>
+ <timezone>GMT-5</timezone>
+ </developer>
+ </developers>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.fusesource.hawtjni</groupId>
+ <artifactId>hawtjni-runtime</artifactId>
+ <version>${hawtjni-version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.7</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+
+ <!-- the older clean plugin has trouble deleting directories with symlinks in them -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>2.3</version>
+ </plugin>
+
+ <plugin>
+ <groupId>org.fusesource.hawtjni</groupId>
+ <artifactId>maven-hawtjni-plugin</artifactId>
+ <version>${hawtjni-version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate</goal>
+ <goal>build</goal>
+ <goal>package-jar</goal>
+ <goal>package-source</goal>
+ </goals>
+ <configuration>
+ <name>leveldbjni</name>
+ <callbacks>false</callbacks>
+ <copyright><![CDATA[
+/*******************************************************************************
+ * Copyright (C) 2011, FuseSource Corp. All rights reserved.
+ *
+ * http://fusesource.com
+ *
+ * The software in this package is published under the terms of the
+ * CDDL license a copy of which has been included with this distribution
+ * in the license.txt file.
+ *******************************************************************************/
+ ]]></copyright>
+ <configureArgs>
+ <arg>--with-leveldb=${leveldb}</arg>
+ </configureArgs>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.3</version>
+ <configuration>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <forkMode>once</forkMode>
+ <argLine>-ea</argLine>
+ <failIfNoTests>false</failIfNoTests>
+ <workingDirectory>${project.build.directory}</workingDirectory>
+ <excludes>
+ <exclude>**/Abstract*.java</exclude>
+ <exclude>**/Test*.java</exclude>
+ </excludes>
+ <includes>
+ <include>**/*Test.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.0.1</version>
+ <executions>
+ <execution>
+ <id>bundle-manifest</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>manifest</goal>
+ </goals>
+ <configuration>
+ <instructions>
+ <Import-Package>!org.fusesource.leveldbjni*,!org.fusesource.hawtjni*,sun.reflect;resolution:=optional,*</Import-Package>
+ </instructions>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jxr-maven-plugin</artifactId>
+ <version>2.0-beta-1</version>
+ <configuration>
+ <aggregate>true</aggregate>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.6</version>
+ <configuration>
+ <excludePackageNames>*.internal</excludePackageNames>
+ <linksource>true</linksource>
+ <links>
+ <link>http://java.sun.com/j2se/1.5.0/docs/api</link>
+ </links>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>2.1.1</version>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>index</report>
+ <report>sumary</report>
+ <report>plugins</report>
+ <report>dependencies</report>
+ <report>mailing-list</report>
+ <report>issue-tracking</report>
+ <report>license</report>
+ <report>scm</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>surefire-report-maven-plugin</artifactId>
+ <version>2.0-beta-1</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>2.5</version>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <profiles>
+
+ <!-- Profile which enables Universal binaries on OS X -->
+ <profile>
+ <id>mac</id>
+ <activation>
+ <os><family>mac</family></os>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.fusesource.hawtjni</groupId>
+ <artifactId>maven-hawtjni-plugin</artifactId>
+ <configuration>
+ <osgiPlatforms>
+ <osgiPlatform>osname=MacOS;processor=x86-64</osgiPlatform>
+ <osgiPlatform>osname=MacOS;processor=x86</osgiPlatform>
+ <osgiPlatform>*</osgiPlatform>
+ </osgiPlatforms>
+ <configureArgs>
+ <arg>--with-universal</arg>
+ <arg>--with-leveldb=${leveldb}</arg>
+ </configureArgs>
+ <platform>osx</platform>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+ <id>download</id>
+ <repositories>
+ <repository>
+ <id>fusesource.nexus.snapshot</id>
+ <name>FuseSource Community Snapshot Repository</name>
+ <url>http://repo.fusesource.com/nexus/content/groups/public-snapshots</url>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>fusesource.nexus.snapshot</id>
+ <name>FuseSource Community Snapshot Repository</name>
+ <url>http://repo.fusesource.com/nexus/content/groups/public-snapshots</url>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+
+ </profiles>
+</project>
198 src/main/java/org/fusesource/leveldbjni/DB.java
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2011, FuseSource Corp. All rights reserved.
+ *
+ * http://fusesource.com
+ *
+ * The software in this package is published under the terms of the
+ * CDDL license a copy of which has been included with this distribution
+ * in the license.txt file.
+ */
+package org.fusesource.leveldbjni;
+
+import org.fusesource.hawtjni.runtime.*;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.fusesource.hawtjni.runtime.ArgFlag.*;
+
+/**
+ * JNI Interface to access low level LevelDB functions.
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public class DB extends NativeObject {
+
+ static final Library LIBRARY = new Library("leveldbjni", DB.class);
+
+ @JniClass(name="leveldb::DB", flags={ClassFlag.CPP})
+ private static class DBJNI {
+ static { DB.LIBRARY.load(); }
+
+ @JniMethod(flags={MethodFlag.CPP_DELETE})
+ static final native void delete(
+ @JniArg(cast="leveldb::DB *") long ptr);
+
+ @JniMethod(copy="leveldb::Status", accessor = "leveldb::DB::Open")
+ static final native long Open(
+ @JniArg(cast="leveldb::Options *", flags={ArgFlag.BY_VALUE}) long options,
+ @JniArg(cast="const char*") String path,
+ @JniArg(cast="leveldb::DB**") long[] ptr);
+
+ @JniMethod(copy="leveldb::Status", flags={MethodFlag.CPP})
+ static final native long Put(
+ @JniArg(cast="leveldb::DB *") long ptr,
+ @JniArg(cast="const leveldb::WriteOptions *", flags={ArgFlag.BY_VALUE}) long options,
+ @JniArg(cast="const leveldb::Slice *", flags={ArgFlag.BY_VALUE}) long key,
+ @JniArg(cast="const leveldb::Slice *", flags={ArgFlag.BY_VALUE}) long value
+ );
+
+ @JniMethod(copy="leveldb::Status", flags={MethodFlag.CPP})
+ static final native long Delete(
+ @JniArg(cast="leveldb::DB *") long ptr,
+ @JniArg(cast="const leveldb::WriteOptions *", flags={ArgFlag.BY_VALUE}) long options,
+ @JniArg(cast="const leveldb::Slice *", flags={ArgFlag.BY_VALUE}) long key
+ );
+
+ @JniMethod(copy="leveldb::Status", flags={MethodFlag.CPP})
+ static final native long Write(
+ @JniArg(cast="leveldb::DB *") long ptr,
+ @JniArg(cast="const leveldb::WriteOptions *", flags={ArgFlag.BY_VALUE}) long options,
+ @JniArg(cast="leveldb::WriteBatch *") long updates
+ );
+
+ @JniMethod(copy="leveldb::Status", flags={MethodFlag.CPP})
+ static final native long Get(
+ @JniArg(cast="leveldb::DB *") long ptr,
+ @JniArg(cast="const leveldb::ReadOptions *", flags={ArgFlag.BY_VALUE}) long options,
+ @JniArg(cast="const leveldb::Slice *", flags={ArgFlag.BY_VALUE}) long key,
+ @JniArg(cast="std::string *") long value
+ );
+ }
+
+ @Override
+ public void delete() {
+ assertAllocated();
+ DBJNI.delete(ptr);
+ ptr = 0;
+ }
+
+ private DB(long ptr) {
+ super(ptr);
+ }
+
+ public static class DBException extends IOException {
+ private final boolean notFound;
+
+ DBException(String s, boolean notFound) {
+ super(s);
+ this.notFound = notFound;
+ }
+
+ public boolean isNotFound() {
+ return notFound;
+ }
+ }
+
+ static private void checkStatus(long s) throws DBException {
+ Status status = new Status(s);
+ try {
+ if( !status.isOk() ) {
+ throw new DBException(status.toString(), status.isNotFound());
+ }
+ } finally {
+ status.delete();
+ }
+ }
+
+ public static DB open(Options options, File path) throws IOException, DBException {
+ long rc[] = new long[1];
+ checkStatus(DBJNI.Open(options.pointer(), path.getCanonicalPath(), rc));
+ return new DB(rc[0]);
+ }
+
+ public void put(WriteOptions options, byte[] key, byte[] value) throws DBException {
+ NativeBuffer keyBuffer = new NativeBuffer(key);
+ try {
+ NativeBuffer valueBuffer = new NativeBuffer(value);
+ try {
+ put(options, keyBuffer, valueBuffer);
+ } finally {
+ valueBuffer.delete();
+ }
+ } finally {
+ keyBuffer.delete();
+ }
+ }
+
+ private void put(WriteOptions options, NativeBuffer keyBuffer, NativeBuffer valueBuffer) throws DBException {
+ Slice keySlice = new Slice(keyBuffer);
+ try {
+ Slice valueSlice = new Slice(valueBuffer);
+ try {
+ put(options, keySlice, valueSlice);
+ } finally {
+ valueSlice.delete();
+ }
+ } finally {
+ keySlice.delete();
+ }
+ }
+
+ private void put(WriteOptions options, Slice keySlice, Slice valueSlice) throws DBException {
+ assertAllocated();
+ checkStatus(DBJNI.Put(ptr, options.pointer(), keySlice.pointer(), valueSlice.pointer()));
+ }
+
+ public void delete(WriteOptions options, byte[] key) throws IOException {
+ NativeBuffer keyBuffer = new NativeBuffer(key);
+ try {
+ delete(options, keyBuffer);
+ } finally {
+ keyBuffer.delete();
+ }
+ }
+
+ private void delete(WriteOptions options, NativeBuffer keyBuffer) throws DBException {
+ Slice keySlice = new Slice(keyBuffer);
+ try {
+ delete(options, keySlice);
+ } finally {
+ keySlice.delete();
+ }
+ }
+
+ private void delete(WriteOptions options, Slice keySlice) throws DBException {
+ assertAllocated();
+ checkStatus(DBJNI.Delete(ptr, options.pointer(), keySlice.pointer()));
+ }
+
+ public byte[] get(ReadOptions options, byte[] key) throws DBException {
+ NativeBuffer keyBuffer = new NativeBuffer(key);
+ try {
+ return get(options, keyBuffer);
+ } finally {
+ keyBuffer.delete();
+ }
+ }
+
+ private byte[] get(ReadOptions options, NativeBuffer keyBuffer) throws DBException {
+ Slice keySlice = new Slice(keyBuffer);
+ try {
+ return get(options, keySlice);
+ } finally {
+ keySlice.delete();
+ }
+ }
+
+ private byte[] get(ReadOptions options, Slice keySlice) throws DBException {
+ assertAllocated();
+ StdString result = new StdString();
+ try {
+ checkStatus(DBJNI.Get(ptr, options.pointer(), keySlice.pointer(), result.pointer()));
+ return result.toByteArray();
+ } finally {
+ result.delete();
+ }
+ }
+}
154 src/main/java/org/fusesource/leveldbjni/NativeBuffer.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2011, FuseSource Corp. All rights reserved.
+ *
+ * http://fusesource.com
+ *
+ * The software in this package is published under the terms of the
+ * CDDL license a copy of which has been included with this distribution
+ * in the license.txt file.
+ */
+package org.fusesource.leveldbjni;
+
+import org.fusesource.hawtjni.runtime.*;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.fusesource.hawtjni.runtime.ArgFlag.CRITICAL;
+import static org.fusesource.hawtjni.runtime.ArgFlag.NO_IN;
+import static org.fusesource.hawtjni.runtime.ArgFlag.NO_OUT;
+
+/**
+ */
+public class NativeBuffer extends NativeObject {
+
+ @JniClass
+ static class NativeBufferJNI {
+ static {
+ DB.LIBRARY.load();
+ }
+
+ @JniMethod(cast="void *")
+ public static final native long malloc(
+ @JniArg(cast="size_t") long size);
+
+ public static final native void free(
+ @JniArg(cast="void *") long ptr);
+
+ public static final native void buffer_copy (
+ @JniArg(cast="const void *") long src,
+ @JniArg(cast="size_t") long srcPos,
+ @JniArg(cast="void *") long dest,
+ @JniArg(cast="size_t") long destPos,
+ @JniArg(cast="size_t") long length);
+
+ public static final native void buffer_copy (
+ @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) byte[] src,
+ @JniArg(cast="size_t") long srcPos,
+ @JniArg(cast="void *") long dest,
+ @JniArg(cast="size_t") long destPos,
+ @JniArg(cast="size_t") long length);
+
+ public static final native void buffer_copy (
+ @JniArg(cast="const void *") long src,
+ @JniArg(cast="size_t") long srcPos,
+ @JniArg(cast="void *", flags={NO_IN, CRITICAL}) byte[] dest,
+ @JniArg(cast="size_t") long destPos,
+ @JniArg(cast="size_t") long length);
+
+ @JniMethod(cast="void *")
+ public static final native long memset (
+ @JniArg(cast="void *") long buffer,
+ int c,
+ @JniArg(cast="size_t") long num);
+
+ public static final native int strlen(
+ @JniArg(cast="char *")long s); }
+
+ private final long capacity;
+ private final AtomicInteger retained;
+
+ public NativeBuffer(long capacity) {
+ super(NativeBufferJNI.malloc(capacity));
+ this.capacity = capacity;
+ this.retained = new AtomicInteger(1);
+ }
+
+ public NativeBuffer(byte data[]) {
+ this(data, 0, data.length);
+ }
+
+ public NativeBuffer(byte data[], int offset, int length) {
+ super(NativeBufferJNI.malloc(length));
+ this.capacity = length;
+ this.retained = new AtomicInteger(1);
+ write(0, data, 0, length);
+ }
+
+ private NativeBuffer(NativeBuffer other, long offset, long capacity) {
+ super(PointerMath.add(other.ptr, offset));
+ this.retained = other.retained;
+ this.capacity = capacity;
+ retained.incrementAndGet();
+ }
+
+ public NativeBuffer slice(long offset, long length) {
+ assertAllocated();
+ if( length < 0 ) throw new IllegalArgumentException("length cannot be negative");
+ if( offset < 0 ) throw new IllegalArgumentException("offset cannot be negative");
+ if( offset+length >= capacity) throw new ArrayIndexOutOfBoundsException("offset + length exceed the length of this buffer");
+ return new NativeBuffer(this, offset, length);
+ }
+
+ public NativeBuffer head(long length) {
+ return slice(0, length);
+ }
+
+ public NativeBuffer tail(long length) {
+ if( capacity-length < 0) throw new ArrayIndexOutOfBoundsException("capacity-length cannot be less than zero");
+ return slice(capacity-length, length);
+ }
+
+ public void delete() {
+ assertAllocated();
+ int r = retained.decrementAndGet();
+ if( r < 0 ) {
+ throw new Error("The object has already been deleted.");
+ } else if( r==0 ) {
+ NativeBufferJNI.free(ptr);
+ }
+ ptr = 0;
+ }
+
+ public long capacity() {
+ return capacity;
+ }
+
+ public void write(long at, byte []source, int offset, int length) {
+ assertAllocated();
+ if( length < 0 ) throw new IllegalArgumentException("length cannot be negative");
+ if( offset < 0 ) throw new IllegalArgumentException("offset cannot be negative");
+ if( at < 0 ) throw new IllegalArgumentException("at cannot be negative");
+ if( at+length > capacity ) throw new ArrayIndexOutOfBoundsException("at + length exceeds the capacity of this object");
+ if( offset+length > source.length) throw new ArrayIndexOutOfBoundsException("offset + length exceed the length of the source buffer");
+ NativeBufferJNI.buffer_copy(source, offset, ptr, at, length);
+ }
+
+ public void read(long at, byte []target, int offset, int length) {
+ assertAllocated();
+ if( length < 0 ) throw new IllegalArgumentException("length cannot be negative");
+ if( offset < 0 ) throw new IllegalArgumentException("offset cannot be negative");
+ if( at < 0 ) throw new IllegalArgumentException("at cannot be negative");
+ if( at+length > capacity ) throw new ArrayIndexOutOfBoundsException("at + length exceeds the capacity of this object");
+ if( offset+length > target.length) throw new ArrayIndexOutOfBoundsException("offset + length exceed the length of the target buffer");
+ NativeBufferJNI.buffer_copy(ptr, at, target, offset, length);
+ }
+
+ public byte[] toByteArray() {
+ if( capacity > Integer.MAX_VALUE ) {
+ throw new OutOfMemoryError("Native buffer larger than the largest allowed Java byte[]");
+ }
+ byte [] rc = new byte[(int) capacity];
+ read(0, rc, 0, rc.length);
+ return rc;
+ }
+}
45 src/main/java/org/fusesource/leveldbjni/NativeObject.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2011, FuseSource Corp. All rights reserved.
+ *
+ * http://fusesource.com
+ *
+ * The software in this package is published under the terms of the
+ * CDDL license a copy of which has been included with this distribution
+ * in the license.txt file.
+ */
+package org.fusesource.leveldbjni;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: chirino
+ * Date: 7/31/11
+ * Time: 2:40 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public abstract class NativeObject {
+
+ protected long ptr;
+
+ protected NativeObject(long ptr) {
+ this.ptr = ptr;
+ if( ptr==0 ) {
+ throw new OutOfMemoryError("Failure allocating native heap memory");
+ }
+ }
+
+ long pointer() {
+ return ptr;
+ }
+
+ public boolean isAllocated() {
+ return ptr!=0;
+ }
+
+ protected void assertAllocated() {
+ assert isAllocated() : "This object has been deleted";
+ }
+
+ abstract public void delete();
+
+
+}
137 src/main/java/org/fusesource/leveldbjni/Options.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2011, FuseSource Corp. All rights reserved.
+ *
+ * http://fusesource.com
+ *
+ * The software in this package is published under the terms of the
+ * CDDL license a copy of which has been included with this distribution
+ * in the license.txt file.
+ */
+package org.fusesource.leveldbjni;
+
+import org.fusesource.hawtjni.runtime.*;
+
+/**
+ */
+public class Options extends NativeObject {
+
+ @JniClass(name="leveldb::Options", flags={ClassFlag.CPP})
+ private static class OptionsJNI {
+ static {
+ DB.LIBRARY.load();
+ }
+
+ @JniMethod(flags={MethodFlag.CPP_NEW}, cast="leveldb::Options *")
+ public static final native long create();
+ @JniMethod(flags={MethodFlag.CPP_DELETE})
+ public static final native void delete(@JniArg(cast="leveldb::Options *") long ptr);
+
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.GETTER})
+ public static final native boolean create_if_missing(@JniArg(cast="leveldb::Options *") long ptr);
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.SETTER})
+ public static final native void create_if_missing(@JniArg(cast="leveldb::Options *") long ptr, boolean value);
+
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.GETTER})
+ public static final native boolean error_if_exists(@JniArg(cast="leveldb::Options *") long ptr);
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.SETTER})
+ public static final native void error_if_exists(@JniArg(cast="leveldb::Options *") long ptr, boolean value);
+
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.GETTER})
+ public static final native boolean paranoid_checks(@JniArg(cast="leveldb::Options *") long ptr);
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.SETTER})
+ public static final native void paranoid_checks(@JniArg(cast="leveldb::Options *") long ptr, boolean value);
+
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.GETTER}, cast="size_t")
+ public static final native long write_buffer_size(@JniArg(cast="leveldb::Options *") long ptr);
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.SETTER})
+ public static final native void write_buffer_size(@JniArg(cast="leveldb::Options *") long ptr, @JniArg(cast="size_t") long value);
+
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.GETTER}, cast="size_t")
+ public static final native long block_size(@JniArg(cast="leveldb::Options *") long ptr);
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.SETTER})
+ public static final native void block_size(@JniArg(cast="leveldb::Options *") long ptr, @JniArg(cast="size_t") long value);
+
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.GETTER})
+ public static final native int max_open_files(@JniArg(cast="leveldb::Options *") long ptr);
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.SETTER})
+ public static final native void max_open_files(@JniArg(cast="leveldb::Options *") long ptr, int value);
+
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.GETTER})
+ public static final native int block_restart_interval(@JniArg(cast="leveldb::Options *") long ptr);
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.SETTER})
+ public static final native void block_restart_interval(@JniArg(cast="leveldb::Options *") long ptr, int value);
+
+ // TODO:
+ // const Comparator* comparator;
+ // Env* env;
+ // Logger* info_log;
+ // Cache* block_cache;
+ // CompressionType compression;
+
+ }
+
+ public Options() {
+ super(OptionsJNI.create());
+ }
+
+ public void delete() {
+ assertAllocated();
+ OptionsJNI.delete(ptr);
+ ptr = 0;
+ }
+
+ public void setCreateIfMissing(boolean value) {
+ assertAllocated();
+ OptionsJNI.create_if_missing(ptr, value);
+ }
+ public boolean getCreateIfMissing() {
+ assertAllocated();
+ return OptionsJNI.create_if_missing(ptr);
+ }
+
+ public void setErrorIfExists(boolean value) {
+ assertAllocated();
+ OptionsJNI.error_if_exists(ptr, value);
+ }
+ public boolean getErrorIfExists() {
+ assertAllocated();
+ return OptionsJNI.error_if_exists(ptr);
+ }
+
+ public void setParanoidChecks(boolean value) {
+ assertAllocated();
+ OptionsJNI.paranoid_checks(ptr, value);
+ }
+ public boolean getParanoidChecks() {
+ assertAllocated();
+ return OptionsJNI.paranoid_checks(ptr);
+ }
+
+ public void setWriteBufferSize(long value) {
+ assertAllocated();
+ OptionsJNI.write_buffer_size(ptr, value);
+ }
+ public long getWriteBufferSize() {
+ assertAllocated();
+ return OptionsJNI.write_buffer_size(ptr);
+ }
+
+ public void setMaxOpenFiles(int value) {
+ assertAllocated();
+ OptionsJNI.max_open_files(ptr, value);
+ }
+ public int getMaxOpenFiles() {
+ assertAllocated();
+ return OptionsJNI.max_open_files(ptr);
+ }
+
+ public void setBlockRestartInterval(int value) {
+ assertAllocated();
+ OptionsJNI.block_restart_interval(ptr, value);
+ }
+ public int getBlockRestartInterval() {
+ assertAllocated();
+ return OptionsJNI.block_restart_interval(ptr);
+ }
+
+}
69 src/main/java/org/fusesource/leveldbjni/ReadOptions.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2011, FuseSource Corp. All rights reserved.
+ *
+ * http://fusesource.com
+ *
+ * The software in this package is published under the terms of the
+ * CDDL license a copy of which has been included with this distribution
+ * in the license.txt file.
+ */
+package org.fusesource.leveldbjni;
+
+import org.fusesource.hawtjni.runtime.*;
+
+/**
+ */
+public class ReadOptions extends NativeObject {
+
+ @JniClass(name="leveldb::ReadOptions", flags={ClassFlag.CPP})
+ private static class ReadOptionsJNI {
+ static {
+ DB.LIBRARY.load();
+ }
+
+ @JniMethod(flags={MethodFlag.CPP_NEW}, cast="leveldb::ReadOptions *")
+ public static final native long create();
+ @JniMethod(flags={MethodFlag.CPP_DELETE})
+ public static final native void delete(@JniArg(cast="leveldb::ReadOptions *") long ptr);
+
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.GETTER})
+ public static final native boolean verify_checksums(@JniArg(cast="leveldb::ReadOptions *") long ptr);
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.SETTER})
+ public static final native void verify_checksums(@JniArg(cast="leveldb::ReadOptions *") long ptr, boolean value);
+
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.GETTER})
+ public static final native boolean fill_cache(@JniArg(cast="leveldb::ReadOptions *") long ptr);
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.SETTER})
+ public static final native void fill_cache(@JniArg(cast="leveldb::ReadOptions *") long ptr, boolean value);
+ }
+
+ public ReadOptions() {
+ super(ReadOptionsJNI.create());
+ }
+
+ public void delete() {
+ assertAllocated();
+ ReadOptionsJNI.delete(ptr);
+ ptr = 0;
+ }
+
+ public void setVerifyChecksums(boolean value) {
+ assertAllocated();
+ ReadOptionsJNI.verify_checksums(ptr, value);
+ }
+ public boolean getVerifyChecksums() {
+ assertAllocated();
+ return ReadOptionsJNI.verify_checksums(ptr);
+ }
+
+ public void setFillCache(boolean value) {
+ assertAllocated();
+ ReadOptionsJNI.fill_cache(ptr, value);
+ }
+ public boolean getFillCache() {
+ assertAllocated();
+ return ReadOptionsJNI.fill_cache(ptr);
+ }
+
+
+}
63 src/main/java/org/fusesource/leveldbjni/Slice.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2011, FuseSource Corp. All rights reserved.
+ *
+ * http://fusesource.com
+ *
+ * The software in this package is published under the terms of the
+ * CDDL license a copy of which has been included with this distribution
+ * in the license.txt file.
+ */
+package org.fusesource.leveldbjni;
+
+import org.fusesource.hawtjni.runtime.*;
+
+/**
+ */
+public class Slice extends NativeObject {
+
+ @JniClass(name="leveldb::Slice", flags={ClassFlag.CPP})
+ private static class SliceJNI {
+ static {
+ DB.LIBRARY.load();
+ }
+
+ @JniMethod(flags={MethodFlag.CPP_NEW}, cast="leveldb::Slice *")
+ public static final native long create(
+ @JniArg(cast="const char *") long data,
+ @JniArg(cast="size_t") long n);
+
+ @JniMethod(flags={MethodFlag.CPP_DELETE})
+ public static final native void delete(@JniArg(cast="leveldb::Slice *") long ptr);
+
+ @JniMethod(flags={MethodFlag.CPP}, cast="const char*")
+ public static final native long data(@JniArg(cast="leveldb::Slice *") long ptr);
+
+ @JniMethod(flags={MethodFlag.CPP}, cast="size_t")
+ public static final native long size(@JniArg(cast="leveldb::Slice *") long ptr);
+ }
+
+ public Slice(long ptr, long length) {
+ super(SliceJNI.create(ptr, length));
+ }
+
+ public Slice(NativeBuffer buffer) {
+ this(buffer.pointer(), buffer.capacity());
+ }
+
+ public void delete() {
+ assertAllocated();
+ SliceJNI.delete(ptr);
+ ptr = 0;
+ }
+
+ long getData() {
+ assertAllocated();
+ return SliceJNI.data(ptr);
+ }
+
+ long getSize() {
+ assertAllocated();
+ return SliceJNI.size(ptr);
+ }
+
+}
76 src/main/java/org/fusesource/leveldbjni/Status.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2011, FuseSource Corp. All rights reserved.
+ *
+ * http://fusesource.com
+ *
+ * The software in this package is published under the terms of the
+ * CDDL license a copy of which has been included with this distribution
+ * in the license.txt file.
+ */
+package org.fusesource.leveldbjni;
+
+import org.fusesource.hawtjni.runtime.*;
+
+/**
+ */
+class Status extends NativeObject{
+
+ @JniClass(name="leveldb::Status", flags={ClassFlag.CPP})
+ static class StatusJNI {
+ static {
+ DB.LIBRARY.load();
+ }
+
+ @JniMethod(flags={MethodFlag.CPP_DELETE})
+ public static final native void delete(@JniArg(cast="leveldb::Status *") long ptr);
+
+ @JniMethod(flags={MethodFlag.CPP})
+ public static final native boolean ok(
+ @JniArg(cast="leveldb::Status *") long ptr);
+
+ @JniMethod(flags={MethodFlag.CPP})
+ public static final native boolean IsNotFound(
+ @JniArg(cast="leveldb::Status *") long ptr);
+
+ @JniMethod(copy="std::string", flags={MethodFlag.CPP})
+ public static final native long ToString(
+ @JniArg(cast="leveldb::Status *") long ptr);
+ }
+
+ public Status(long ptr) {
+ super(ptr);
+ }
+
+ @Override
+ public void delete() {
+ assertAllocated();
+ StatusJNI.delete(ptr);
+ ptr = 0;
+ }
+
+ public boolean isOk() {
+ assertAllocated();
+ return StatusJNI.ok(ptr);
+ }
+
+ public boolean isNotFound() {
+ assertAllocated();
+ return StatusJNI.IsNotFound(ptr);
+ }
+
+ public String toString() {
+ assertAllocated();
+ long strptr = StatusJNI.ToString(ptr);
+ if( strptr==0 ) {
+ return null;
+ } else {
+ StdString rc = new StdString(strptr);
+ try {
+ return rc.toString();
+ } finally {
+ rc.delete();
+ }
+ }
+ }
+
+}
76 src/main/java/org/fusesource/leveldbjni/StdString.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2011, FuseSource Corp. All rights reserved.
+ *
+ * http://fusesource.com
+ *
+ * The software in this package is published under the terms of the
+ * CDDL license a copy of which has been included with this distribution
+ * in the license.txt file.
+ */
+package org.fusesource.leveldbjni;
+
+import org.fusesource.hawtjni.runtime.*;
+
+/**
+ */
+public class StdString extends NativeObject {
+
+ @JniClass(name="std::string", flags={ClassFlag.CPP})
+ private static class StdStringJNI {
+ static {
+ DB.LIBRARY.load();
+ }
+
+ @JniMethod(flags={MethodFlag.CPP_NEW}, cast="std::string *")
+ public static final native long create();
+
+ @JniMethod(flags={MethodFlag.CPP_NEW}, cast="std::string *")
+ public static final native long create(String value);
+
+ @JniMethod(flags={MethodFlag.CPP_DELETE})
+ static final native void delete(
+ @JniArg(cast="std::string *") long ptr);
+
+ @JniMethod(flags={MethodFlag.CPP}, accessor = "c_str", cast="const char*")
+ public static final native long c_str_ptr (
+ @JniArg(cast="std::string *") long ptr);
+
+ @JniMethod(flags={MethodFlag.CPP},cast = "size_t")
+ public static final native long length (
+ @JniArg(cast="std::string *") long ptr);
+
+ }
+
+ public StdString(long ptr) {
+ super(ptr);
+ }
+
+ public StdString() {
+ super(StdStringJNI.create());
+ }
+
+ public void delete() {
+ assertAllocated();
+ StdStringJNI.delete(ptr);
+ ptr = 0;
+ }
+
+ public String toString() {
+ return new String(toByteArray());
+ }
+
+ public long length() {
+ assertAllocated();
+ return StdStringJNI.length(ptr);
+ }
+
+ public byte[] toByteArray() {
+ long l = length();
+ if( l > Integer.MAX_VALUE ) {
+ throw new ArrayIndexOutOfBoundsException("Native string is larger than the maximum Java array");
+ }
+ byte []rc = new byte[(int) l];
+ NativeBuffer.NativeBufferJNI.buffer_copy(StdStringJNI.c_str_ptr(ptr), 0, rc, 0, rc.length);
+ return rc;
+ }
+}
55 src/main/java/org/fusesource/leveldbjni/WriteOptions.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2011, FuseSource Corp. All rights reserved.
+ *
+ * http://fusesource.com
+ *
+ * The software in this package is published under the terms of the
+ * CDDL license a copy of which has been included with this distribution
+ * in the license.txt file.
+ */
+package org.fusesource.leveldbjni;
+
+import org.fusesource.hawtjni.runtime.*;
+
+/**
+ */
+public class WriteOptions extends NativeObject {
+
+ @JniClass(name="leveldb::WriteOptions", flags={ClassFlag.CPP})
+ private static class WriteOptionsJNI {
+ static {
+ DB.LIBRARY.load();
+ }
+
+ @JniMethod(flags={MethodFlag.CPP_NEW}, cast="leveldb::WriteOptions *")
+ public static final native long create();
+ @JniMethod(flags={MethodFlag.CPP_DELETE})
+ public static final native void delete(@JniArg(cast="leveldb::WriteOptions *") long ptr);
+
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.GETTER})
+ public static final native boolean sync(@JniArg(cast="leveldb::WriteOptions *") long ptr);
+ @JniMethod(flags = {MethodFlag.CPP, MethodFlag.SETTER})
+ public static final native void sync(@JniArg(cast="leveldb::WriteOptions *") long ptr, boolean value);
+
+ }
+
+ public WriteOptions() {
+ super(WriteOptionsJNI.create());
+ }
+
+ public void delete() {
+ assertAllocated();
+ WriteOptionsJNI.delete(ptr);
+ ptr = 0;
+ }
+
+ public void setSync(boolean value) {
+ assertAllocated();
+ WriteOptionsJNI.sync(ptr, value);
+ }
+ public boolean getSync() {
+ assertAllocated();
+ return WriteOptionsJNI.sync(ptr);
+ }
+
+}
241 src/main/native-package/license.txt
@@ -0,0 +1,241 @@
+ COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL)
+ Version 1.0
+
+
+1. Definitions.
+
+ 1.1. “Contributor” means each individual or entity that creates or contributes to the creation of Modifications.
+
+ 1.2. “Contributor Version” means the combination of the Original Software, prior Modifications used by a Contributor
+ (if any), and the Modifications made by that particular Contributor.
+
+ 1.3. “Covered Software” means (a) the Original Software, or (b) Modifications, or (c) the combination
+ of files containing Original Software with files containing Modifications, in each case including portions thereof.
+
+ 1.4. “Executable” means the Covered Software in any form other than Source Code.
+
+ 1.5. “Initial Developer” means the individual or entity that first makes Original Software available under this License.
+
+ 1.6. “Larger Work” means a work which combines Covered Software or portions thereof with code not governed by the terms
+ of this License.
+
+ 1.7. “License” means this document.
+
+ 1.8. “Licensable” means having the right to grant, to the maximum extent possible, whether at the time of the
+ initial grant or subsequently acquired, any and all of the rights conveyed herein.
+
+ 1.9. “Modifications” means the Source Code and Executable form of any of the following:
+ A. Any file that results from an addition to, deletion from or modification of the contents of a file
+ containing Original Software or previous Modifications;
+ B. Any new file that contains any part of the Original Software or previous Modification; or
+ C. Any new file that is contributed or otherwise made available under the terms of this License.
+
+ 1.10. “Original Software” means the Source Code and Executable form of computer software code that is originally
+ released under this License.
+
+ 1.11. “Patent Claims” means any patent claim(s), now owned or hereafter acquired, including without limitation,
+ method, process, and apparatus claims, in any patent Licensable by grantor.
+
+ 1.12. “Source Code” means (a) the common form of computer software code in which modifications are made and
+ (b) associated documentation included in or with such code.
+
+ 1.13. “You” (or “Your”) means an individual or a legal entity exercising rights under, and complying with all of
+ the terms of, this License. For legal entities, “You” includes any entity which controls, is controlled by, or is
+ under common control with You. For purposes of this definition, “control” means (a) the power, direct or indirect,
+ to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more
+ than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
+
+2. License Grants.
+
+ 2.1. The Initial Developer Grant.
+ Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims,
+ the Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license:
+
+ (a) under intellectual property rights (other than patent or trademark) Licensable by Initial Developer,
+ to use, reproduce, modify, display, perform, sublicense and distribute the Original Software (or portions
+ thereof), with or without Modifications, and/or as part of a Larger Work; and
+
+ (b) under Patent Claims infringed by the making, using or selling of Original Software, to make, have made,
+ use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Software (or portions thereof).
+
+ (c) The licenses granted in Sections 2.1(a) and (b) are effective on the date Initial Developer first
+ distributes or otherwise makes the Original Software available to a third party under the terms of this License.
+
+ (d) Notwithstanding Section 2.1(b) above, no patent license is granted: (1) for code that You delete from
+ the Original Software, or (2) for infringements caused by: (i) the modification of the Original Software,
+ or (ii) the combination of the Original Software with other software or devices.
+
+ 2.2. Contributor Grant.
+ Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims,
+ each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license:
+
+ (a) under intellectual property rights (other than patent or trademark) Licensable by Contributor to use,
+ reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor
+ (or portions thereof), either on an unmodified basis, with other Modifications, as Covered Software and/or
+ as part of a Larger Work; and
+
+ (b) under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor
+ either alone and/or in combination with its Contributor Version (or portions of such combination), to make,
+ use, sell, offer for sale, have made, and/or otherwise dispose of: (1) Modifications made by that Contributor
+ (or portions thereof); and (2) the combination of Modifications made by that Contributor with its Contributor
+ Version (or portions of such combination).
+
+ (c) The licenses granted in Sections 2.2(a) and 2.2(b) are effective on the date Contributor first distributes
+ or otherwise makes the Modifications available to a third party.
+
+ (d) Notwithstanding Section 2.2(b) above, no patent license is granted: (1) for any code that Contributor has
+ deleted from the Contributor Version; (2) for infringements caused by: (i) third party modifications of
+ Contributor Version, or (ii) the combination of Modifications made by that Contributor with other software
+ (except as part of the Contributor Version) or other devices; or (3) under Patent Claims infringed by Covered
+ Software in the absence of Modifications made by that Contributor.
+
+3. Distribution Obligations.
+
+ 3.1. Availability of Source Code.
+ Any Covered Software that You distribute or otherwise make available in Executable form must also be made available
+ in Source Code form and that Source Code form must be distributed only under the terms of this License. You must
+ include a copy of this License with every copy of the Source Code form of the Covered Software You distribute or
+ otherwise make available. You must inform recipients of any such Covered Software in Executable form as to how they
+ can obtain such Covered Software in Source Code form in a reasonable manner on or through a medium customarily used
+ for software exchange.
+
+ 3.2. Modifications.
+ The Modifications that You create or to which You contribute are governed by the terms of this License. You
+ represent that You believe Your Modifications are Your original creation(s) and/or You have sufficient rights to
+ grant the rights conveyed by this License.
+
+ 3.3. Required Notices.
+ You must include a notice in each of Your Modifications that identifies You as the Contributor of the Modification.
+ You may not remove or alter any copyright, patent or trademark notices contained within the Covered Software, or
+ any notices of licensing or any descriptive text giving attribution to any Contributor or the Initial Developer.
+
+ 3.4. Application of Additional Terms.
+ You may not offer or impose any terms on any Covered Software in Source Code form that alters or restricts the
+ applicable version of this License or the recipients’ rights hereunder. You may choose to offer, and to charge a
+ fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software.
+ However, you may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor.
+ You must make it absolutely clear that any such warranty, support, indemnity or liability obligation is offered
+ by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability
+ incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability
+ terms You offer.
+
+ 3.5. Distribution of Executable Versions.
+ You may distribute the Executable form of the Covered Software under the terms of this License or under the terms
+ of a license of Your choice, which may contain terms different from this License, provided that You are in compliance
+ with the terms of this License and that the license for the Executable form does not attempt to limit or alter
+ the recipient’s rights in the Source Code form from the rights set forth in this License. If You distribute the
+ Covered Software in Executable form under a different license, You must make it absolutely clear that any terms
+ which differ from this License are offered by You alone, not by the Initial Developer or Contributor. You hereby
+ agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer
+ or such Contributor as a result of any such terms You offer.
+
+ 3.6. Larger Works.
+ You may create a Larger Work by combining Covered Software with other code not governed by the terms of this License
+ and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this
+ License are fulfilled for the Covered Software.
+
+4. Versions of the License.
+
+ 4.1. New Versions.
+ Sun Microsystems, Inc. is the initial license steward and may publish revised and/or new versions of this License
+ from time to time. Each version will be given a distinguishing version number. Except as provided in Section 4.3,
+ no one other than the license steward has the right to modify this License.
+
+ 4.2. Effect of New Versions.
+ You may always continue to use, distribute or otherwise make the Covered Software available under the terms of
+ the version of the License under which You originally received the Covered Software. If the Initial Developer
+ includes a notice in the Original Software prohibiting it from being distributed or otherwise made available under
+ any subsequent version of the License, You must distribute and make the Covered Software available under the terms
+ of the version of the License under which You originally received the Covered Software. Otherwise, You may also
+ choose to use, distribute or otherwise make the Covered Software available under the terms of any subsequent version
+ of the License published by the license steward.
+
+ 4.3. Modified Versions.
+ When You are an Initial Developer and You want to create a new license for Your Original Software, You may create
+ and use a modified version of this License if You: (a) rename the license and remove any references to the name of
+ the license steward (except to note that the license differs from this License); and (b) otherwise make it clear that
+ the license contains terms which differ from this License.
+
+5. DISCLAIMER OF WARRANTY.
+
+COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN “AS IS” BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR
+IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A
+PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU.
+SHOULD ANY COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
+COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
+
+6. TERMINATION.
+
+ 6.1. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms
+ herein and fail to cure such breach within 30 days of becoming aware of the breach. Provisions which, by their
+ nature, must remain in effect beyond the termination of this License shall survive.
+
+ 6.2. If You assert a patent infringement claim (excluding declaratory judgment actions) against Initial Developer
+ or a Contributor (the Initial Developer or Contributor against whom You assert such claim is referred to as
+ “Participant”) alleging that the Participant Software (meaning the Contributor Version where the Participant
+ is a Contributor or the Original Software where the Participant is the Initial Developer) directly or
+ indirectly infringes any patent, then any and all rights granted directly or indirectly to You by such Participant,
+ the Initial Developer (if the Initial Developer is not the Participant) and all Contributors under Sections 2.1
+ and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively and automatically
+ at the expiration of such 60 day notice period, unless if within such 60 day period You withdraw Your claim with
+ respect to the Participant Software against such Participant either unilaterally or pursuant to a written agreement
+ with Participant.
+
+ 6.3. If You assert a patent infringement claim against Participant alleging that the Participant Software directly
+ or indirectly infringes any patent where such claim is resolved (such as by license or settlement) prior to the
+ initiation of patent infringement litigation, then the reasonable value of the licenses granted by such Participant
+ under Sections 2.1 or 2.2 shall be taken into account in determining the amount or value of any payment or license.
+
+ 6.4. In the event of termination under Sections 6.1 or 6.2 above, all end user licenses that have been validly granted
+ by You or any distributor hereunder prior to termination (excluding licenses granted to You by any distributor)
+ shall survive termination.
+
+7. LIMITATION OF LIABILITY.
+
+UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE
+INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR
+LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY
+SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL
+INJURY RESULTING FROM SUCH PARTY’S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
+EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
+
+8. U.S. GOVERNMENT END USERS.
+
+The Covered Software is a “commercial item,” as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of
+“commercial computer software” (as that term is defined at 48 C.F.R. § 252.227-7014(a)(1)) and “commercial computer software documentation”
+as such terms are used in 48 C.F.R. 12.212 Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
+all U.S. Government End Users acquire Covered Software with only those rights set forth herein. This U.S. Government Rights clause is in lieu of,
+and supersedes, any other FAR, DFAR, or other clause or provision that addresses Government rights in computer software under this License.
+
+9. MISCELLANEOUS.
+
+This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed
+by the law of the jurisdiction specified in a notice contained within the Original Software (except to the extent applicable law, if any,
+provides otherwise), excluding such jurisdiction’s conflict-of-law provisions. Any litigation relating to this License shall be subject
+to the jurisdiction of the courts located in the jurisdiction and venue specified in a notice contained within the Original Software, with the
+losing party responsible for costs, including, without limitation, court costs and reasonable attorneys’ fees and expenses. The application of
+the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that
+the language of a contract shall be construed against the drafter shall not apply to this License. You agree that You alone are responsible for
+compliance with the United States export administration regulations (and the export control laws and regulation of any other countries) when You use,
+distribute or otherwise make available any Covered Software.
+
+10. RESPONSIBILITY FOR CLAIMS.
+
+As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of
+its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on
+an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability.
+
+--------
+
+NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION
+LICENSE (CDDL)
+
+The OpenSolaris code released under the CDDL shall be governed by the laws
+of the State of California (excluding conflict-of-law provisions). Any
+litigation relating to this License shall be subject to the jurisdiction of
+the Federal Courts of the Northern District of California and the state
+courts of the State of California, with venue lying in Santa Clara County,
+California.
27 src/main/native-package/m4/custom.m4
@@ -0,0 +1,27 @@
+dnl ---------------------------------------------------------------------------
+dnl Copyright (C) 2011, FuseSource Corp. All rights reserved.
+dnl
+dnl http://fusesource.com
+dnl
+dnl The software in this package is published under the terms of the
+dnl CDDL license a copy of which has been included with this distribution
+dnl in the license.txt file.
+dnl ---------------------------------------------------------------------------
+
+AC_DEFUN([CUSTOM_M4_SETUP],
+[
+ AC_LANG_PUSH(C++)
+ AC_ARG_WITH([leveldb],
+ [AS_HELP_STRING([--with-leveldb@<:@=PATH@:>@],
+ [Directory where leveldb was built. Example: --with-leveldb=/opt/leveldb])],
+ [
+ CFLAGS="$CFLAGS -I${withval}/include"
+ CXXFLAGS="$CXXFLAGS -I${withval}/include"
+ AC_SUBST(CXXFLAGS)
+ LDFLAGS="$LDFLAGS -lleveldb -L${withval}"
+ AC_SUBST(LDFLAGS)
+ ])
+
+ AC_CHECK_HEADER([leveldb/db.h],,AC_MSG_ERROR([cannot find headers for leveldb]))
+ AC_LANG_POP()
+])
14 src/main/native-package/src/buffer.c
@@ -0,0 +1,14 @@
+/*******************************************************************************
+ * Copyright (C) 2011, FuseSource Corp. All rights reserved.
+ *
+ * http://fusesource.com
+ *
+ * The software in this package is published under the terms of the
+ * CDDL license a copy of which has been included with this distribution
+ * in the license.txt file.
+ *******************************************************************************/
+#include "leveldbjni.h"
+
+void buffer_copy(const void *source, size_t source_pos, void *dest, size_t dest_pos, size_t length) {
+ memmove(dest+dest_pos, source+source_pos, length);
+}
52 src/main/native-package/src/leveldbjni.h
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (C) 2011, FuseSource Corp. All rights reserved.
+ *
+ * http://fusesource.com
+ *
+ * The software in this package is published under the terms of the
+ * CDDL license a copy of which has been included with this distribution
+ * in the license.txt file.
+ *******************************************************************************/
+#ifndef LEVELDBJNI_H
+#define LEVELDBJNI_H
+
+#ifdef HAVE_CONFIG_H
+ /* configure based build.. we will use what it discovered about the platform */
+ #include "config.h"
+#else
+ #if defined(_WIN32) || defined(_WIN64)
+ /* Windows based build */
+ #define HAVE_STDLIB_H 1
+ #define HAVE_STRINGS_H 1
+ #include <windows.h>
+ #endif
+#endif
+
+#ifdef HAVE_UNISTD_H
+ #include <unistd.h>
+#endif
+
+#ifdef HAVE_STDLIB_H
+ #include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRINGS_H
+ #include <string.h>
+#endif
+
+#ifdef __cplusplus
+#include "leveldb/db.h"
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void buffer_copy(const void *source, size_t source_pos, void *dest, size_t dest_pos, size_t length);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+
+#endif /* LEVELDBJNI_H */
107 src/test/java/org/fusesource/leveldbjni/DBTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2011, FuseSource Corp. All rights reserved.
+ *
+ * http://fusesource.com
+ *
+ * The software in this package is published under the terms of the
+ * CDDL license a copy of which has been included with this distribution
+ * in the license.txt file.
+ */
+package org.fusesource.leveldbjni;
+
+import junit.framework.TestCase;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+
+public class DBTest extends TestCase {
+
+ File getTestDirectory(String name) {
+ File rc = new File(new File("test-data"), name);
+ rc.mkdirs();
+ return rc;
+ }
+
+ @Test
+ public void testOpen() throws IOException {
+
+ Options options = new Options();
+ options.setCreateIfMissing(true);
+
+ File path = getTestDirectory("db1");
+ System.out.println("Creating DB at: "+path.getCanonicalPath());
+ DB db = DB.open(options, path);
+
+ options.delete();
+ db.delete();
+
+ // Try again.. this time we expect a failure since it exists.
+ options = new Options();
+ options.setErrorIfExists(true);
+ System.out.println("Creating DB at: "+path.getCanonicalPath());
+ try {
+ DB.open(options, path);
+ fail("Expected exception.");
+ } catch (DB.DBException e) {
+ e.printStackTrace();
+ }
+ options.delete();
+
+ }
+
+ @Test
+ public void testCRUD() throws IOException {
+
+ Options options = new Options();
+ options.setCreateIfMissing(true);
+
+ File path = getTestDirectory("db2");
+ System.out.println("Creating DB at: "+path.getCanonicalPath());
+ DB db = DB.open(options, path);
+
+ WriteOptions wo = new WriteOptions();
+ wo.setSync(false);
+
+ ReadOptions ro = new ReadOptions();
+ ro.setFillCache(true);
+ ro.setVerifyChecksums(true);
+
+
+ byte [] red = "red".getBytes("UTF-8");
+ byte [] blue = "blue".getBytes("UTF-8");
+ byte [] green = "green".getBytes("UTF-8");
+ byte [] tampa = "Tampa".getBytes("UTF-8");
+ byte [] london = "London".getBytes("UTF-8");
+ byte [] newyork = "New York".getBytes("UTF-8");
+
+ db.put(wo, tampa, green);
+ db.put(wo, london, red);
+ db.put(wo, newyork, blue);
+
+ assertEquals(db.get(ro, tampa), green);
+ assertEquals(db.get(ro, london), red);
+ assertEquals(db.get(ro, newyork), blue);
+
+ db.delete(wo, newyork);
+ try {
+ db.get(ro, newyork);
+ fail("Expecting exception");
+ } catch( DB.DBException e) {
+ e.printStackTrace();
+ }
+
+ // leveldb does not consider deleting something that does not exist an error.
+ db.delete(wo, newyork);
+
+ ro.delete();
+ wo.delete();
+ options.delete();
+ db.delete();
+ }
+
+ public void assertEquals(byte [] arg1, byte[] arg2) {
+ assertTrue(Arrays.equals(arg1, arg2));
+ }
+}

0 comments on commit 3baf541

Please sign in to comment.
Something went wrong with that request. Please try again.