• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/db-4.8.30/examples_java/src/db/GettingStarted/
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2004-2009 Oracle.  All rights reserved.
5 *
6 * $Id$
7 */
8
9// File: ItemNameKeyCreator.java
10
11package db.GettingStarted;
12
13import com.sleepycat.bind.tuple.TupleBinding;
14import com.sleepycat.db.SecondaryKeyCreator;
15import com.sleepycat.db.DatabaseEntry;
16import com.sleepycat.db.DatabaseException;
17import com.sleepycat.db.SecondaryDatabase;
18
19public class ItemNameKeyCreator implements SecondaryKeyCreator {
20
21    private TupleBinding theBinding;
22
23    // Use the constructor to set the tuple binding
24    ItemNameKeyCreator(TupleBinding binding) {
25        theBinding = binding;
26    }
27
28    // Abstract method that we must implement
29    public boolean createSecondaryKey(SecondaryDatabase secDb,
30             DatabaseEntry keyEntry,    // From the primary
31             DatabaseEntry dataEntry,   // From the primary
32             DatabaseEntry resultEntry) // set the key data on this.
33         throws DatabaseException {
34
35        if (dataEntry != null) {
36            // Convert dataEntry to an Inventory object
37            Inventory inventoryItem =
38                  (Inventory)theBinding.entryToObject(dataEntry);
39            // Get the item name and use that as the key
40            String theItem = inventoryItem.getItemName();
41            resultEntry.setData(theItem.getBytes());
42        }
43        return true;
44    }
45}
46