1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2004-2009 Oracle. All rights reserved. 5 * 6 * $Id$ 7 */ 8 9// File: InventoryBinding.java 10 11package db.GettingStarted; 12 13import com.sleepycat.bind.tuple.TupleBinding; 14import com.sleepycat.bind.tuple.TupleInput; 15import com.sleepycat.bind.tuple.TupleOutput; 16 17public class InventoryBinding extends TupleBinding { 18 19 // Implement this abstract method. Used to convert 20 // a DatabaseEntry to an Inventory object. 21 public Object entryToObject(TupleInput ti) { 22 23 String sku = ti.readString(); 24 String itemName = ti.readString(); 25 String category = ti.readString(); 26 String vendor = ti.readString(); 27 int vendorInventory = ti.readInt(); 28 float vendorPrice = ti.readFloat(); 29 30 Inventory inventory = new Inventory(); 31 inventory.setSku(sku); 32 inventory.setItemName(itemName); 33 inventory.setCategory(category); 34 inventory.setVendor(vendor); 35 inventory.setVendorInventory(vendorInventory); 36 inventory.setVendorPrice(vendorPrice); 37 38 return inventory; 39 } 40 41 // Implement this abstract method. Used to convert a 42 // Inventory object to a DatabaseEntry object. 43 public void objectToEntry(Object object, TupleOutput to) { 44 45 Inventory inventory = (Inventory)object; 46 47 to.writeString(inventory.getSku()); 48 to.writeString(inventory.getItemName()); 49 to.writeString(inventory.getCategory()); 50 to.writeString(inventory.getVendor()); 51 to.writeInt(inventory.getVendorInventory()); 52 to.writeFloat(inventory.getVendorPrice()); 53 } 54} 55