Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

ItemNameKeyCreator.java

00001 // File: ItemNameKeyCreator.java
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     // Use the constructor to set the tuple binding
00016     ItemNameKeyCreator(TupleBinding binding) {
00017         theBinding = binding;
00018     }
00019 
00020     // Abstract method that we must implement
00021     public boolean createSecondaryKey(SecondaryDatabase secDb,
00022              DatabaseEntry keyEntry,    // From the primary
00023              DatabaseEntry dataEntry,   // From the primary
00024              DatabaseEntry resultEntry) // set the key data on this.
00025          throws DatabaseException {
00026 
00027         if (dataEntry != null) {
00028             // Convert dataEntry to an Inventory object
00029             Inventory inventoryItem =
00030                   (Inventory)theBinding.entryToObject(dataEntry);
00031             // Get the item name and use that as the key
00032             String theItem = inventoryItem.getItemName();
00033             resultEntry.setData(theItem.getBytes());
00034         }
00035         return true;
00036     }
00037 }

Generated on Sun Dec 25 12:14:27 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2