01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: PrimaryKeyValueAdapter.java,v 1.5.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 primary key.
16: *
17: * @author Mark Hayes
18: */
19: class PrimaryKeyValueAdapter<V> implements ValueAdapter<V> {
20:
21: private EntryBinding keyBinding;
22:
23: PrimaryKeyValueAdapter(Class<V> keyClass, EntryBinding keyBinding) {
24: this .keyBinding = keyBinding;
25: }
26:
27: public DatabaseEntry initKey() {
28: return new DatabaseEntry();
29: }
30:
31: public DatabaseEntry initPKey() {
32: return new DatabaseEntry();
33: }
34:
35: public DatabaseEntry initData() {
36: return BasicIndex.NO_RETURN_ENTRY;
37: }
38:
39: public void clearEntries(DatabaseEntry key, DatabaseEntry pkey,
40: DatabaseEntry data) {
41: key.setData(null);
42: pkey.setData(null);
43: }
44:
45: public V entryToValue(DatabaseEntry key, DatabaseEntry pkey,
46: DatabaseEntry data) {
47: return (V) keyBinding.entryToObject(pkey);
48: }
49:
50: public void valueToData(V value, DatabaseEntry data) {
51: throw new UnsupportedOperationException(
52: "Cannot change the data in a key-only index");
53: }
54: }
|