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

MarshalledObject.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2002-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: MarshalledObject.java,v 12.1 2005/01/31 19:27:35 mark Exp $
00008  */
00009 
00010 package com.sleepycat.bind.tuple.test;
00011 
00012 import com.sleepycat.bind.tuple.MarshalledTupleEntry;
00013 import com.sleepycat.bind.tuple.MarshalledTupleKeyEntity;
00014 import com.sleepycat.bind.tuple.TupleInput;
00015 import com.sleepycat.bind.tuple.TupleOutput;
00016 
00020 public class MarshalledObject
00021     implements MarshalledTupleEntry, MarshalledTupleKeyEntity {
00022 
00023     private String data;
00024     private String primaryKey;
00025     private String indexKey1;
00026     private String indexKey2;
00027 
00028     public MarshalledObject() {
00029     }
00030 
00031     MarshalledObject(String data, String primaryKey,
00032                      String indexKey1, String indexKey2) {
00033 
00034         this.data = data;
00035         this.primaryKey = primaryKey;
00036         this.indexKey1 = indexKey1;
00037         this.indexKey2 = indexKey2;
00038     }
00039 
00040     String getData() {
00041 
00042         return data;
00043     }
00044 
00045     String getPrimaryKey() {
00046 
00047         return primaryKey;
00048     }
00049 
00050     String getIndexKey1() {
00051 
00052         return indexKey1;
00053     }
00054 
00055     String getIndexKey2() {
00056 
00057         return indexKey2;
00058     }
00059 
00060     int expectedDataLength() {
00061 
00062         return data.length() + 1 +
00063                indexKey1.length() + 1 +
00064                indexKey2.length() + 1;
00065     }
00066 
00067     int expectedKeyLength() {
00068 
00069         return primaryKey.length() + 1;
00070     }
00071 
00072     public void marshalEntry(TupleOutput dataOutput) {
00073 
00074         dataOutput.writeString(data);
00075         dataOutput.writeString(indexKey1);
00076         dataOutput.writeString(indexKey2);
00077     }
00078 
00079     public void unmarshalEntry(TupleInput dataInput) {
00080 
00081         data = dataInput.readString();
00082         indexKey1 = dataInput.readString();
00083         indexKey2 = dataInput.readString();
00084     }
00085 
00086     public void marshalPrimaryKey(TupleOutput keyOutput) {
00087 
00088         keyOutput.writeString(primaryKey);
00089     }
00090 
00091     public void unmarshalPrimaryKey(TupleInput keyInput) {
00092 
00093         primaryKey = keyInput.readString();
00094     }
00095 
00096     public boolean marshalSecondaryKey(String keyName, TupleOutput keyOutput) {
00097 
00098         if ("1".equals(keyName)) {
00099             if (indexKey1.length() > 0) {
00100                 keyOutput.writeString(indexKey1);
00101                 return true;
00102             } else {
00103                 return false;
00104             }
00105         } else if ("2".equals(keyName)) {
00106             if (indexKey1.length() > 0) {
00107                 keyOutput.writeString(indexKey2);
00108                 return true;
00109             } else {
00110                 return false;
00111             }
00112         } else {
00113             throw new IllegalArgumentException("Unknown keyName: " + keyName);
00114         }
00115     }
00116 
00117     public boolean nullifyForeignKey(String keyName) {
00118 
00119         if ("1".equals(keyName)) {
00120             if (indexKey1.length() > 0) {
00121                 indexKey1 = "";
00122                 return true;
00123             } else {
00124                 return false;
00125             }
00126         } else if ("2".equals(keyName)) {
00127             if (indexKey1.length() > 0) {
00128                 indexKey2 = "";
00129                 return true;
00130             } else {
00131                 return false;
00132             }
00133         } else {
00134             throw new IllegalArgumentException("Unknown keyName: " + keyName);
00135         }
00136     }
00137 }
00138 

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