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


Java PrimaryIndex.put方法代码示例

本文整理汇总了Java中com.sleepycat.persist.PrimaryIndex.put方法的典型用法代码示例。如果您正苦于以下问题:Java PrimaryIndex.put方法的具体用法?Java PrimaryIndex.put怎么用?Java PrimaryIndex.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sleepycat.persist.PrimaryIndex的用法示例。


在下文中一共展示了PrimaryIndex.put方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.sleepycat.persist.PrimaryIndex; //导入方法依赖的package包/类
private void run()
    throws DatabaseException {

    PrimaryIndex<ReverseOrder,Person> index =
        store.getPrimaryIndex(ReverseOrder.class, Person.class);

    index.put(new Person("Andy"));
    index.put(new Person("Lisa"));
    index.put(new Person("Zola"));

    /* Print the entities in key order. */
    EntityCursor<Person> people = index.entities();
    try {
        for (Person person : people) {
            System.out.println(person);
        }
    } finally {
        people.close();
    }
}
 
开发者ID:prat0318,项目名称:dbms,代码行数:21,代码来源:CustomKeyOrderExample.java

示例2: readObjects

import com.sleepycat.persist.PrimaryIndex; //导入方法依赖的package包/类
@Override
void readObjects(EntityStore store, boolean doUpdate)
    throws DatabaseException {

    PrimaryIndex<Integer,ConvertExample5_Entity>
        index = store.getPrimaryIndex
            (Integer.class,
             ConvertExample5_Entity.class);
    ConvertExample5_Entity obj = index.get(99);
    TestCase.assertNotNull(obj);
    TestCase.assertEquals(99, obj.key);
    TestCase.assertNotNull(obj.cat);
    TestCase.assertEquals("Jeffry", obj.cat.name);
    TestCase.assertEquals(999, obj.cat.finickyLevel);
    TestCase.assertNotNull(obj.dog);
    TestCase.assertEquals("Nelson", obj.dog.name);
    TestCase.assertEquals(0.01, obj.dog.barkVolume);

    if (doUpdate) {
        index.put(obj);
    }
}
 
开发者ID:nologic,项目名称:nabs,代码行数:23,代码来源:EvolveClasses.java

示例3: testProxyNestedRef

import com.sleepycat.persist.PrimaryIndex; //导入方法依赖的package包/类
/**
 * A proxied object may not current contain a field that references the
 * parent proxy.  [#15815]
 */
public void testProxyNestedRef() 
    throws DatabaseException {

    open();
    PrimaryIndex<Integer,ProxyNestedRef> index = store.getPrimaryIndex
        (Integer.class, ProxyNestedRef.class);
    ProxyNestedRef entity = new ProxyNestedRef();
    entity.list.add(entity.list);
    try {
        index.put(entity);
        fail();
    } catch (IllegalArgumentException expected) {
        assertTrue(expected.getMessage().indexOf
            ("Cannot embed a reference to a proxied object") >= 0);
    }
    close();
}
 
开发者ID:nologic,项目名称:nabs,代码行数:22,代码来源:NegativeTest.java

示例4: readObjects

import com.sleepycat.persist.PrimaryIndex; //导入方法依赖的package包/类
@Override
void readObjects(EntityStore store, boolean doUpdate)
    throws DatabaseException {

    PrimaryIndex<Integer,ConvertExample4_Entity>
        index = store.getPrimaryIndex
            (Integer.class,
             ConvertExample4_Entity.class);
    ConvertExample4_Entity obj = index.get(99);
    TestCase.assertNotNull(obj);
    TestCase.assertEquals(99, obj.key);
    TestCase.assertNotNull(obj.embed);
    TestCase.assertEquals("name", obj.embed.name);

    if (doUpdate) {
        index.put(obj);
    }
}
 
开发者ID:nologic,项目名称:nabs,代码行数:19,代码来源:EvolveClasses.java

示例5: readObjects

