00001
00002
00003
00004
00005
00006
00007
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;
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 }