com.sleepycat.je.dbi
Class DupKeyData

java.lang.Object
  extended by com.sleepycat.je.dbi.DupKeyData

public class DupKeyData
extends Object

Utility methods for combining, splitting and comparing two-part key values for duplicates databases. At the Btree storage level, for the key/data pairs in a duplicates database, the data is always zero length and the key is a two-part key. The 'key' parameter in the API is the first part of the key. The the 'data' parameter in the API is the second part of the key. The length of the first part is stored at the end of the combined key as a packed integer, so that the two parts can be split, combined, and compared separately. The length is stored at the end, rather than the start, to enable key prefixing for the first part, e.g., for Strings with different lengths but common prefixes.


Nested Class Summary
static class DupKeyData.NextNoDupComparator
          Used to perform the getNextNoDup operation.
static class DupKeyData.PutNoOverwriteComparator
          Used to perform the putNoOverwrite operation.
static class DupKeyData.TwoPartKeyComparator
          Comparator that compares the combined key/data two-part key, calling the user-defined btree and duplicate comparator as needed.
 
Constructor Summary
DupKeyData()
           
 
Method Summary
static byte[] combine(byte[] key, byte[] data)
           
static byte[] combine(byte[] key, int keyOff, int keySize, byte[] data, int dataOff, int dataSize)
           
static DatabaseEntry combine(DatabaseEntry paramKey, DatabaseEntry paramData)
          Returns twoPartKey as: paramKey bytes, paramData bytes, reverse-packed len of paramKey bytes.
static int compareMainKey(byte[] keyBytes1, byte[] keyBytes2, Comparator<byte[]> btreeComparator)
          Compares the first part of the two keys.
static int compareMainKey(byte[] keyBytes1, byte[] keyBytes2, int keyOff2, int keySize2, Comparator<byte[]> btreeComparator)
          Compares the first part of the two keys.
static byte[] makePrefixKey(byte[] key, int keyOff, int keySize)
          Returns a two-part key entry with the given key portion, no data, and the special PREFIX_ONLY value for the key length.
static DatabaseEntry removeData(byte[] twoPartKey)
          Splits twoPartKey and returns a two-part key entry containing the key portion from twoPartKey, no data, and the special PREFIX_ONLY value for the key length.
static byte[] replaceData(byte[] twoPartKey, byte[] newData)
          Splits twoPartKey and returns a two-part key entry containing the key portion of twoPartKey combined with newData.
static void split(byte[] twoPartKey, int twoPartKeySize, DatabaseEntry paramKey, DatabaseEntry paramData)
          Same as split method above, but with twoPartKey/twoPartKeySize byte array and array size params.
static void split(DatabaseEntry twoPartKey, DatabaseEntry paramKey, DatabaseEntry paramData)
          Splits twoPartKey, previously set by combine, into original paramKey and paramData if they are non-null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DupKeyData

public DupKeyData()
Method Detail

combine

public static DatabaseEntry combine(DatabaseEntry paramKey,
                                    DatabaseEntry paramData)
Returns twoPartKey as: paramKey bytes, paramData bytes, reverse-packed len of paramKey bytes. The byte array in the resulting twoPartKey will be copied again by JE at a lower level. It would be nice if there were a way to give ownership of the array to JE, to avoid the extra copy.


combine

public static byte[] combine(byte[] key,
                             byte[] data)

combine

public static byte[] combine(byte[] key,
                             int keyOff,
                             int keySize,
                             byte[] data,
                             int dataOff,
                             int dataSize)

split

public static void split(DatabaseEntry twoPartKey,
                         DatabaseEntry paramKey,
                         DatabaseEntry paramData)
Splits twoPartKey, previously set by combine, into original paramKey and paramData if they are non-null. The offset of the twoPartKey must be zero. This can be assumed because the entry is read from the database and JE always returns entries with a zero offset. This method copies the bytes into to new arrays rather than using the DatabaseEntry offset and size to shared the array, to keep with the convention that JE always returns whole arrays. It would be nice to avoid the copy, but that might break user apps.


split

public static void split(byte[] twoPartKey,
                         int twoPartKeySize,
                         DatabaseEntry paramKey,
                         DatabaseEntry paramData)
Same as split method above, but with twoPartKey/twoPartKeySize byte array and array size params.


replaceData

public static byte[] replaceData(byte[] twoPartKey,
                                 byte[] newData)
Splits twoPartKey and returns a two-part key entry containing the key portion of twoPartKey combined with newData.


removeData

public static DatabaseEntry removeData(byte[] twoPartKey)
Splits twoPartKey and returns a two-part key entry containing the key portion from twoPartKey, no data, and the special PREFIX_ONLY value for the key length. When used for a search, this will compare as less than any other entry having the same first part, i.e., in the same duplicate set.


makePrefixKey

public static byte[] makePrefixKey(byte[] key,
                                   int keyOff,
                                   int keySize)
Returns a two-part key entry with the given key portion, no data, and the special PREFIX_ONLY value for the key length. When used for a search, this will compare as less than any other entry having the same first part, i.e., in the same duplicate set.


compareMainKey

public static int compareMainKey(byte[] keyBytes1,
                                 byte[] keyBytes2,
                                 Comparator<byte[]> btreeComparator)
Compares the first part of the two keys.


compareMainKey

public static int compareMainKey(byte[] keyBytes1,
                                 byte[] keyBytes2,
                                 int keyOff2,
                                 int keySize2,
                                 Comparator<byte[]> btreeComparator)
Compares the first part of the two keys.



Copyright (c) 2004-2012 Oracle. All rights reserved.