import com.sleepycat.persist.PrimaryIndex; //导入方法依赖的package包/类
@Override
void readObjects(EntityStore store, boolean doUpdate)
    throws DatabaseException {

    PrimaryIndex<Integer,InsertSuperclass2_Top>
        index = store.getPrimaryIndex
            (Integer.class,
             InsertSuperclass2_Top.class);
    InsertSuperclass2_Top obj = index.get(key);
    TestCase.assertNotNull(obj);
    TestCase.assertNotNull(obj.embed);
    TestCase.assertEquals(99, obj.key);
    TestCase.assertEquals(88, obj.ff);
    TestCase.assertEquals(123, obj.embed.f);
    TestCase.assertEquals(456, obj.embed.g);
    if (doUpdate) {
        index.put(obj);
    }
}
 
开发者ID:nologic,项目名称:nabs,代码行数:20,代码来源:EvolveClasses.java

示例6: testReadOnly

import com.sleepycat.persist.PrimaryIndex; //导入方法依赖的package包/类
public void testReadOnly()
    throws DatabaseException {

    open();
    PrimaryIndex<Integer,SharedSequenceEntity1> priIndex =
        store.getPrimaryIndex(Integer.class, SharedSequenceEntity1.class);
    Transaction txn = txnBegin();
    SharedSequenceEntity1 e = new SharedSequenceEntity1();
    priIndex.put(txn, e);
    assertEquals(1, e.key);
    txnCommit(txn);
    close();

    /*
     * Check that we can open the store read-only and read the records
     * written above.
     */
    openReadOnly();
    priIndex =
        store.getPrimaryIndex(Integer.class, SharedSequenceEntity1.class);
    e = priIndex.get(1);
    assertNotNull(e);
    close();
}
 
开发者ID:nologic,项目名称:nabs,代码行数:25,代码来源:OperationTest.java

示例7: testSeparateSequence

import com.sleepycat.persist.PrimaryIndex; //导入方法依赖的package包/类
public void testSeparateSequence()
    throws DatabaseException {

    open();

    PrimaryIndex<Integer,SeparateSequenceEntity1> priIndex1 =
        store.getPrimaryIndex
            (Integer.class, SeparateSequenceEntity1.class);

    PrimaryIndex<Integer,SeparateSequenceEntity2> priIndex2 =
        store.getPrimaryIndex
            (Integer.class, SeparateSequenceEntity2.class);

    Transaction txn = txnBegin();
    SeparateSequenceEntity1 e1 = new SeparateSequenceEntity1();
    SeparateSequenceEntity2 e2 = new SeparateSequenceEntity2();
    priIndex1.put(txn, e1);
    assertEquals(1, e1.key);
    priIndex2.putNoOverwrite(txn, e2);
    assertEquals(Integer.valueOf(1), e2.key);
    e1.key = 0;
    priIndex1.putNoOverwrite(txn, e1);
    assertEquals(2, e1.key);
    e2.key = null;
    priIndex2.put(txn, e2);
    assertEquals(Integer.valueOf(2), e2.key);
    txnCommit(txn);

    close();
}
 
开发者ID:nologic,项目名称:nabs,代码行数:31,代码来源:OperationTest.java

示例8: testSharedSequence

import com.sleepycat.persist.PrimaryIndex; //导入方法依赖的package包/类
public void testSharedSequence() 
    throws DatabaseException {

    open();

    PrimaryIndex<Integer,SharedSequenceEntity1> priIndex1 =
        store.getPrimaryIndex(Integer.class, SharedSequenceEntity1.class);

    PrimaryIndex<Integer,SharedSequenceEntity2> priIndex2 =
        store.getPrimaryIndex(Integer.class, SharedSequenceEntity2.class);

    Transaction txn = txnBegin();
    SharedSequenceEntity1 e1 = new SharedSequenceEntity1();
    SharedSequenceEntity2 e2 = new SharedSequenceEntity2();
    priIndex1.put(txn, e1);
    assertEquals(1, e1.key);
    priIndex2.putNoOverwrite(txn, e2);
    assertEquals(Integer.valueOf(2), e2.key);
    e1.key = 0;
    priIndex1.putNoOverwrite(txn, e1);
    assertEquals(3, e1.key);
    e2.key = null;
    priIndex2.put(txn, e2);
    assertEquals(Integer.valueOf(4), e2.key);
    txnCommit(txn);

    close();
}
 
开发者ID:nologic,项目名称:nabs,代码行数:29,代码来源:OperationTest.java

