00001 /*- 00002 * See the file LICENSE for redistribution information. 00003 * 00004 * Copyright (c) 2000-2005 00005 * Sleepycat Software. All rights reserved. 00006 * 00007 * $Id: TupleTupleMarshalledKeyCreator.java,v 12.1 2005/01/31 19:27:32 mark Exp $ 00008 */ 00009 00010 package com.sleepycat.bind.tuple; 00011 00025 public class TupleTupleMarshalledKeyCreator extends TupleTupleKeyCreator { 00026 00027 private String keyName; 00028 private TupleTupleMarshalledBinding binding; 00029 00039 public TupleTupleMarshalledKeyCreator(TupleTupleMarshalledBinding binding, 00040 String keyName) { 00041 00042 this.binding = binding; 00043 this.keyName = keyName; 00044 } 00045 00046 // javadoc is inherited 00047 public boolean createSecondaryKey(TupleInput primaryKeyInput, 00048 TupleInput dataInput, 00049 TupleOutput indexKeyOutput) { 00050 00051 /* The primary key is unmarshalled before marshalling the index key, to 00052 * account for cases where the index key includes fields taken from the 00053 * primary key. 00054 */ 00055 MarshalledTupleKeyEntity entity = (MarshalledTupleKeyEntity) 00056 binding.entryToObject(primaryKeyInput, dataInput); 00057 00058 return entity.marshalSecondaryKey(keyName, indexKeyOutput); 00059 } 00060 00061 // javadoc is inherited 00062 public boolean nullifyForeignKey(TupleInput dataInput, 00063 TupleOutput dataOutput) { 00064 00065 // XXX null primary key input below may be unexpected by the binding 00066 MarshalledTupleKeyEntity entity = (MarshalledTupleKeyEntity) 00067 binding.entryToObject(null, dataInput); 00068 if (entity.nullifyForeignKey(keyName)) { 00069 binding.objectToData(entity, dataOutput); 00070 return true; 00071 } else { 00072 return false; 00073 } 00074 } 00075 }