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


Java EntityCursor.next方法代码示例

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


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

示例1: containsLVRPostalCode

import com.sleepycat.persist.EntityCursor; //导入方法依赖的package包/类
/**
    * Returns true if the postal code is a large volume receiver postal code.
    * False otherwise.
    */
public boolean containsLVRPostalCode(String postalCode) throws DatabaseException {
	if (postalCode == null) return false;
	EntityCursor<LargeVolumeReceiver> cursor = largeVolumeReceiverPK.entities(postalCode, true, postalCode, true);
	try {
		if (cursor.next() != null) {
			return true;
		}
	} finally {
		cursor.close();
	}
	return false;
}
 
开发者ID:SQLPower,项目名称:power-matchmaker,代码行数:17,代码来源:AddressDatabase.java

示例2: findLargeVolumeReceiver

import com.sleepycat.persist.EntityCursor; //导入方法依赖的package包/类
/**
 * Only one large volume receiver should be found for each postal code.
 * If there is no large volume receiver for the given postal code then
 * the LVR returned will be null.
 */
public LargeVolumeReceiver findLargeVolumeReceiver(String postalCode) throws DatabaseException {
	if (postalCode == null) return null;
	EntityCursor<LargeVolumeReceiver> cursor = largeVolumeReceiverPK.entities(postalCode, true, postalCode, true);
	LargeVolumeReceiver lvr = cursor.next();
	cursor.close();
	return lvr;
}
 
开发者ID:SQLPower,项目名称:power-matchmaker,代码行数:13,代码来源:AddressDatabase.java

示例3: containsDeliveryInstallationName

import com.sleepycat.persist.EntityCursor; //导入方法依赖的package包/类
/**
 * Returns true if the database has a delivery installation with
 * the given name. Returns false otherwise.
 */
public boolean containsDeliveryInstallationName(String diName) throws DatabaseException {
	if (diName == null) return false;
	EntityCursor<PostalCode> cursor = postalCodeDIName.entities(diName, true, diName, true);
	try {
		if (cursor.next() != null) return true;
	} finally {
		cursor.close();
	}
	return false;
}
 
开发者ID:SQLPower,项目名称:power-matchmaker,代码行数:15,代码来源:AddressDatabase.java

示例4: testCursorCount

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

    open();

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

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

    Transaction txn = txnBeginCursor();

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

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

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

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

示例5: testCursorCount

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

    open();

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

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

    Transaction txn = txnBeginCursor();

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

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

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

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

示例6: removeExpiredReverse

import com.sleepycat.persist.EntityCursor; //导入方法依赖的package包/类
/**
 * Removes expired entries from the database.
*/
public void removeExpiredReverse() {

    EntityCursor<ReverseData> cursor = null;
    Transaction txn = null;
    int removedEntries = 0;
    try {
        long currentDate = Calendar.getInstance().getTimeInMillis();
        txn = environment.beginTransaction(null, null);
        cursor = dnsCacheAccessor.reversePrimaryIndex.entities(txn, null);

        for (ReverseData entity = cursor.first(); entity != null;
            entity = cursor.next()) {

            if (currentDate > entity.getExpirationDate()) {
                cursor.delete();
                removedEntries++;
            }
        }

        txn.commit();
    } catch (DatabaseException ex) {
        LOG.error("Expired reverse dns data cleanup has failed.", ex);
        if (txn != null) txn.abort();
    } finally {
        if (cursor != null) cursor.close();
    }
}
 
开发者ID:MTA-SZTAKI,项目名称:longneck-dns,代码行数:31,代码来源:DnsCache.java

示例7: getCacheCoverage