示例9: testAutoOpenRelatedEntity

import com.sleepycat.persist.PrimaryIndex; //导入方法依赖的package包/类
/**
 * When Y is opened and X has a key with relatedEntity=Y.class, X should
 * be opened automatically.  If X is not opened, foreign key constraints
 * will not be enforced. [#15358]
 */
public void testAutoOpenRelatedEntity()
    throws DatabaseException {

    PrimaryIndex<Integer,RelatedY> priY;
    PrimaryIndex<Integer,RelatedX> priX;

    /* Opening X should create (and open) Y and enforce constraints. */
    open();
    priX = store.getPrimaryIndex(Integer.class, RelatedX.class);
    PersistTestUtils.assertDbExists
        (true, env, STORE_NAME, RelatedY.class.getName(), null);
    try {
        priX.put(new RelatedX());
        fail();
    } catch (DatabaseException e) {
        assertTrue
            (e.getMessage().indexOf
             ("foreign key not allowed: it is not present") > 0);
    }
    priY = store.getPrimaryIndex(Integer.class, RelatedY.class);
    priY.put(new RelatedY());
    priX.put(new RelatedX());
    close();

    /* Delete should cascade even when X is not opened explicitly. */
    open();
    priY = store.getPrimaryIndex(Integer.class, RelatedY.class);
    assertEquals(1, priY.count());
    priY.delete(88);
    assertEquals(0, priY.count());
    priX = store.getPrimaryIndex(Integer.class, RelatedX.class);
    assertEquals(0, priX.count()); /* Failed prior to [#15358] fix. */
    close();
}
 
开发者ID:nologic,项目名称:nabs,代码行数:40,代码来源:OperationTest.java

示例10: copyRawObjects

import com.sleepycat.persist.PrimaryIndex; //导入方法依赖的package包/类
@Override
void copyRawObjects(RawStore rawStore, EntityStore newStore)
    throws DatabaseException {

    PrimaryIndex<Integer,RenamedEntity2_NewEntityName_WithRenamer>
        index = newStore.getPrimaryIndex
            (Integer.class,
             RenamedEntity2_NewEntityName_WithRenamer.class);
    RawObject raw = rawStore.getPrimaryIndex(NAME2).get(99);
    index.put((RenamedEntity2_NewEntityName_WithRenamer)
              newStore.getModel().convertRawObject(raw));
}
 
开发者ID:nologic,项目名称:nabs,代码行数:13,代码来源:EvolveClasses.java

示例11: copyRawObjects

import com.sleepycat.persist.PrimaryIndex; //导入方法依赖的package包/类
@Override
void copyRawObjects(RawStore rawStore, EntityStore newStore)
    throws DatabaseException {

    PrimaryIndex<Integer,DeleteSuperclass2_WithConverter>
        index = newStore.getPrimaryIndex
            (Integer.class,
             DeleteSuperclass2_WithConverter.class);
    RawObject raw = rawStore.getPrimaryIndex(NAME2).get(99);
    index.put((DeleteSuperclass2_WithConverter)
              newStore.getModel().convertRawObject(raw));
}
 
开发者ID:nologic,项目名称:nabs,代码行数:13,代码来源:EvolveClasses.java

示例12: copyRawObjects

import com.sleepycat.persist.PrimaryIndex; //导入方法依赖的package包/类
@Override
void copyRawObjects(RawStore rawStore, EntityStore newStore)
    throws DatabaseException {

    PrimaryIndex<Integer,DeleteEnumConstant_NoMutation>
        index = newStore.getPrimaryIndex
            (Integer.class,
             DeleteEnumConstant_NoMutation.class);
    RawObject raw = rawStore.getPrimaryIndex(NAME).get(99);
    index.put((DeleteEnumConstant_NoMutation)
              newStore.getModel().convertRawObject(raw));
}
 
开发者ID:nologic,项目名称:nabs,代码行数:13,代码来源:EvolveClasses.java

示例13: testCompositeSequence

