1 8 9 package com.sleepycat.collections; 10 11 import com.sleepycat.bind.EntryBinding; 12 import com.sleepycat.bind.serial.ClassCatalog; 13 import com.sleepycat.bind.serial.TupleSerialMarshalledBinding; 14 import com.sleepycat.bind.serial.TupleSerialMarshalledKeyCreator; 15 import com.sleepycat.bind.tuple.TupleBinding; 16 import com.sleepycat.bind.tuple.TupleMarshalledBinding; 17 import com.sleepycat.je.Database; 18 19 28 public class TupleSerialFactory { 29 30 private ClassCatalog catalog; 31 32 35 public TupleSerialFactory(ClassCatalog catalog) { 36 37 this.catalog = catalog; 38 } 39 40 43 public final ClassCatalog getCatalog() { 44 45 return catalog; 46 } 47 48 64 public StoredMap newMap(Database db, Class keyClass, Class valueBaseClass, 65 boolean writeAllowed) { 66 67 return new StoredMap(db, 68 getKeyBinding(keyClass), 69 getEntityBinding(valueBaseClass), 70 writeAllowed); 71 } 72 73 89 public StoredSortedMap newSortedMap(Database db, Class keyClass, 90 Class valueBaseClass, 91 boolean writeAllowed) { 92 93 return new StoredSortedMap(db, 94 getKeyBinding(keyClass), 95 getEntityBinding(valueBaseClass), 96 writeAllowed); 97 } 98 99 112 public TupleSerialMarshalledKeyCreator getKeyCreator(Class valueBaseClass, 113 String keyName) { 114 115 return new TupleSerialMarshalledKeyCreator( 116 getEntityBinding(valueBaseClass), 117 keyName); 118 } 119 120 private TupleSerialMarshalledBinding getEntityBinding(Class baseClass) { 121 122 return new TupleSerialMarshalledBinding(catalog, baseClass); 123 } 124 125 private EntryBinding getKeyBinding(Class keyClass) { 126 127 EntryBinding binding = TupleBinding.getPrimitiveBinding(keyClass); 128 if (binding == null) { 129 binding = new TupleMarshalledBinding(keyClass); 130 } 131 return binding; 132 } 133 } 134 135 | Popular Tags |