01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: ValueAdapter.java,v 1.5.2.2 2008/01/07 15:14:18 cwl Exp $
07: */
08:
09: package com.sleepycat.persist;
10:
11: import com.sleepycat.je.DatabaseEntry;
12:
13: /**
14: * An adapter that translates between database entries (key, primary key, data)
15: * and a "value", which may be either the key, primary key, or entity. This
16: * interface is used to implement a generic index and cursor (BasicIndex and
17: * BasicCursor). If we didn't use this approach, we would need separate index
18: * and cursor implementations for each type of value that can be returned. In
19: * other words, this interface is used to reduce class explosion.
20: *
21: * @author Mark Hayes
22: */
23: interface ValueAdapter<V> {
24:
25: /**
26: * Creates a DatabaseEntry for the key or returns null if the key is not
27: * needed.
28: */
29: DatabaseEntry initKey();
30:
31: /**
32: * Creates a DatabaseEntry for the primary key or returns null if the
33: * primary key is not needed.
34: */
35: DatabaseEntry initPKey();
36:
37: /**
38: * Creates a DatabaseEntry for the data or returns null if the data is not
39: * needed. BasicIndex.NO_RETURN_ENTRY may be returned if the data argument
40: * is required but we don't need it.
41: */
42: DatabaseEntry initData();
43:
44: /**
45: * Sets the data array of the given entries to null, based on knowledge of
46: * which entries are non-null and are not NO_RETURN_ENTRY.
47: */
48: void clearEntries(DatabaseEntry key, DatabaseEntry pkey,
49: DatabaseEntry data);
50:
51: /**
52: * Returns the appropriate "value" (key, primary key, or entity) using the
53: * appropriate bindings for that purpose.
54: */
55: V entryToValue(DatabaseEntry key, DatabaseEntry pkey,
56: DatabaseEntry data);
57:
58: /**
59: * Converts an entity value to a data entry using an entity binding, or
60: * throws UnsupportedOperationException if this is not appropriate. Called
61: * by BasicCursor.update.
62: */
63: void valueToData(V value, DatabaseEntry data);
64: }
|