Here's my Sleepycat Hello World
import com.sleepycat.je.Cursor; import com.sleepycat.je.Database; import com.sleepycat.je.DatabaseEntry; import com.sleepycat.je.DatabaseConfig; import com.sleepycat.je.DatabaseException; import com.sleepycat.je.Environment; import com.sleepycat.je.EnvironmentConfig; import com.sleepycat.je.LockMode; import com.sleepycat.je.OperationStatus; import java.io.File; public class HelloBdb { public static void main(String[] args) throws Exception { String key = args[0]; String value = args[1]; File dir = new File("db"); dir.mkdirs(); Environment env = new Environment(dir, new EnvironmentConfig()); Database database = env.openDatabase(null, "foobar", new DatabaseConfig()); database.put(null, new DatabaseEntry(key.getBytes()), new DatabaseEntry(value.getBytes())); DatabaseEntry foundKey = new DatabaseEntry(); DatabaseEntry foundData = new DatabaseEntry(); Cursor cursor = database.openCursor(null, null); while (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) { String keyString = new String(foundKey.getData()); String dataString = new String(foundData.getData()); System.out.println("Key | Data : " + keyString + " | " + dataString + ""); } cursor.close(); database.close(); env.close(); } }
Of course, the real fun will be running this in a multi-threaded environment and the concurrency issues therein. With Hello World done, it's time to move on to see what else needs to be added to the cookbook.
( Apr 12 2005, 08:57:09 PM PDT ) Permalink