1 8 9 package com.sleepycat.bind.serial; 10 11 import com.sleepycat.bind.tuple.TupleBase; 12 import com.sleepycat.bind.tuple.TupleInput; 13 import com.sleepycat.bind.tuple.TupleOutput; 14 import com.sleepycat.je.DatabaseEntry; 15 import com.sleepycat.je.DatabaseException; 16 import com.sleepycat.je.ForeignKeyNullifier; 17 import com.sleepycat.je.SecondaryDatabase; 18 import com.sleepycat.je.SecondaryKeyCreator; 19 20 42 public abstract class TupleSerialKeyCreator extends TupleBase 43 implements SecondaryKeyCreator, ForeignKeyNullifier { 44 45 protected SerialBinding dataBinding; 46 47 55 public TupleSerialKeyCreator(ClassCatalog classCatalog, Class dataClass) { 56 57 this(new SerialBinding(classCatalog, dataClass)); 58 } 59 60 65 public TupleSerialKeyCreator(SerialBinding dataBinding) { 66 67 this.dataBinding = dataBinding; 68 } 69 70 public boolean createSecondaryKey(SecondaryDatabase db, 72 DatabaseEntry primaryKeyEntry, 73 DatabaseEntry dataEntry, 74 DatabaseEntry indexKeyEntry) 75 throws DatabaseException { 76 77 TupleOutput output = getTupleOutput(null); 78 TupleInput primaryKeyInput = entryToInput(primaryKeyEntry); 79 Object dataInput = dataBinding.entryToObject(dataEntry); 80 if (createSecondaryKey(primaryKeyInput, dataInput, output)) { 81 outputToEntry(output, indexKeyEntry); 82 return true; 83 } else { 84 return false; 85 } 86 } 87 88 public boolean nullifyForeignKey(SecondaryDatabase db, 90 DatabaseEntry dataEntry) 91 throws DatabaseException { 92 93 Object data = dataBinding.entryToObject(dataEntry); 94 data = nullifyForeignKey(data); 95 if (data != null) { 96 dataBinding.objectToEntry(data, dataEntry); 97 return true; 98 } else { 99 return false; 100 } 101 } 102 103 121 public abstract boolean createSecondaryKey(TupleInput primaryKeyInput, 122 Object dataInput, 123 TupleOutput indexKeyOutput); 124 125 141 public Object nullifyForeignKey(Object data) { 142 143 return null; 144 } 145 } 146 | Popular Tags |