KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > collections > test > TestKeyCreator


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

8
9 package com.sleepycat.collections.test;
10
11 import com.sleepycat.bind.RecordNumberBinding;
12 import com.sleepycat.je.DatabaseEntry;
13 import com.sleepycat.je.DatabaseException;
14 import com.sleepycat.je.SecondaryDatabase;
15 import com.sleepycat.je.SecondaryKeyCreator;
16
17 /**
18  * Unused until secondaries are available.
19  * @author Mark Hayes
20  */

21 class TestKeyCreator implements SecondaryKeyCreator {
22
23     private boolean isRecNum;
24
25     TestKeyCreator(boolean isRecNum) {
26
27         this.isRecNum = isRecNum;
28     }
29
30     public boolean createSecondaryKey(SecondaryDatabase db,
31                                       DatabaseEntry primaryKeyData,
32                                       DatabaseEntry valueData,
33                                       DatabaseEntry indexKeyData)
34         throws DatabaseException {
35
36         if (valueData.getSize() == 0) {
37             return false;
38         }
39         if (valueData.getSize() != 1) {
40             throw new IllegalStateException JavaDoc();
41         }
42         byte val = valueData.getData()[valueData.getOffset()];
43         if (val == 0) {
44             return false; // fixed-len pad value
45
}
46         val -= 100;
47         if (isRecNum) {
48             RecordNumberBinding.recordNumberToEntry(val, indexKeyData);
49         } else {
50             indexKeyData.setData(new byte[] { val }, 0, 1);
51         }
52         return true;
53     }
54
55     public void clearIndexKey(DatabaseEntry valueData) {
56
57         throw new RuntimeException JavaDoc("not supported");
58     }
59 }
60
Popular Tags