import com.sleepycat.persist.EntityCursor; //导入方法依赖的package包/类
public BufferedImage getCacheCoverage(int zoom, Point tileNumMin, Point tileNumMax) throws DatabaseException,
		InterruptedException {
	log.debug("Loading cache coverage for region " + tileNumMin + " " + tileNumMax + " of zoom level " + zoom);
	DelayedInterruptThread t = (DelayedInterruptThread) Thread.currentThread();
	int width = tileNumMax.x - tileNumMin.x + 1;
	int height = tileNumMax.y - tileNumMin.y + 1;
	byte ff = (byte) 0xFF;
	byte[] colors = new byte[] { 120, 120, 120, 120, // alpha-gray
			10, ff, 0, 120 // alpha-green
	};
	IndexColorModel colorModel = new IndexColorModel(2, 2, colors, 0, true);
	BufferedImage image = null;
	try {
		image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, colorModel);
	} catch (Throwable e) {
		log.error("Failed to create coverage image: " + e.toString());
		image = null;
		System.gc();
		return null;
	}
	WritableRaster raster = image.getRaster();

	// We are loading the coverage of the selected area column by column which is much faster than loading the
	// whole region at once
	for (int x = tileNumMin.x; x <= tileNumMax.x; x++) {
		TileDbKey fromKey = new TileDbKey(x, tileNumMin.y, zoom);
		TileDbKey toKey = new TileDbKey(x, tileNumMax.y, zoom);
		EntityCursor<TileDbKey> cursor = tileIndex.keys(fromKey, true, toKey, true);
		try {
			TileDbKey key = cursor.next();
			while (key != null) {
				int pixelx = key.x - tileNumMin.x;
				int pixely = key.y - tileNumMin.y;
				raster.setSample(pixelx, pixely, 0, 1);
				key = cursor.next();
				if (t.isInterrupted()) {
					log.debug("Cache coverage loading aborted");
					throw new InterruptedException();
				}
			}
		} finally {
			cursor.close();
		}
	}
	return image;
}
 
开发者ID:bh4017,项目名称:mobac,代码行数:47,代码来源:BerkeleyDbTileStore.java

示例8: testSubclassIndex

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

    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    env = new Environment(envHome, envConfig);

    StoreConfig storeConfig = new StoreConfig();
    storeConfig.setAllowCreate(true);
    EntityStore store = new EntityStore(env, "foo", storeConfig);

    PrimaryIndex<String, Employee> employeesById =
        store.getPrimaryIndex(String.class, Employee.class);

    employeesById.put(new Employee("1"));
    employeesById.put(new Manager("2", "a"));
    employeesById.put(new Manager("3", "a"));
    employeesById.put(new Manager("4", "b"));

    Employee e;
    Manager m;

    e = employeesById.get("1");
    assertNotNull(e);
    assertTrue(!(e instanceof Manager));

    /* Ensure DB exists BEFORE calling getSubclassIndex. [#15247] */
    PersistTestUtils.assertDbExists
        (true, env, "foo", Employee.class.getName(), "dept");

    /* Normal use: Subclass index for a key in the subclass. */
    SecondaryIndex<String, String, Manager> managersByDept =
        store.getSubclassIndex
            (employeesById, Manager.class, String.class, "dept");

    m = managersByDept.get("a");
    assertNotNull(m);
    assertEquals("2", m.id);

    m = managersByDept.get("b");
    assertNotNull(m);
    assertEquals("4", m.id);

    EntityCursor<Manager> managers = managersByDept.entities();
    try {
        m = managers.next();
        assertNotNull(m);
        assertEquals("2", m.id);
        m = managers.next();
        assertNotNull(m);
        assertEquals("3", m.id);
        m = managers.next();
        assertNotNull(m);
        assertEquals("4", m.id);
        m = managers.next();
        assertNull(m);
    } finally {
        managers.close();
    }

    /* Getting a subclass index for the entity class is also allowed. */
    store.getSubclassIndex
        (employeesById, Employee.class, String.class, "other");

    /* Getting a subclass index for a base class key is not allowed. */
    try {
        store.getSubclassIndex
            (employeesById, Manager.class, String.class, "other");
        fail();
    } catch (IllegalArgumentException expected) {
    }

    store.close();
    env.close();
    env = null;
}
 
开发者ID:nologic,项目名称:nabs,代码行数:77,代码来源:SubclassIndexTest.java

