001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005: *
006: * $Id: Part.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 Part represents the combined key/data pair for a part entity.
019: *
020: * <p> In this sample, Part 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)
025: * are transient and are set by the binding after the data object has been
026: * deserialized. This avoids the use of a PartData 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 Part implements Serializable, MarshalledTupleKeyEntity {
034:
035: private transient String number;
036: private String name;
037: private String color;
038: private Weight weight;
039: private String city;
040:
041: public Part(String number, String name, String color,
042: Weight weight, String city) {
043:
044: this .number = number;
045: this .name = name;
046: this .color = color;
047: this .weight = weight;
048: this .city = city;
049: }
050:
051: public final String getNumber() {
052:
053: return number;
054: }
055:
056: public final String getName() {
057:
058: return name;
059: }
060:
061: public final String getColor() {
062:
063: return color;
064: }
065:
066: public final Weight getWeight() {
067:
068: return weight;
069: }
070:
071: public final String getCity() {
072:
073: return city;
074: }
075:
076: public String toString() {
077:
078: return "[Part: number=" + number + " name=" + name + " color="
079: + color + " weight=" + weight + " city=" + city + ']';
080: }
081:
082: // --- MarshalledTupleKeyEntity implementation ---
083:
084: public void marshalPrimaryKey(TupleOutput keyOutput) {
085:
086: keyOutput.writeString(this .number);
087: }
088:
089: public void unmarshalPrimaryKey(TupleInput keyInput) {
090:
091: this .number = keyInput.readString();
092: }
093:
094: public boolean marshalSecondaryKey(String keyName,
095: TupleOutput keyOutput) {
096:
097: throw new UnsupportedOperationException(keyName);
098: }
099:
100: public boolean nullifyForeignKey(String keyName) {
101:
102: throw new UnsupportedOperationException(keyName);
103: }
104: }
|