1 8 9 package com.sleepycat.persist; 10 11 import com.sleepycat.bind.EntityBinding; 12 import com.sleepycat.je.DatabaseEntry; 13 14 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, 26 boolean isSecondary) { 27 this.entityBinding = entityBinding; 28 this.isSecondary = isSecondary; 29 } 30 31 public DatabaseEntry initKey() { 32 return new DatabaseEntry(); 33 } 34 35 public DatabaseEntry initPKey() { 36 return isSecondary ? (new DatabaseEntry()) : null; 37 } 38 39 public DatabaseEntry initData() { 40 return new DatabaseEntry(); 41 } 42 43 public void clearEntries(DatabaseEntry key, 44 DatabaseEntry pkey, 45 DatabaseEntry data) { 46 key.setData(null); 47 if (isSecondary) { 48 pkey.setData(null); 49 } 50 data.setData(null); 51 } 52 53 public V entryToValue(DatabaseEntry key, 54 DatabaseEntry pkey, 55 DatabaseEntry data) { 56 return (V) entityBinding.entryToObject(isSecondary ? pkey : key, data); 57 } 58 59 public void valueToData(V value, DatabaseEntry data) { 60 entityBinding.objectToData(value, data); 61 } 62 } 63 | Popular Tags |