示例9: testDeleteFromSubIndex

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

    open();

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

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

    Transaction txn = txnBegin();
    MyEntity e = new MyEntity();
    e.secKey = 1;
    e.priKey = 1;
    priIndex.put(txn, e);
    e.priKey = 2;
    priIndex.put(txn, e);
    e.priKey = 3;
    priIndex.put(txn, e);
    e.priKey = 4;
    priIndex.put(txn, e);
    txnCommit(txn);

    EntityIndex<Integer,MyEntity> subIndex = secIndex.subIndex(1);
    txn = txnBeginCursor();
    e = subIndex.get(txn, 1, null);
    assertEquals(1, e.priKey);
    assertEquals(Integer.valueOf(1), e.secKey);
    e = subIndex.get(txn, 2, null);
    assertEquals(2, e.priKey);
    assertEquals(Integer.valueOf(1), e.secKey);
    e = subIndex.get(txn, 3, null);
    assertEquals(3, e.priKey);
    assertEquals(Integer.valueOf(1), e.secKey);
    e = subIndex.get(txn, 5, null);
    assertNull(e);

    boolean deleted = subIndex.delete(txn, 1);
    assertTrue(deleted);
    assertNull(subIndex.get(txn, 1, null));
    assertNotNull(subIndex.get(txn, 2, null));

    EntityCursor<MyEntity> cursor = subIndex.entities(txn, null);
    boolean saw4 = false;
    for (MyEntity e2 = cursor.first(); e2 != null; e2 = cursor.next()) {
        if (e2.priKey == 3) {
            cursor.delete();
        }
        if (e2.priKey == 4) {
            saw4 = true;
        }
    }
    cursor.close();
    assertTrue(saw4);
    assertNull(subIndex.get(txn, 1, null));
    assertNull(subIndex.get(txn, 3, null));
    assertNotNull(subIndex.get(txn, 2, null));
    assertNotNull(subIndex.get(txn, 4, null));

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

示例10: testCompositeSequence

import com.sleepycat.persist.EntityCursor; //导入方法依赖的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

示例11: testDeferredWrite

import com.sleepycat.persist.EntityCursor; //导入方法依赖的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

示例12: testSubclassIndex

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

    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    env = new Environment(envHome, envConfig);

    StoreConfig storeConfig = new StoreConfig();
    storeConfig.setAllowCreate(true);
    EntityStore store = new EntityStore(env, "foo", storeConfig);

    PrimaryIndex<String, Employee> employeesById =
        store.getPrimaryIndex(String.class, Employee.class);

    employeesById.put(new Employee("1"));
    employeesById.put(new Manager("2", "a"));
    employeesById.put(new Manager("3", "a"));
    employeesById.put(new Manager("4", "b"));

    Employee e;
    Manager m;

    e = employeesById.get("1");
    assertNotNull(e);
    assertTrue(!(e instanceof Manager));

    /* Ensure DB exists BEFORE calling getSubclassIndex. [#15247] */
    PersistTestUtils.assertDbExists
        (true, env, "foo", Employee.class.getName(), "dept");

    /* Normal use: Subclass index for a key in the subclass. */
    SecondaryIndex<String, String, Manager> managersByDept =
        store.getSubclassIndex
            (employeesById, Manager.class, String.class, "dept"); 

    m = managersByDept.get("a");
    assertNotNull(m);
    assertEquals("2", m.id);

    m = managersByDept.get("b");
    assertNotNull(m);
    assertEquals("4", m.id);

    EntityCursor<Manager> managers = managersByDept.entities();
    try {
        m = managers.next();
        assertNotNull(m);
        assertEquals("2", m.id);
        m = managers.next();
        assertNotNull(m);
        assertEquals("3", m.id);
        m = managers.next();
        assertNotNull(m);
        assertEquals("4", m.id);
        m = managers.next();
        assertNull(m);
    } finally {
        managers.close();
    }

    /* Getting a subclass index for the entity class is also allowed. */
    store.getSubclassIndex
        (employeesById, Employee.class, String.class, "other"); 

    /* Getting a subclass index for a base class key is not allowed. */
    try {
        store.getSubclassIndex
            (employeesById, Manager.class, String.class, "other"); 
        fail();
    } catch (IllegalArgumentException expected) {
    }

    store.close();
    env.close();
    env = null;
}
 
开发者ID:nologic,项目名称:nabs,代码行数:77,代码来源:SubclassIndexTest.java

