• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt/router/db-4.8.30/java/src/com/sleepycat/persist/
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002-2009 Oracle.  All rights reserved.
5 *
6 * $Id$
7 */
8
9package com.sleepycat.persist;
10
11import com.sleepycat.db.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 */
23interface 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,
49                      DatabaseEntry pkey,
50                      DatabaseEntry data);
51
52    /**
53     * Returns the appropriate "value" (key, primary key, or entity) using the
54     * appropriate bindings for that purpose.
55     */
56    V entryToValue(DatabaseEntry key,
57                   DatabaseEntry pkey,
58                   DatabaseEntry data);
59
60    /**
61     * Converts an entity value to a data entry using an entity binding, or
62     * throws UnsupportedOperationException if this is not appropriate.  Called
63     * by BasicCursor.update.
64     */
65    void valueToData(V value, DatabaseEntry data);
66}
67