01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: TestKeyCreator.java,v 1.24.2.2 2008/01/07 15:14:24 cwl Exp $
07: */
08:
09: 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, DatabaseEntry valueData,
32: DatabaseEntry indexKeyData) throws DatabaseException {
33:
34: if (valueData.getSize() == 0) {
35: return false;
36: }
37: if (valueData.getSize() != 1) {
38: throw new IllegalStateException();
39: }
40: byte val = valueData.getData()[valueData.getOffset()];
41: if (val == 0) {
42: return false; // fixed-len pad value
43: }
44: val -= 100;
45: if (isRecNum) {
46: RecordNumberBinding.recordNumberToEntry(val, indexKeyData);
47: } else {
48: indexKeyData.setData(new byte[] { val }, 0, 1);
49: }
50: return true;
51: }
52:
53: public void clearIndexKey(DatabaseEntry valueData) {
54:
55: throw new RuntimeException("not supported");
56: }
57: }
|