本文整理汇总了Java中com.sleepycat.je.SecondaryKeyCreator类的典型用法代码示例。如果您正苦于以下问题:Java SecondaryKeyCreator类的具体用法?Java SecondaryKeyCreator怎么用?Java SecondaryKeyCreator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SecondaryKeyCreator类属于com.sleepycat.je包,在下文中一共展示了SecondaryKeyCreator类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SingleKeySecondaryDbWrap
import com.sleepycat.je.SecondaryKeyCreator; //导入依赖的package包/类
public SingleKeySecondaryDbWrap(String name, final DbWrap<?, V> primary, final Serializer<K> keySerializer) {
super(name, primary, keySerializer);
this.keyCreator = new SecondaryKeyCreator() {
public boolean createSecondaryKey(SecondaryDatabase db,
DatabaseEntry key, DatabaseEntry data, DatabaseEntry result)
throws DatabaseException {
V value = (V) primary.valueSerializer.deSerialize(data.getData());
byte[] keyValue = createKey(value);
if (keyValue != null) {
result.setData(keyValue);
return true;
}
else {
return false;
}
}
};
}
示例2: defaultSecondaryConfig
import com.sleepycat.je.SecondaryKeyCreator; //导入依赖的package包/类
/**
* Default {@link SecondaryConfig}, {allowCreate: true, sortedDuplicates: true} with given {@link SecondaryKeyCreator}
* @param keyCreator
* @return
*/
public static SecondaryConfig defaultSecondaryConfig(SecondaryKeyCreator keyCreator) {
SecondaryConfig cfg = new SecondaryConfig();
cfg.setAllowCreate(true);
//Duplicates are frequently required for secondary databases
cfg.setSortedDuplicates(true);
cfg.setTransactional(true);
cfg.setKeyCreator(checkNotNull(keyCreator, "SecondaryKeyCreator cannot be null"));
return cfg;
}
示例3: checkSecKey
import com.sleepycat.je.SecondaryKeyCreator; //导入依赖的package包/类
private void checkSecKey(MyEntity entity,
Class entityCls,
String keyName,
Object keyValue,
Class keyCls)
throws DatabaseException {
/* Get entity metadata. */
EntityMetadata entityMeta =
model.getEntityMetadata(entityCls.getName());
assertNotNull(entityMeta);
/* Get secondary key metadata. */
SecondaryKeyMetadata secKeyMeta =
entityMeta.getSecondaryKeys().get(keyName);
assertNotNull(secKeyMeta);
/* Create key creator/nullifier. */
SecondaryKeyCreator keyCreator = new PersistKeyCreator
(catalog, entityMeta, keyCls.getName(), secKeyMeta);
/* Convert entity to bytes. */
PersistEntityBinding entityBinding =
new PersistEntityBinding(catalog, entityCls.getName(), false);
entityBinding.objectToData(entity, dataEntry);
entityBinding.objectToKey(entity, keyEntry);
/* Extract secondary key bytes from entity bytes. */
DatabaseEntry secKeyEntry = new DatabaseEntry();
boolean isKeyPresent = keyCreator.createSecondaryKey
(null, keyEntry, dataEntry, secKeyEntry);
assertEquals(keyValue != null, isKeyPresent);
/* Convert secondary key bytes back to an object. */
PersistKeyBinding keyBinding =
new PersistKeyBinding(catalog, keyCls.getName(), false);
if (isKeyPresent) {
Object keyValue2 = keyBinding.entryToObject(secKeyEntry);
assertEquals(keyValue, keyValue2);
DatabaseEntry secKeyEntry2 = new DatabaseEntry();
keyBinding.objectToEntry(keyValue2, secKeyEntry2);
assertEquals(secKeyEntry, secKeyEntry2);
}
}
示例4: SimpleMultiKeyCreator
import com.sleepycat.je.SecondaryKeyCreator; //导入依赖的package包/类
SimpleMultiKeyCreator(SecondaryKeyCreator keyCreator) {
this.keyCreator = keyCreator;
}
示例5: checkSecKey
import com.sleepycat.je.SecondaryKeyCreator; //导入依赖的package包/类
private void checkSecKey(MyEntity entity,
Class entityCls,
String keyName,
Object keyValue,
Class keyCls)
throws DatabaseException {
/* Get entity metadata. */
EntityMetadata entityMeta =
model.getEntityMetadata(entityCls.getName());
assertNotNull(entityMeta);
/* Get secondary key metadata. */
SecondaryKeyMetadata secKeyMeta =
entityMeta.getSecondaryKeys().get(keyName);
assertNotNull(secKeyMeta);
/* Create key creator/nullifier. */
SecondaryKeyCreator keyCreator = new PersistKeyCreator
(catalog, entityMeta, keyCls.getName(), secKeyMeta);
/* Convert entity to bytes. */
PersistEntityBinding entityBinding =
new PersistEntityBinding(catalog, entityCls.getName(), false);
entityBinding.objectToData(entity, dataEntry);
entityBinding.objectToKey(entity, keyEntry);
/* Extract secondary key bytes from entity bytes. */
DatabaseEntry secKeyEntry = new DatabaseEntry();
boolean isKeyPresent = keyCreator.createSecondaryKey
(null, keyEntry, dataEntry, secKeyEntry);
assertEquals(keyValue != null, isKeyPresent);
/* Convert secondary key bytes back to an object. */
PersistKeyBinding keyBinding =
new PersistKeyBinding(catalog, keyCls.getName(), false);
if (isKeyPresent) {
Object keyValue2 = keyBinding.entryToObject(secKeyEntry);
assertEquals(keyValue, keyValue2);
DatabaseEntry secKeyEntry2 = new DatabaseEntry();
keyBinding.objectToEntry(keyValue2, secKeyEntry2);
assertEquals(secKeyEntry, secKeyEntry2);
}
}