本文整理汇总了Java中com.sleepycat.persist.PrimaryIndex类的典型用法代码示例。如果您正苦于以下问题:Java PrimaryIndex类的具体用法?Java PrimaryIndex怎么用?Java PrimaryIndex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PrimaryIndex类属于com.sleepycat.persist包,在下文中一共展示了PrimaryIndex类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDump
import com.sleepycat.persist.PrimaryIndex; //导入依赖的package包/类
public void testDump() {
RawStore rs = access.getRawStore();
EntityModel model = rs.getModel();
for (String clsName : model.getKnownClasses()) {
if (model.getEntityMetadata(clsName) != null) {
final PrimaryIndex<Object,RawObject> index;
try {
index = rs.getPrimaryIndex(clsName);
} catch (IndexNotAvailableException e) {
System.err.println("Skipping primary index that is " +
"not yet available: " + clsName);
continue;
}
EntityCursor<RawObject> entities = index.entities();
for (RawObject entity : entities) {
System.out.println(entity);
}
entities.close();
}
}
}
示例2: 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();
}
}
示例3: 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();
}
示例4: testEntitySubclassWithPrimaryKey
import com.sleepycat.persist.PrimaryIndex; //导入依赖的package包/类
/**
* Disallow primary keys on entity subclasses. [#15757]
*/
public void testEntitySubclassWithPrimaryKey()
throws DatabaseException {
open();
PrimaryIndex<Integer,EntitySuperClass> index = store.getPrimaryIndex
(Integer.class, EntitySuperClass.class);
EntitySuperClass e1 = new EntitySuperClass(1, "one");
index.put(e1);
assertEquals(e1, index.get(1));
EntitySubClass e2 = new EntitySubClass(2, "two", "foo", 9);
try {
index.put(e2);
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains
("PrimaryKey may not appear on an Entity subclass"));
}
assertEquals(e1, index.get(1));
close();
}
示例5: readObjects
import com.sleepycat.persist.PrimaryIndex; //导入依赖的package包/类
@Override
void readObjects(EntityStore store, boolean doUpdate)
throws DatabaseException {
PrimaryIndex<Byte,AllowPriKeyField_byte2Byte>
index = store.getPrimaryIndex
(Byte.class,
AllowPriKeyField_byte2Byte.class);
AllowPriKeyField_byte2Byte obj = index.get(key);
TestCase.assertNotNull(obj);
TestCase.assertEquals(Byte.valueOf((byte) 99), obj.key);
if (doUpdate) {
index.put(obj);
}
}
示例6: readObjects
import com.sleepycat.persist.PrimaryIndex; //导入依赖的package包/类
@Override
void readObjects(EntityStore store, boolean doUpdate)
throws DatabaseException {
PrimaryIndex<Integer,ArrayNameChange_Entity>
index = store.getPrimaryIndex
(Integer.class,
ArrayNameChange_Entity.class);
ArrayNameChange_Entity obj = index.get(99);
TestCase.assertNotNull(obj);
TestCase.assertEquals(99, obj.key);
TestCase.assertNotNull(obj.embed);
TestCase.assertEquals(1, obj.embed.length);
TestCase.assertEquals(88L, obj.embed[0].data);
TestCase.assertSame(obj.embed2, obj.embed[0]);
if (doUpdate) {
index.put(obj);
}
}
示例7: 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();
}
示例8: 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);
}
}
示例9: 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();
}
示例10: testToManyKeyClass
import com.sleepycat.persist.PrimaryIndex; //导入依赖的package包/类
/**
* When opening an X_TO_MANY secondary that has a persistent key class, the
* key class was not recognized as being persistent if it was never before
* referenced when getSecondaryIndex was called. This was a bug in JE
* 3.0.12, reported on OTN. [#15103]
*/
public void testToManyKeyClass()
throws DatabaseException {
open();
PrimaryIndex<Integer,ToManyKeyEntity> priIndex =
store.getPrimaryIndex(Integer.class, ToManyKeyEntity.class);
SecondaryIndex<ToManyKey,Integer,ToManyKeyEntity> secIndex =
store.getSecondaryIndex(priIndex, ToManyKey.class, "key2");
priIndex.put(new ToManyKeyEntity());
secIndex.get(new ToManyKey());
close();
}
示例11: doTwoConditionsJoin
import com.sleepycat.persist.PrimaryIndex; //导入依赖的package包/类
/**
* Do a "AND" join on a single primary database, similar to the SQL:
* <blockquote><pre>
* SELECT * FROM table WHERE col1 = key1 AND col2 = key2;
* </pre></blockquote>
*
* @param pk
* @param sk1
* @param key1
* @param sk2
* @param key2
* @return
* @throws DatabaseException
*/
public <PK, SK1, SK2, E> ForwardCursor<E>
doTwoConditionsJoin(PrimaryIndex<PK, E> pk,
SecondaryIndex<SK1, PK, E> sk1,
SK1 key1,
SecondaryIndex<SK2, PK, E> sk2,
SK2 key2)
throws DatabaseException {
assert (pk != null);
assert (sk1 != null);
assert (sk2 != null);
EntityJoin<PK, E> join = new EntityJoin<PK, E>(pk);
join.addCondition(sk1, key1);
join.addCondition(sk2, key2);
return join.entities();
}
示例12: testToManyReadOnly
import com.sleepycat.persist.PrimaryIndex; //导入依赖的package包/类
/**
* Test a fix for a bug where opening a TO_MANY secondary index would fail
* fail with "IllegalArgumentException: Wrong secondary key class: ..."
* when the store was opened read-only. [#15156]
*/
public void testToManyReadOnly()
throws DatabaseException {
open();
PrimaryIndex<Integer,ToManyKeyEntity> priIndex =
store.getPrimaryIndex(Integer.class, ToManyKeyEntity.class);
priIndex.put(new ToManyKeyEntity());
close();
openReadOnly();
priIndex = store.getPrimaryIndex(Integer.class, ToManyKeyEntity.class);
SecondaryIndex<ToManyKey,Integer,ToManyKeyEntity> secIndex =
store.getSecondaryIndex(priIndex, ToManyKey.class, "key2");
secIndex.get(new ToManyKey());
close();
}