01: package persist.gettingStarted;
02:
03: import com.sleepycat.je.DatabaseException;
04: import com.sleepycat.persist.EntityStore;
05: import com.sleepycat.persist.PrimaryIndex;
06: import com.sleepycat.persist.SecondaryIndex;
07:
08: public class DataAccessor {
09: // Open the indices
10: public DataAccessor(EntityStore store) throws DatabaseException {
11:
12: // Primary key for Inventory classes
13: inventoryBySku = store.getPrimaryIndex(String.class,
14: Inventory.class);
15:
16: // Secondary key for Inventory classes
17: // Last field in the getSecondaryIndex() method must be
18: // the name of a class member; in this case, an Inventory.class
19: // data member.
20: inventoryByName = store.getSecondaryIndex(inventoryBySku,
21: String.class, "itemName");
22:
23: // Primary key for Vendor class
24: vendorByName = store
25: .getPrimaryIndex(String.class, Vendor.class);
26: }
27:
28: // Inventory Accessors
29: PrimaryIndex<String, Inventory> inventoryBySku;
30: SecondaryIndex<String, String, Inventory> inventoryByName;
31:
32: // Vendor Accessors
33: PrimaryIndex<String, Vendor> vendorByName;
34: }
|