1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002,2008 Oracle.  All rights reserved.
5 *
6 * $Id: Part.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 Part represents the combined key/data pair for a part entity.
19 *
20 * <p> In this sample, Part 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)
25 * are transient and are set by the binding after the data object has been
26 * deserialized. This avoids the use of a PartData 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 Part implements Serializable, MarshalledTupleKeyEntity {
34
35    private transient String number;
36    private String name;
37    private String color;
38    private Weight weight;
39    private String city;
40
41    public Part(String number, String name, String color, Weight weight,
42                String city) {
43
44        this.number = number;
45        this.name = name;
46        this.color = color;
47        this.weight = weight;
48        this.city = city;
49    }
50
51    public final String getNumber() {
52
53        return number;
54    }
55
56    public final String getName() {
57
58        return name;
59    }
60
61    public final String getColor() {
62
63        return color;
64    }
65
66    public final Weight getWeight() {
67
68        return weight;
69    }
70
71    public final String getCity() {
72
73        return city;
74    }
75
76    public String toString() {
77
78        return "[Part: number=" + number +
79	    " name=" + name +
80	    " color=" + color +
81	    " weight=" + weight +
82	    " city=" + city + ']';
83    }
84
85    // --- MarshalledTupleKeyEntity implementation ---
86
87    public void marshalPrimaryKey(TupleOutput keyOutput) {
88
89        keyOutput.writeString(this.number);
90    }
91
92    public void unmarshalPrimaryKey(TupleInput keyInput) {
93
94        this.number = keyInput.readString();
95    }
96
97    public boolean marshalSecondaryKey(String keyName, TupleOutput keyOutput) {
98
99        throw new UnsupportedOperationException(keyName);
100    }
101
102    public boolean nullifyForeignKey(String keyName) {
103
104        throw new UnsupportedOperationException(keyName);
105    }
106}
107