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.class</title>
7    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8    <meta name="generator" content="DocBook XSL Stylesheets V1.62.4" />
9    <link rel="home" 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="previous" 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.class</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.class</h2>
33          </div>
34        </div>
35        <div></div>
36      </div>
37      <p>
38                            Our example's <tt class="classname">Inventory</tt>
39                            class is much like our <tt class="classname">Vendor</tt>
40                            class in that it is simply used to encapsulate
41                            data. However, in this case we want to be able
42                            to access objects two different ways: by
43                            product SKU and by product name.
44                    </p>
45      <p>
46                        In our data set, the product SKU is required to be
47                        unique, so we use that as the primary key. The
48                        product name, however, is not a unique value so we
49                        set this up as a secondary key.
50                    </p>
51      <p>
52                         The class appears as follows in our example:
53                    </p>
54      <pre class="programlisting">package persist.gettingStarted;
55
56import com.sleepycat.persist.model.Entity;
57import com.sleepycat.persist.model.PrimaryKey;
58import static com.sleepycat.persist.model.Relationship.*;
59import com.sleepycat.persist.model.SecondaryKey;
60
61@Entity
62public class Inventory {
63
64    // Primary key is sku
65    @PrimaryKey
66    private String sku;
67
68    // Secondary key is the itemName
69    @SecondaryKey(relate=MANY_TO_ONE)
70    private String itemName;
71
72    private String category;
73    private String vendor;
74    private int vendorInventory;
75    private float vendorPrice;
76
77    public void setSku(String data) {
78        sku = data;
79    }
80
81    public void setItemName(String data) {
82        itemName = data;
83    }
84
85    public void setCategory(String data) {
86        category = data;
87    }
88
89    public void setVendorInventory(int data) {
90        vendorInventory = data;
91    }
92
93    public void setVendor(String data) {
94        vendor = data;
95    }
96
97    public void setVendorPrice(float data) {
98        vendorPrice = data;
99    }
100
101    public String getSku() {
102        return sku;
103    }
104
105    public String getItemName() {
106        return itemName;
107    }
108
109    public String getCategory() {
110        return category;
111    }
112
113    public int getVendorInventory() {
114        return vendorInventory;
115    }
116
117    public String getVendor() {
118        return vendor;
119    }
120
121    public float getVendorPrice() {
122        return vendorPrice;
123    }
124} </pre>
125    </div>
126    <div class="navfooter">
127      <hr />
128      <table width="100%" summary="Navigation footer">
129        <tr>
130          <td width="40%" align="left"><a accesskey="p" href="dpl_example.html">Prev</a>��</td>
131          <td width="20%" align="center">
132            <a accesskey="u" href="dpl_example.html">Up</a>
133          </td>
134          <td width="40%" align="right">��<a accesskey="n" href="mydbenv-persist.html">Next</a></td>
135        </tr>
136        <tr>
137          <td width="40%" align="left" valign="top">Chapter��6.��A DPL Example��</td>
138          <td width="20%" align="center">
139            <a accesskey="h" href="index.html">Home</a>
140          </td>
141          <td width="40%" align="right" valign="top">��MyDbEnv</td>
142        </tr>
143      </table>
144    </div>
145  </body>
146</html>
147