KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > bind > serial > TupleSerialMarshalledKeyCreator


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2000,2006 Oracle. All rights reserved.
5  *
6  * $Id: TupleSerialMarshalledKeyCreator.java,v 1.25 2006/10/30 21:14:08 bostic Exp $
7  */

8
9 package com.sleepycat.bind.serial;
10
11 import com.sleepycat.bind.tuple.MarshalledTupleKeyEntity;
12 import com.sleepycat.bind.tuple.TupleInput;
13 import com.sleepycat.bind.tuple.TupleOutput;
14
15 /**
16  * A concrete key creator that works in conjunction with a {@link
17  * TupleSerialMarshalledBinding}. This key creator works by calling the
18  * methods of the {@link MarshalledTupleKeyEntity} interface to create and
19  * clear the index key fields.
20  *
21  * @author Mark Hayes
22  */

23 public class TupleSerialMarshalledKeyCreator extends TupleSerialKeyCreator {
24
25     private TupleSerialMarshalledBinding binding;
26     private String JavaDoc keyName;
27
28     /**
29      * Creates a tuple-serial marshalled key creator.
30      *
31      * @param binding is the binding used for the tuple-serial entity.
32      *
33      * @param keyName is the key name passed to the {@link
34      * MarshalledTupleKeyEntity#marshalSecondaryKey} method to identify the
35      * index key.
36      */

37     public TupleSerialMarshalledKeyCreator(TupleSerialMarshalledBinding
38                                            binding,
39                                            String JavaDoc keyName) {
40
41         super(binding.dataBinding);
42         this.binding = binding;
43         this.keyName = keyName;
44
45         if (dataBinding == null) {
46             throw new NullPointerException JavaDoc("dataBinding may not be null");
47         }
48     }
49
50     // javadoc is inherited
51
public boolean createSecondaryKey(TupleInput primaryKeyInput,
52                                       Object JavaDoc dataInput,
53                                       TupleOutput indexKeyOutput) {
54
55         /*
56          * The primary key is unmarshalled before marshalling the index key, to
57          * account for cases where the index key includes fields taken from the
58          * primary key.
59          */

60         MarshalledTupleKeyEntity entity = (MarshalledTupleKeyEntity)
61             binding.entryToObject(primaryKeyInput, dataInput);
62
63         return entity.marshalSecondaryKey(keyName, indexKeyOutput);
64     }
65
66     // javadoc is inherited
67
public Object JavaDoc nullifyForeignKey(Object JavaDoc dataInput) {
68
69         MarshalledTupleKeyEntity entity = (MarshalledTupleKeyEntity)
70             binding.entryToObject(null, dataInput);
71
72         return entity.nullifyForeignKey(keyName) ? dataInput : null;
73     }
74 }
75
Popular Tags