- Download an Oracle NoSQL Database.
Download an Oracle NoSQL Database at Oracle NoSQL Database, Server.
The one I downloaded is an Enterprise Edition kv-ee-2.1.54.zip.
- Install the Oracle NoSQL Database.
Unzip the zip file kv-ee-2.1.54.zip and it will create a folder kv-2.1.54, which again includes the four folders: doc, examples, exttab, and lib, and two files: LICENSE and README.
- Download a Java SE (Java Platform, Standard Edition).
Download a Java SE at Java SE Downloads.
The one I downloaded is Java SE Development Kit 7u45 for Windows x86 jdk-7u45-windows-i586.exe.
- Install the Java SE.
Doubly click the file jdk-7u45-windows-i586.exe and it will start installing the Java SE for you.
After installation, it creates a folder such as C:\Program File (x86)\Java, which again includes two folders:
jdk1.7.0_45, where the JDK (Java Development Kit) includes a complete JRE plus tools for developing, debugging, and monitoring Java applications, and
jre7, where the JRE (Java Runtime Environment) contains everything required to run Java applications on your system.
- Download an Eclipse IDE for Java Developers.
Download an Eclipse IDE for Java Developers at Eclipse IDE for Java Developers.
The one I downloaded is eclipse-java-europa-winter-win32.zip.
- Install the Eclipse IDE for Java Developers.
Unzip the zip file eclipse-java-europa-winter-win32.zip and it will create a folder eclipse, which again includes four folders: configuration, features, plugins, and readme.
- Start up the Oracle KVLite.
KVLite is a single process version of Oracle NoSQL Database.
KVLite is not tuned for performance, but does give you easy access to a simple key/value store so that you can test the API.
cd into the kv-2.1.54 directory to start the NoSQL Database server.
For example
$ cd C:\Oracle NoSQL\kv-2.1.54
$ java -jar lib/kvstore.jar kvlite
Created new kvlite store with args:
-root ./kvroot -store kvstore -host myhost -port 5000 -admin 5001
- Create a Java Project.
Select the following options in the Eclipse:
File ⇒ New ⇒ Java Project
Enter the project name such as com.wenchen.hello and click the button Next.
- Add the Oracle kvclient Library.
Go to the Libraries tab and click the button Add Library:
Pick User Library and click the button Next:
Click the button User Libraries:
Click the button New, enter a user library name such as kvclient, and click the button Add JARs:
Add the JAR such as C:\Oracle NoSQL\kv-2.1.54\lib\kvclient.jar and click the button OK:
- Start Developing the Application.
The Eclipse IDE now becomes as follows:
Point to the project in the left pane of Package Explorer, right click the mouse, select the options New and Class, enter the class name such as HelloBigDataWorld, and click the button Finish:
Complete the class such as
|
src/com/wenchen/hello/HelloBigDataWorld.java
|
package com.wenchen.hello;
import oracle.kv.KVStore;
import oracle.kv.KVStoreConfig;
import oracle.kv.KVStoreFactory;
import oracle.kv.Key;
import oracle.kv.Value;
import oracle.kv.ValueVersion;
/**
* An extremely simple KVStore client application that writes and reads a
* single record. It can be used to validate an installation.
*
* Before running this example program, start a KVStore instance. The simplest
* way to do that is to run KV Lite as described in the INSTALL document. Use
* the KVStore instance name, host and port for running this program, as
* follows:
*
* java schema.HelloBigDataWorld -store <instance name> \
* -host <host name> \
* -port <port number>
*
* For all examples the default instance name is kvstore, the default host name
* is localhost and the default port number is 5000. These defaults match the
* defaults for running kvlite, so the simplest way to run the examples along
* with kvlite is to omit all parameters.
*/
public class HelloBigDataWorld {
private final KVStore store;
/**
* Runs the HelloBigDataWorld command line program.
*/
public static void main( String args[ ] ) {
try {
HelloBigDataWorld example = new HelloBigDataWorld( args );
example.runExample( );
}
catch ( RuntimeException e ) {
e.printStackTrace( );
}
}
/**
* Parses command line args and opens the KVStore.
*/
HelloBigDataWorld( String[ ] argv ) {
String storeName = "kvstore";
String hostName = "localhost";
String hostPort = "5000";
final int nArgs = argv.length;
int argc = 0;
while ( argc < nArgs ) {
final String thisArg = argv[argc++];
if ( thisArg.equals( "-store" ) )
if ( argc < nArgs )
storeName = argv[argc++];
else
usage( "-store requires an argument" );
else if ( thisArg.equals( "-host" ) )
if ( argc < nArgs )
hostName = argv[argc++];
else
usage( "-host requires an argument" );
else if ( thisArg.equals( "-port" ) )
if ( argc < nArgs )
hostPort = argv[argc++];
else
usage( "-port requires an argument" );
else
usage( "Unknown argument: " + thisArg );
}
store = KVStoreFactory.getStore
( new KVStoreConfig( storeName, hostName + ":" + hostPort ) );
}
private void usage( String message ) {
System.out.println( "\n" + message + "\n" );
System.out.println( "usage: " + getClass( ).getName( ) );
System.out.println( "\t-store <instance name> (default: kvstore) " +
"-host <host name> (default: localhost) " +
"-port <port number> (default: 5000)" );
System.exit( 1 );
}
/**
* Performs example operations and closes the KVStore.
*/
void runExample( ) {
final String keyString = "Hello";
final String valueString = "Big Data World!";
store.put( Key.createKey( keyString ),
Value.createValue( valueString.getBytes( ) ) );
final ValueVersion valueVersion = store.get( Key.createKey( keyString ) );
System.out.println( keyString + " " +
new String( valueVersion.getValue( ).getValue( ) ) );
store.close( );
}
}
|
The Eclipse then becomes as follows:
- Build and Run the Project.
Select the following options to build the project:
Project ⇒ Build Project
Select the following options to run the project:
Run ⇒ Run
The output “Hello Big Data World!” is then displayed in the Console tab:
|