1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002,2008 Oracle.  All rights reserved.
5 *
6 * $Id: Supplier.java,v 12.7 2008/01/08 20:58:29 bostic Exp $
7 */
8
9package collections.ship.factory;
10
11import java.io.Serializable;
12
13import com.sleepycat.bind.tuple.MarshalledTupleKeyEntity;
14import com.sleepycat.bind.tuple.TupleInput;
15import com.sleepycat.bind.tuple.TupleOutput;
16
17/**
18 * A Supplier represents the combined key/data pair for a supplier entity.
19 *
20 * <p> In this sample, Supplier is bound to the stored key/data entry by
21 * implementing the MarshalledTupleKeyEntity interface. </p>
22 *
23 * <p> The binding is "tricky" in that it uses this class for both the stored
24 * data entry and the combined entity object.  To do this, the key field(s) are
25 * transient and are set by the binding after the data object has been
26 * deserialized. This avoids the use of a SupplierData class completely. </p>
27 *
28 * <p> Since this class is used directly for data storage, it must be
29 * Serializable. </p>
30 *
31 * @author Mark Hayes
32 */
33public class Supplier implements Serializable, MarshalledTupleKeyEntity {
34
35    static final String CITY_KEY = "city";
36
37    private transient String number;
38    private String name;
39    private int status;
40    private String city;
41
42    public Supplier(String number, String name, int status, String city) {
43
44        this.number = number;
45        this.name = name;
46        this.status = status;
47        this.city = city;
48    }
49
50    public final String getNumber() {
51
52        return number;
53    }
54
55    public final String getName() {
56
57        return name;
58    }
59
60    public final int getStatus() {
61
62        return status;
63    }
64
65    public final String getCity() {
66
67        return city;
68    }
69
70    public String toString() {
71
72        return "[Supplier: number=" + number +
73	    " name=" + name +
74	    " status=" + status +
75	    " city=" + city + ']';
76    }
77
78    // --- MarshalledTupleKeyEntity implementation ---
79
80    public void marshalPrimaryKey(TupleOutput keyOutput) {
81
82        keyOutput.writeString(this.number);
83    }
84
85    public void unmarshalPrimaryKey(TupleInput keyInput) {
86
87        this.number = keyInput.readString();
88    }
89
90    public boolean marshalSecondaryKey(String keyName, TupleOutput keyOutput) {
91
92        if (keyName.equals(CITY_KEY)) {
93            if (this.city != null) {
94                keyOutput.writeString(this.city);
95                return true;
96            } else {
97                return false;
98            }
99        } else {
100            throw new UnsupportedOperationException(keyName);
101        }
102    }
103
104    public boolean nullifyForeignKey(String keyName) {
105
106        throw new UnsupportedOperationException(keyName);
107    }
108}
109