KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persist > gettingStarted > DataAccessor


1 package persist.gettingStarted;
2
3 import com.sleepycat.je.DatabaseException;
4 import com.sleepycat.persist.EntityStore;
5 import com.sleepycat.persist.PrimaryIndex;
6 import com.sleepycat.persist.SecondaryIndex;
7
8 public class DataAccessor {
9     // Open the indices
10
public DataAccessor(EntityStore store)
11         throws DatabaseException {
12
13         // Primary key for Inventory classes
14
inventoryBySku = store.getPrimaryIndex(
15             String JavaDoc.class, Inventory.class);
16
17         // Secondary key for Inventory classes
18
// Last field in the getSecondaryIndex() method must be
19
// the name of a class member; in this case, an Inventory.class
20
// data member.
21
inventoryByName = store.getSecondaryIndex(
22             inventoryBySku, String JavaDoc.class, "itemName");
23
24         // Primary key for Vendor class
25
vendorByName = store.getPrimaryIndex(
26             String JavaDoc.class, Vendor.class);
27     }
28
29     // Inventory Accessors
30
PrimaryIndex<String JavaDoc,Inventory> inventoryBySku;
31     SecondaryIndex<String JavaDoc,String JavaDoc,Inventory> inventoryByName;
32
33     // Vendor Accessors
34
PrimaryIndex<String JavaDoc,Vendor> vendorByName;
35 }
36
37
Popular Tags