00001
00002
00003 package db.GettingStarted;
00004
00005 import com.sleepycat.bind.tuple.TupleBinding;
00006 import com.sleepycat.db.SecondaryKeyCreator;
00007 import com.sleepycat.db.DatabaseEntry;
00008 import com.sleepycat.db.DatabaseException;
00009 import com.sleepycat.db.SecondaryDatabase;
00010
00011 public class ItemNameKeyCreator implements SecondaryKeyCreator {
00012
00013 private TupleBinding theBinding;
00014
00015
00016 ItemNameKeyCreator(TupleBinding binding) {
00017 theBinding = binding;
00018 }
00019
00020
00021 public boolean createSecondaryKey(SecondaryDatabase secDb,
00022 DatabaseEntry keyEntry,
00023 DatabaseEntry dataEntry,
00024 DatabaseEntry resultEntry)
00025 throws DatabaseException {
00026
00027 if (dataEntry != null) {
00028
00029 Inventory inventoryItem =
00030 (Inventory)theBinding.entryToObject(dataEntry);
00031
00032 String theItem = inventoryItem.getItemName();
00033 resultEntry.setData(theItem.getBytes());
00034 }
00035 return true;
00036 }
00037 }