1 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 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 (); 41 } 42 byte val = valueData.getData()[valueData.getOffset()]; 43 if (val == 0) { 44 return false; } 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 ("not supported"); 58 } 59 } 60 | Popular Tags |