1 4 package je.gettingStarted; 5 6 import com.sleepycat.je.SecondaryKeyCreator; 7 import com.sleepycat.je.DatabaseEntry; 8 import com.sleepycat.je.DatabaseException; 9 import com.sleepycat.je.SecondaryDatabase; 10 import com.sleepycat.bind.tuple.TupleBinding; 11 12 import java.io.IOException ; 13 14 public class ItemNameKeyCreator implements SecondaryKeyCreator { 15 16 private TupleBinding theBinding; 17 18 ItemNameKeyCreator(TupleBinding binding) { 20 theBinding = binding; 21 } 22 23 public boolean createSecondaryKey(SecondaryDatabase secDb, 25 DatabaseEntry keyEntry, DatabaseEntry dataEntry, DatabaseEntry resultEntry) throws DatabaseException { 29 30 if (dataEntry != null) { 31 Inventory inventoryItem = 33 (Inventory)theBinding.entryToObject(dataEntry); 34 String theItem = inventoryItem.getItemName(); 36 try { 37 resultEntry.setData(theItem.getBytes("UTF-8")); 38 } catch (IOException willNeverOccur) {} 39 } 40 return true; 41 } 42 } 43 | Popular Tags |