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

TestKeyCreator.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: TestKeyCreator.java,v 12.1 2005/01/31 19:27:35 mark Exp $
00008  */
00009 
00010 package com.sleepycat.collections.test;
00011 
00012 import com.sleepycat.bind.RecordNumberBinding;
00013 import com.sleepycat.db.DatabaseEntry;
00014 import com.sleepycat.db.DatabaseException;
00015 import com.sleepycat.db.SecondaryDatabase;
00016 import com.sleepycat.db.SecondaryKeyCreator;
00017 
00022 class TestKeyCreator implements SecondaryKeyCreator {
00023 
00024     private boolean isRecNum;
00025 
00026     TestKeyCreator(boolean isRecNum) {
00027 
00028         this.isRecNum = isRecNum;
00029     }
00030 
00031     public boolean createSecondaryKey(SecondaryDatabase db,
00032                                       DatabaseEntry primaryKeyData,
00033                                       DatabaseEntry valueData,
00034                                       DatabaseEntry indexKeyData)
00035         throws DatabaseException {
00036 
00037         if (valueData.getSize() == 0) {
00038             return false;
00039         }
00040         if (valueData.getSize() != 1) {
00041             throw new IllegalStateException();
00042         }
00043         byte val = valueData.getData()[valueData.getOffset()];
00044         if (val == 0) {
00045             return false; // fixed-len pad value
00046         }
00047         val -= 100;
00048         if (isRecNum) {
00049             RecordNumberBinding.recordNumberToEntry(val, indexKeyData);
00050         } else {
00051             indexKeyData.setData(new byte[] { val }, 0, 1);
00052         }
00053         return true;
00054     }
00055 
00056     public void clearIndexKey(DatabaseEntry valueData) {
00057 
00058         throw new RuntimeException("not supported");
00059     }
00060 }

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