Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

TupleSerialKeyCreator.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2000-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: TupleSerialKeyCreator.java,v 12.2 2005/08/01 20:25:08 mark Exp $
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     // javadoc is inherited
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     // javadoc is inherited
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 }

Generated on Sun Dec 25 12:14:30 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2