1 4 package com.tc.objectserver.persistence.sleepycat; 5 6 import com.sleepycat.bind.EntryBinding; 7 import com.sleepycat.bind.serial.ClassCatalog; 8 import com.sleepycat.bind.serial.SerialBinding; 9 import com.sleepycat.je.DatabaseEntry; 10 import com.tc.objectserver.core.api.ManagedObject; 11 12 import java.util.HashMap ; 13 import java.util.Map ; 14 15 public class SleepycatSerializationAdapter implements SerializationAdapter { 16 17 private final ClassCatalog classCatalog; 18 private final Map entryBindings; 19 20 public SleepycatSerializationAdapter(ClassCatalog classCatalog) { 21 this.classCatalog = classCatalog; 22 this.entryBindings = new HashMap (); 23 } 24 25 public void serializeManagedObject(DatabaseEntry entry, ManagedObject mo) { 26 serialize(entry, mo, ManagedObject.class); 27 } 28 29 public void serializeString(DatabaseEntry entry, String string) { 30 serialize(entry, string, String .class); 31 } 32 33 public ManagedObject deserializeManagedObject(DatabaseEntry entry) { 34 return (ManagedObject) deserialize(entry, ManagedObject.class); 35 } 36 37 public String deserializeString(DatabaseEntry entry) { 38 return (String )deserialize(entry, String .class); 39 } 40 41 public void reset() { 42 return; 43 } 44 45 private void serialize(DatabaseEntry entry, Object o, Class clazz) { 46 getEntryBindingFor(clazz).objectToEntry(o, entry); 47 } 48 49 private Object deserialize(DatabaseEntry data, Class clazz) { 50 return getEntryBindingFor(clazz).entryToObject(data); 51 } 52 53 private EntryBinding getEntryBindingFor(Class c) { 54 EntryBinding rv = (EntryBinding) this.entryBindings.get(c); 55 if (rv == null) { 56 rv = new SerialBinding(this.classCatalog, c); 57 this.entryBindings.put(c, rv); 58 } 59 return rv; 60 } 61 62 } 63 | Popular Tags |