Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

Shipment.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2002-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: Shipment.java,v 12.2 2005/06/16 20:22:40 bostic Exp $
00008  */
00009 
00010 package collections.ship.marshal;
00011 
00012 import java.io.Serializable;
00013 
00014 import com.sleepycat.bind.tuple.TupleInput;
00015 import com.sleepycat.bind.tuple.TupleOutput;
00016 
00034 public class Shipment implements Serializable, MarshalledEnt {
00035 
00036     static final String PART_KEY = "part";
00037     static final String SUPPLIER_KEY = "supplier";
00038 
00039     private transient String partNumber;
00040     private transient String supplierNumber;
00041     private int quantity;
00042 
00043     public Shipment(String partNumber, String supplierNumber, int quantity) {
00044 
00045         this.partNumber = partNumber;
00046         this.supplierNumber = supplierNumber;
00047         this.quantity = quantity;
00048     }
00049 
00054     void setKey(String partNumber, String supplierNumber) {
00055 
00056         this.partNumber = partNumber;
00057         this.supplierNumber = supplierNumber;
00058     }
00059 
00060     public final String getPartNumber() {
00061 
00062         return partNumber;
00063     }
00064 
00065     public final String getSupplierNumber() {
00066 
00067         return supplierNumber;
00068     }
00069 
00070     public final int getQuantity() {
00071 
00072         return quantity;
00073     }
00074 
00075     public String toString() {
00076 
00077         return "[Shipment: part=" + partNumber +
00078                 " supplier=" + supplierNumber +
00079                 " quantity=" + quantity + ']';
00080     }
00081 
00082     // --- MarshalledEnt implementation ---
00083 
00084     Shipment() {
00085 
00086         // A no-argument constructor is necessary only to allow the binding to
00087         // instantiate objects of this class.
00088     }
00089 
00090     public void unmarshalPrimaryKey(TupleInput keyInput) {
00091 
00092         this.partNumber = keyInput.readString();
00093         this.supplierNumber = keyInput.readString();
00094     }
00095 
00096     public void marshalPrimaryKey(TupleOutput keyOutput) {
00097 
00098         keyOutput.writeString(this.partNumber);
00099         keyOutput.writeString(this.supplierNumber);
00100     }
00101 
00102     public boolean marshalSecondaryKey(String keyName, TupleOutput keyOutput) {
00103 
00104         if (keyName.equals(PART_KEY)) {
00105             keyOutput.writeString(this.partNumber);
00106             return true;
00107         } else if (keyName.equals(SUPPLIER_KEY)) {
00108             keyOutput.writeString(this.supplierNumber);
00109             return true;
00110         } else {
00111             throw new UnsupportedOperationException(keyName);
00112         }
00113     }
00114 }

Generated on Sun Dec 25 12:14:27 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2