00001 /*- 00002 * See the file LICENSE for redistribution information. 00003 * 00004 * Copyright (c) 2000-2005 00005 * Sleepycat Software. All rights reserved. 00006 * 00007 * $Id: TupleSerialMarshalledKeyCreator.java,v 12.1 2005/01/31 19:27:30 mark Exp $ 00008 */ 00009 00010 package com.sleepycat.bind.serial; 00011 00012 import com.sleepycat.bind.tuple.MarshalledTupleKeyEntity; 00013 import com.sleepycat.bind.tuple.TupleInput; 00014 import com.sleepycat.bind.tuple.TupleOutput; 00015 00024 public class TupleSerialMarshalledKeyCreator extends TupleSerialKeyCreator { 00025 00026 private TupleSerialMarshalledBinding binding; 00027 private String keyName; 00028 00038 public TupleSerialMarshalledKeyCreator(TupleSerialMarshalledBinding 00039 binding, 00040 String keyName) { 00041 00042 super(binding.dataBinding); 00043 this.binding = binding; 00044 this.keyName = keyName; 00045 00046 if (dataBinding == null) { 00047 throw new NullPointerException("dataBinding may not be null"); 00048 } 00049 } 00050 00051 // javadoc is inherited 00052 public boolean createSecondaryKey(TupleInput primaryKeyInput, 00053 Object dataInput, 00054 TupleOutput indexKeyOutput) { 00055 00056 /* 00057 * The primary key is unmarshalled before marshalling the index key, to 00058 * account for cases where the index key includes fields taken from the 00059 * primary key. 00060 */ 00061 MarshalledTupleKeyEntity entity = (MarshalledTupleKeyEntity) 00062 binding.entryToObject(primaryKeyInput, dataInput); 00063 00064 return entity.marshalSecondaryKey(keyName, indexKeyOutput); 00065 } 00066 00067 // javadoc is inherited 00068 public Object nullifyForeignKey(Object dataInput) { 00069 00070 MarshalledTupleKeyEntity entity = (MarshalledTupleKeyEntity) 00071 binding.entryToObject(null, dataInput); 00072 00073 return entity.nullifyForeignKey(keyName) ? dataInput : null; 00074 } 00075 }