1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml">
4  <head>
5    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6    <title>Inventory.java</title>
7    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9    <link rel="start" href="index.html" title="Getting Started with Berkeley DB" />
10    <link rel="up" href="dpl_example.html" title="Chapter��6.��A DPL Example" />
11    <link rel="prev" href="dpl_example.html" title="Chapter��6.��A DPL Example" />
12    <link rel="next" href="mydbenv-persist.html" title="MyDbEnv" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">Inventory.java</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="dpl_example.html">Prev</a>��</td>
22          <th width="60%" align="center">Chapter��6.��A DPL Example</th>
23          <td width="20%" align="right">��<a accesskey="n" href="mydbenv-persist.html">Next</a></td>
24        </tr>
25      </table>
26      <hr />
27    </div>
28    <div class="sect1" lang="en" xml:lang="en">
29      <div class="titlepage">
30        <div>
31          <div>
32            <h2 class="title" style="clear: both"><a id="inventoryclass"></a>Inventory.java</h2>
33          </div>
34        </div>
35      </div>
36      <p>
37                            Our example's <code class="classname">Inventory</code>
38                            class is much like our <code class="classname">Vendor</code>
39                            class in that it is simply used to encapsulate
40                            data. However, in this case we want to be able
41                            to access objects two different ways: by
42                            product SKU and by product name.
43                    </p>
44      <p>
45                        In our data set, the product SKU is required to be
46                        unique, so we use that as the primary key. The
47                        product name, however, is not a unique value so we
48                        set this up as a secondary key.
49                    </p>
50      <p>
51                         The class appears as follows in our example:
52                    </p>
53      <pre class="programlisting">package persist.gettingStarted;
54
55import com.sleepycat.persist.model.Entity;
56import com.sleepycat.persist.model.PrimaryKey;
57import static com.sleepycat.persist.model.Relationship.*;
58import com.sleepycat.persist.model.SecondaryKey;
59
60@Entity
61public class Inventory {
62
63    // Primary key is sku
64    @PrimaryKey
65    private String sku;
66
67    // Secondary key is the itemName
68    @SecondaryKey(relate=MANY_TO_ONE)
69    private String itemName;
70
71    private String category;
72    private String vendor;
73    private int vendorInventory;
74    private float vendorPrice;
75
76    public void setSku(String data) {
77        sku = data;
78    }
79
80    public void setItemName(String data) {
81        itemName = data;
82    }
83
84    public void setCategory(String data) {
85        category = data;
86    }
87
88    public void setVendorInventory(int data) {
89        vendorInventory = data;
90    }
91
92    public void setVendor(String data) {
93        vendor = data;
94    }
95
96    public void setVendorPrice(float data) {
97        vendorPrice = data;
98    }
99
100    public String getSku() {
101        return sku;
102    }
103
104    public String getItemName() {
105        return itemName;
106    }
107
108    public String getCategory() {
109        return category;
110    }
111
112    public int getVendorInventory() {
113        return vendorInventory;
114    }
115
116    public String getVendor() {
117        return vendor;
118    }
119
120    public float getVendorPrice() {
121        return vendorPrice;
122    }
123} </pre>
124    </div>
125    <div class="navfooter">
126      <hr />
127      <table width="100%" summary="Navigation footer">
128        <tr>
129          <td width="40%" align="left"><a accesskey="p" href="dpl_example.html">Prev</a>��</td>
130          <td width="20%" align="center">
131            <a accesskey="u" href="dpl_example.html">Up</a>
132          </td>
133          <td width="40%" align="right">��<a accesskey="n" href="mydbenv-persist.html">Next</a></td>
134        </tr>
135        <tr>
136          <td width="40%" align="left" valign="top">Chapter��6.��A DPL Example��</td>
137          <td width="20%" align="center">
138            <a accesskey="h" href="index.html">Home</a>
139          </td>
140          <td width="40%" align="right" valign="top">��MyDbEnv</td>
141        </tr>
142      </table>
143    </div>
144  </body>
145</html>
146