001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005: *
006: * $Id: Supplier.java,v 1.16.2.2 2008/01/07 15:14:01 cwl Exp $
007: */
008:
009: package collections.ship.factory;
010:
011: import java.io.Serializable;
012:
013: import com.sleepycat.bind.tuple.MarshalledTupleKeyEntity;
014: import com.sleepycat.bind.tuple.TupleInput;
015: import com.sleepycat.bind.tuple.TupleOutput;
016:
017: /**
018: * A Supplier represents the combined key/data pair for a supplier entity.
019: *
020: * <p> In this sample, Supplier is bound to the stored key/data entry by
021: * implementing the MarshalledTupleKeyEntity interface. </p>
022: *
023: * <p> The binding is "tricky" in that it uses this class for both the stored
024: * data entry and the combined entity object. To do this, the key field(s) are
025: * transient and are set by the binding after the data object has been
026: * deserialized. This avoids the use of a SupplierData class completely. </p>
027: *
028: * <p> Since this class is used directly for data storage, it must be
029: * Serializable. </p>
030: *
031: * @author Mark Hayes
032: */
033: public class Supplier implements Serializable, MarshalledTupleKeyEntity {
034:
035: static final String CITY_KEY = "city";
036:
037: private transient String number;
038: private String name;
039: private int status;
040: private String city;
041:
042: public Supplier(String number, String name, int status, String city) {
043:
044: this .number = number;
045: this .name = name;
046: this .status = status;
047: this .city = city;
048: }
049:
050: public final String getNumber() {
051:
052: return number;
053: }
054:
055: public final String getName() {
056:
057: return name;
058: }
059:
060: public final int getStatus() {
061:
062: return status;
063: }
064:
065: public final String getCity() {
066:
067: return city;
068: }
069:
070: public String toString() {
071:
072: return "[Supplier: number=" + number + " name=" + name
073: + " status=" + status + " city=" + city + ']';
074: }
075:
076: // --- MarshalledTupleKeyEntity implementation ---
077:
078: public void marshalPrimaryKey(TupleOutput keyOutput) {
079:
080: keyOutput.writeString(this .number);
081: }
082:
083: public void unmarshalPrimaryKey(TupleInput keyInput) {
084:
085: this .number = keyInput.readString();
086: }
087:
088: public boolean marshalSecondaryKey(String keyName,
089: TupleOutput keyOutput) {
090:
091: if (keyName.equals(CITY_KEY)) {
092: if (this .city != null) {
093: keyOutput.writeString(this .city);
094: return true;
095: } else {
096: return false;
097: }
098: } else {
099: throw new UnsupportedOperationException(keyName);
100: }
101: }
102:
103: public boolean nullifyForeignKey(String keyName) {
104:
105: throw new UnsupportedOperationException(keyName);
106: }
107: }
|