当前位置: 首页>>代码示例>>Java>>正文


Java SecondaryKeyCreator类代码示例

本文整理汇总了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;
			}
		}
	};
}
 
开发者ID:mosscode,项目名称:bdbwrap,代码行数:22,代码来源:SingleKeySecondaryDbWrap.java

示例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;
}
 
开发者ID:jronrun,项目名称:benayn,代码行数:15,代码来源:Berkeley.java

示例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);
    }
}
 
开发者ID:nologic,项目名称:nabs,代码行数:45,代码来源:BindingTest.java

示例4: SimpleMultiKeyCreator

import com.sleepycat.je.SecondaryKeyCreator; //导入依赖的package包/类
SimpleMultiKeyCreator(SecondaryKeyCreator keyCreator) {
    this.keyCreator = keyCreator;
}
 
开发者ID:nologic,项目名称:nabs,代码行数:4,代码来源:MultiKeyTxnTestCase.java

示例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);
    }
}
 
开发者ID:nologic,项目名称:nabs,代码行数:45,代码来源:BindingTest.java


注:本文中的com.sleepycat.je.SecondaryKeyCreator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。