01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2000,2008 Oracle. All rights reserved.
05: *
06: * $Id: TupleTupleBinding.java,v 1.24.2.2 2008/01/07 15:14:06 cwl Exp $
07: */
08:
09: package com.sleepycat.bind.tuple;
10:
11: import com.sleepycat.bind.EntityBinding;
12: import com.sleepycat.je.DatabaseEntry;
13:
14: /**
15: * An abstract <code>EntityBinding</code> that treats an entity's key entry and
16: * data entry as tuples.
17: *
18: * <p>This class takes care of converting the entries to/from {@link
19: * TupleInput} and {@link TupleOutput} objects. Its three abstract methods
20: * must be implemented by a concrete subclass to convert between tuples and
21: * entity objects.</p>
22: * <ul>
23: * <li> {@link #entryToObject(TupleInput,TupleInput)} </li>
24: * <li> {@link #objectToKey(Object,TupleOutput)} </li>
25: * <li> {@link #objectToData(Object,TupleOutput)} </li>
26: * </ul>
27: *
28: * @author Mark Hayes
29: */
30: public abstract class TupleTupleBinding extends TupleBase implements
31: EntityBinding {
32:
33: /**
34: * Creates a tuple-tuple entity binding.
35: */
36: public TupleTupleBinding() {
37: }
38:
39: // javadoc is inherited
40: public Object entryToObject(DatabaseEntry key, DatabaseEntry data) {
41:
42: return entryToObject(TupleBinding.entryToInput(key),
43: TupleBinding.entryToInput(data));
44: }
45:
46: // javadoc is inherited
47: public void objectToKey(Object object, DatabaseEntry key) {
48:
49: TupleOutput output = getTupleOutput(object);
50: objectToKey(object, output);
51: outputToEntry(output, key);
52: }
53:
54: // javadoc is inherited
55: public void objectToData(Object object, DatabaseEntry data) {
56:
57: TupleOutput output = getTupleOutput(object);
58: objectToData(object, output);
59: outputToEntry(output, data);
60: }
61:
62: // abstract methods
63:
64: /**
65: * Constructs an entity object from {@link TupleInput} key and data
66: * entries.
67: *
68: * @param keyInput is the {@link TupleInput} key entry object.
69: *
70: * @param dataInput is the {@link TupleInput} data entry object.
71: *
72: * @return the entity object constructed from the key and data.
73: */
74: public abstract Object entryToObject(TupleInput keyInput,
75: TupleInput dataInput);
76:
77: /**
78: * Extracts a key tuple from an entity object.
79: *
80: * @param object is the entity object.
81: *
82: * @param output is the {@link TupleOutput} to which the key should be
83: * written.
84: */
85: public abstract void objectToKey(Object object, TupleOutput output);
86:
87: /**
88: * Extracts a key tuple from an entity object.
89: *
90: * @param object is the entity object.
91: *
92: * @param output is the {@link TupleOutput} to which the data should be
93: * written.
94: */
95: public abstract void objectToData(Object object, TupleOutput output);
96: }
|