diff options
Diffstat (limited to 'examples_java/src/db/GettingStarted/ItemNameKeyCreator.java')
-rw-r--r-- | examples_java/src/db/GettingStarted/ItemNameKeyCreator.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/examples_java/src/db/GettingStarted/ItemNameKeyCreator.java b/examples_java/src/db/GettingStarted/ItemNameKeyCreator.java new file mode 100644 index 0000000..f52834d --- /dev/null +++ b/examples_java/src/db/GettingStarted/ItemNameKeyCreator.java @@ -0,0 +1,45 @@ +/*- + * See the file LICENSE for redistribution information. + * + * Copyright (c) 2004-2009 Oracle. All rights reserved. + * + * $Id$ + */ + +// File: ItemNameKeyCreator.java + +package db.GettingStarted; + +import com.sleepycat.bind.tuple.TupleBinding; +import com.sleepycat.db.SecondaryKeyCreator; +import com.sleepycat.db.DatabaseEntry; +import com.sleepycat.db.DatabaseException; +import com.sleepycat.db.SecondaryDatabase; + +public class ItemNameKeyCreator implements SecondaryKeyCreator { + + private TupleBinding theBinding; + + // Use the constructor to set the tuple binding + ItemNameKeyCreator(TupleBinding binding) { + theBinding = binding; + } + + // Abstract method that we must implement + public boolean createSecondaryKey(SecondaryDatabase secDb, + DatabaseEntry keyEntry, // From the primary + DatabaseEntry dataEntry, // From the primary + DatabaseEntry resultEntry) // set the key data on this. + throws DatabaseException { + + if (dataEntry != null) { + // Convert dataEntry to an Inventory object + Inventory inventoryItem = + (Inventory)theBinding.entryToObject(dataEntry); + // Get the item name and use that as the key + String theItem = inventoryItem.getItemName(); + resultEntry.setData(theItem.getBytes()); + } + return true; + } +} |