01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: DataValueAdapter.java,v 1.6.2.3 2008/01/07 15:14:18 cwl Exp $
07: */
08:
09: package com.sleepycat.persist;
10:
11: import com.sleepycat.bind.EntryBinding;
12: import com.sleepycat.je.DatabaseEntry;
13:
14: /**
15: * A ValueAdapter where the "value" is the data, although the data in this case
16: * is the primary key in a KeysIndex.
17: *
18: * @author Mark Hayes
19: */
20: class DataValueAdapter<V> implements ValueAdapter<V> {
21:
22: private EntryBinding dataBinding;
23:
24: DataValueAdapter(Class<V> keyClass, EntryBinding dataBinding) {
25: this .dataBinding = dataBinding;
26: }
27:
28: public DatabaseEntry initKey() {
29: return new DatabaseEntry();
30: }
31:
32: public DatabaseEntry initPKey() {
33: return null;
34: }
35:
36: public DatabaseEntry initData() {
37: return new DatabaseEntry();
38: }
39:
40: public void clearEntries(DatabaseEntry key, DatabaseEntry pkey,
41: DatabaseEntry data) {
42: key.setData(null);
43: data.setData(null);
44: }
45:
46: public V entryToValue(DatabaseEntry key, DatabaseEntry pkey,
47: DatabaseEntry data) {
48: return (V) dataBinding.entryToObject(data);
49: }
50:
51: public void valueToData(V value, DatabaseEntry data) {
52: throw new UnsupportedOperationException(
53: "Cannot change the data in a key-only index");
54: }
55: }
|