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