示例13: testDeleteFromSubIndex

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

    open();

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

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

    Transaction txn = txnBegin();
    MyEntity e = new MyEntity();
    e.secKey = 1;
    e.priKey = 1;
    priIndex.put(txn, e);
    e.priKey = 2;
    priIndex.put(txn, e);
    e.priKey = 3;
    priIndex.put(txn, e);
    e.priKey = 4;
    priIndex.put(txn, e);
    txnCommit(txn);

    EntityIndex<Integer,MyEntity> subIndex = secIndex.subIndex(1);
    txn = txnBeginCursor();
    e = subIndex.get(txn, 1, null);
    assertEquals(1, e.priKey);
    assertEquals(Integer.valueOf(1), e.secKey);
    e = subIndex.get(txn, 2, null);
    assertEquals(2, e.priKey);
    assertEquals(Integer.valueOf(1), e.secKey);
    e = subIndex.get(txn, 3, null);
    assertEquals(3, e.priKey);
    assertEquals(Integer.valueOf(1), e.secKey);
    e = subIndex.get(txn, 5, null);
    assertNull(e);

    boolean deleted = subIndex.delete(txn, 1);
    assertTrue(deleted);
    assertNull(subIndex.get(txn, 1, null));
    assertNotNull(subIndex.get(txn, 2, null));

    EntityCursor<MyEntity> cursor = subIndex.entities(txn, null);
    boolean saw4 = false;
    for (MyEntity e2 = cursor.first(); e2 != null; e2 = cursor.next()) {
        if (e2.priKey == 3) {
            cursor.delete();
        }
        if (e2.priKey == 4) {
            saw4 = true;
        }
    }
    cursor.close();
    assertTrue(saw4);
    assertNull(subIndex.get(txn, 1, null));
    assertNull(subIndex.get(txn, 3, null));
    assertNotNull(subIndex.get(txn, 2, null));
    assertNotNull(subIndex.get(txn, 4, null));

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

示例14: testDeferredWrite

import com.sleepycat.persist.EntityCursor; //导入方法依赖的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

示例15: testSubclassIndex

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

    EnvironmentConfig envConfig = TestEnv.BDB.getConfig();
    envConfig.setAllowCreate(true);
    env = new Environment(envHome, envConfig);

    StoreConfig storeConfig = new StoreConfig();
    storeConfig.setAllowCreate(true);
    EntityStore store = new EntityStore(env, "foo", storeConfig);

    PrimaryIndex<String, Employee> employeesById =
        store.getPrimaryIndex(String.class, Employee.class);

    employeesById.put(new Employee("1"));
    employeesById.put(new Manager("2", "a"));
    employeesById.put(new Manager("3", "a"));
    employeesById.put(new Manager("4", "b"));

    Employee e;
    Manager m;

    e = employeesById.get("1");
    assertNotNull(e);
    assertTrue(!(e instanceof Manager));

    /* Ensure DB exists BEFORE calling getSubclassIndex. [#15247] */
    PersistTestUtils.assertDbExists
        (true, env, "foo", Employee.class.getName(), "dept");

    /* Normal use: Subclass index for a key in the subclass. */
    SecondaryIndex<String, String, Manager> managersByDept =
        store.getSubclassIndex
            (employeesById, Manager.class, String.class, "dept");

    m = managersByDept.get("a");
    assertNotNull(m);
    assertEquals("2", m.id);

    m = managersByDept.get("b");
    assertNotNull(m);
    assertEquals("4", m.id);

    EntityCursor<Manager> managers = managersByDept.entities();
    try {
        m = managers.next();
        assertNotNull(m);
        assertEquals("2", m.id);
        m = managers.next();
        assertNotNull(m);
        assertEquals("3", m.id);
        m = managers.next();
        assertNotNull(m);
        assertEquals("4", m.id);
        m = managers.next();
        assertNull(m);
    } finally {
        managers.close();
    }

    /* Getting a subclass index for the entity class is also allowed. */
    store.getSubclassIndex
        (employeesById, Employee.class, String.class, "other");

    /* Getting a subclass index for a base class key is not allowed. */
    try {
        store.getSubclassIndex
            (employeesById, Manager.class, String.class, "other");
        fail();
    } catch (IllegalArgumentException expected) {
    }

    store.close();
    env.close();
    env = null;
}
 
开发者ID:nologic,项目名称:nabs,代码行数:77,代码来源:SubclassIndexTest.java


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