import com.sleepycat.persist.PrimaryIndex; //导入方法依赖的package包/类
public void testCompositeSequence() 
    throws DatabaseException {

    open();

    PrimaryIndex<CompositeSequenceEntity1.Key,CompositeSequenceEntity1>
        priIndex1 =
        store.getPrimaryIndex
            (CompositeSequenceEntity1.Key.class,
             CompositeSequenceEntity1.class);

    PrimaryIndex<CompositeSequenceEntity2.Key,CompositeSequenceEntity2>
        priIndex2 =
        store.getPrimaryIndex
            (CompositeSequenceEntity2.Key.class,
             CompositeSequenceEntity2.class);

    Transaction txn = txnBegin();
    CompositeSequenceEntity1 e1 = new CompositeSequenceEntity1();
    CompositeSequenceEntity2 e2 = new CompositeSequenceEntity2();
    priIndex1.put(txn, e1);
    assertEquals(1, e1.key.key);
    priIndex2.putNoOverwrite(txn, e2);
    assertEquals(Integer.valueOf(1), e2.key.key);
    e1.key = null;
    priIndex1.putNoOverwrite(txn, e1);
    assertEquals(2, e1.key.key);
    e2.key = null;
    priIndex2.put(txn, e2);
    assertEquals(Integer.valueOf(2), e2.key.key);
    txnCommit(txn);

    EntityCursor<CompositeSequenceEntity1> c1 = priIndex1.entities();
    e1 = c1.next();
    assertEquals(2, e1.key.key);
    e1 = c1.next();
    assertEquals(1, e1.key.key);
    e1 = c1.next();
    assertNull(e1);
    c1.close();

    EntityCursor<CompositeSequenceEntity2> c2 = priIndex2.entities();
    e2 = c2.next();
    assertEquals(Integer.valueOf(2), e2.key.key);
    e2 = c2.next();
    assertEquals(Integer.valueOf(1), e2.key.key);
    e2 = c2.next();
    assertNull(e2);
    c2.close();

    close();
}
 
开发者ID:nologic,项目名称:nabs,代码行数:53,代码来源:OperationTest.java

示例14: testDeferredWrite

import com.sleepycat.persist.PrimaryIndex; //导入方法依赖的package包/类
public void testDeferredWrite()
    throws DatabaseException {

    if (envConfig.getTransactional()) {
        /* Deferred write cannot be used with transactions. */
        return;
    }
    StoreConfig storeConfig = new StoreConfig();
    storeConfig.setDeferredWrite(true);
    storeConfig.setAllowCreate(true);
    open(storeConfig);
    assertTrue(store.getConfig().getDeferredWrite());

    PrimaryIndex<Integer,MyEntity> priIndex =
        store.getPrimaryIndex(Integer.class, MyEntity.class);

    SecondaryIndex<Integer,Integer,MyEntity> secIndex =
        store.getSecondaryIndex(priIndex, Integer.class, "secKey");

    DatabaseConfig dbConfig = priIndex.getDatabase().getConfig();
    assertTrue(dbConfig.getDeferredWrite());
    dbConfig = secIndex.getDatabase().getConfig();
    assertTrue(dbConfig.getDeferredWrite());

    MyEntity e = new MyEntity();
    e.priKey = 1;
    e.secKey = 1;
    priIndex.put(e);

    EntityCursor<MyEntity> cursor = secIndex.entities();
    cursor.next();
    assertEquals(1, cursor.count());
    cursor.close();

    e.priKey = 2;
    priIndex.put(e);
    cursor = secIndex.entities();
    cursor.next();
    assertEquals(2, cursor.count());
    cursor.close();

    class MySyncHook implements Store.SyncHook {

        boolean gotFlush;
        List<Database> synced = new ArrayList<Database>();

        public void onSync(Database db, boolean flushLog) {
            synced.add(db);
            if (flushLog) {
                assertTrue(!gotFlush);
                gotFlush = true;
            }
        }
    }

    MySyncHook hook = new MySyncHook();
    Store.setSyncHook(hook);
    store.sync();
    assertTrue(hook.gotFlush);
    assertEquals(2, hook.synced.size());
    assertTrue(hook.synced.contains(priIndex.getDatabase()));
    assertTrue(hook.synced.contains(secIndex.getDatabase()));

    close();
}
 
开发者ID:nologic,项目名称:nabs,代码行数:66,代码来源:OperationTest.java


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