00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package com.sleepycat.bind.serial;
00011
00012 import com.sleepycat.bind.tuple.TupleBase;
00013 import com.sleepycat.bind.tuple.TupleInput;
00014 import com.sleepycat.bind.tuple.TupleOutput;
00015 import com.sleepycat.db.DatabaseEntry;
00016 import com.sleepycat.db.DatabaseException;
00017 import com.sleepycat.db.SecondaryDatabase;
00018 import com.sleepycat.db.SecondaryKeyCreator;
00019
00033 public abstract class TupleSerialKeyCreator extends TupleBase
00034 implements SecondaryKeyCreator {
00035
00036 protected SerialBinding dataBinding;
00037
00046 public TupleSerialKeyCreator(ClassCatalog classCatalog, Class dataClass) {
00047
00048 this(new SerialBinding(classCatalog, dataClass));
00049 }
00050
00056 public TupleSerialKeyCreator(SerialBinding dataBinding) {
00057
00058 this.dataBinding = dataBinding;
00059 }
00060
00061
00062 public boolean createSecondaryKey(SecondaryDatabase db,
00063 DatabaseEntry primaryKeyEntry,
00064 DatabaseEntry dataEntry,
00065 DatabaseEntry indexKeyEntry)
00066 throws DatabaseException {
00067
00068 TupleOutput output = getTupleOutput(null);
00069 TupleInput primaryKeyInput = entryToInput(primaryKeyEntry);
00070 Object dataInput = dataBinding.entryToObject(dataEntry);
00071 if (createSecondaryKey(primaryKeyInput, dataInput, output)) {
00072 outputToEntry(output, indexKeyEntry);
00073 return true;
00074 } else {
00075 return false;
00076 }
00077 }
00078
00079
00080 public boolean nullifyForeignKey(SecondaryDatabase db,
00081 DatabaseEntry dataEntry)
00082 throws DatabaseException {
00083
00084 Object data = dataBinding.entryToObject(dataEntry);
00085 data = nullifyForeignKey(data);
00086 if (data != null) {
00087 dataBinding.objectToEntry(data, dataEntry);
00088 return true;
00089 } else {
00090 return false;
00091 }
00092 }
00093
00112 public abstract boolean createSecondaryKey(TupleInput primaryKeyInput,
00113 Object dataInput,
00114 TupleOutput indexKeyOutput);
00115
00132 public Object nullifyForeignKey(Object data) {
00133
00134 return null;
00135 }
00136 }