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

SerialSerialKeyCreator.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: SerialSerialKeyCreator.java,v 12.1 2005/01/31 19:27:29 mark Exp $
00008  */
00009 
00010 package com.sleepycat.bind.serial;
00011 
00012 import com.sleepycat.db.DatabaseEntry;
00013 import com.sleepycat.db.DatabaseException;
00014 import com.sleepycat.db.SecondaryDatabase;
00015 import com.sleepycat.db.SecondaryKeyCreator;
00016 
00029 public abstract class SerialSerialKeyCreator
00030     implements SecondaryKeyCreator {
00031 
00032     protected SerialBinding primaryKeyBinding;
00033     protected SerialBinding dataBinding;
00034     protected SerialBinding indexKeyBinding;
00035 
00048     public SerialSerialKeyCreator(ClassCatalog classCatalog,
00049                                   Class primaryKeyClass,
00050                                   Class dataClass,
00051                                   Class indexKeyClass) {
00052 
00053         this(new SerialBinding(classCatalog, primaryKeyClass),
00054              new SerialBinding(classCatalog, dataClass),
00055              new SerialBinding(classCatalog, indexKeyClass));
00056     }
00057 
00067     public SerialSerialKeyCreator(SerialBinding primaryKeyBinding,
00068                                   SerialBinding dataBinding,
00069                                   SerialBinding indexKeyBinding) {
00070 
00071         this.primaryKeyBinding = primaryKeyBinding;
00072         this.dataBinding = dataBinding;
00073         this.indexKeyBinding = indexKeyBinding;
00074     }
00075 
00076     // javadoc is inherited
00077     public boolean createSecondaryKey(SecondaryDatabase db,
00078                                       DatabaseEntry primaryKeyEntry,
00079                                       DatabaseEntry dataEntry,
00080                                       DatabaseEntry indexKeyEntry)
00081         throws DatabaseException {
00082 
00083         Object primaryKeyInput =
00084             primaryKeyBinding.entryToObject(primaryKeyEntry);
00085         Object dataInput = dataBinding.entryToObject(dataEntry);
00086         Object indexKey = createSecondaryKey(primaryKeyInput, dataInput);
00087         if (indexKey != null) {
00088             indexKeyBinding.objectToEntry(indexKey, indexKeyEntry);
00089             return true;
00090         } else {
00091             return false;
00092         }
00093     }
00094 
00095     // javadoc is inherited
00096     public boolean nullifyForeignKey(SecondaryDatabase db,
00097                                      DatabaseEntry dataEntry)
00098         throws DatabaseException {
00099 
00100         Object data = dataBinding.entryToObject(dataEntry);
00101         data = nullifyForeignKey(data);
00102         if (data != null) {
00103             dataBinding.objectToEntry(data, dataEntry);
00104             return true;
00105         } else {
00106             return false;
00107         }
00108     }
00109 
00122     public abstract Object createSecondaryKey(Object primaryKey, Object data);
00123 
00139     public Object nullifyForeignKey(Object data) {
00140 
00141         return null;
00142     }
00143 }

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