01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: EntityValueAdapter.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.EntityBinding;
12: import com.sleepycat.je.DatabaseEntry;
13:
14: /**
15: * A ValueAdapter where the "value" is the entity.
16: *
17: * @author Mark Hayes
18: */
19: class EntityValueAdapter<V> implements ValueAdapter<V> {
20:
21: private EntityBinding entityBinding;
22: private boolean isSecondary;
23:
24: EntityValueAdapter(Class<V> entityClass,
25: EntityBinding entityBinding, boolean isSecondary) {
26: this .entityBinding = entityBinding;
27: this .isSecondary = isSecondary;
28: }
29:
30: public DatabaseEntry initKey() {
31: return new DatabaseEntry();
32: }
33:
34: public DatabaseEntry initPKey() {
35: return isSecondary ? (new DatabaseEntry()) : null;
36: }
37:
38: public DatabaseEntry initData() {
39: return new DatabaseEntry();
40: }
41:
42: public void clearEntries(DatabaseEntry key, DatabaseEntry pkey,
43: DatabaseEntry data) {
44: key.setData(null);
45: if (isSecondary) {
46: pkey.setData(null);
47: }
48: data.setData(null);
49: }
50:
51: public V entryToValue(DatabaseEntry key, DatabaseEntry pkey,
52: DatabaseEntry data) {
53: return (V) entityBinding.entryToObject(
54: isSecondary ? pkey : key, data);
55: }
56:
57: public void valueToData(V value, DatabaseEntry data) {
58: entityBinding.objectToData(value, data);
59: }
60: }
|