本文整理了Java中com.j256.ormlite.dao.Dao.setObjectCache()
方法的一些代码示例,展示了Dao.setObjectCache()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.setObjectCache()
方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:setObjectCache
[英]Same as #setObjectCache(boolean) except you specify the actual cache instance to use for the DAO. This allows you to use a ReferenceObjectCache with SoftReference setting, the LruObjectCache, or inject your own cache implementation. Call it with null to disable the cache.
[中]与#setObjectCache(布尔值)相同,只是指定要用于DAO的实际缓存实例。这允许您使用带有SoftReference设置的ReferenceObjectCache、LruObjectCache或注入您自己的缓存实现。使用null调用它以禁用缓存。
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* @see Dao#setObjectCache(boolean)
*/
@Override
public void setObjectCache(boolean enabled) {
try {
dao.setObjectCache(enabled);
} catch (SQLException e) {
logMessage(e, "setObjectCache(" + enabled + ") threw exception");
throw new RuntimeException(e);
}
}
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#setObjectCache(boolean)
*/
@Override
public void setObjectCache(boolean enabled) {
try {
dao.setObjectCache(enabled);
} catch (SQLException e) {
logMessage(e, "setObjectCache(" + enabled + ") threw exception");
throw new RuntimeException(e);
}
}
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#setObjectCache(ObjectCache)
*/
@Override
public void setObjectCache(ObjectCache objectCache) {
try {
dao.setObjectCache(objectCache);
} catch (SQLException e) {
logMessage(e, "setObjectCache threw exception on " + objectCache);
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* @see Dao#setObjectCache(ObjectCache)
*/
@Override
public void setObjectCache(ObjectCache objectCache) {
try {
dao.setObjectCache(objectCache);
} catch (SQLException e) {
logMessage(e, "setObjectCache threw exception on " + objectCache);
throw new RuntimeException(e);
}
}
代码示例来源:origin: j256/ormlite-core
@Override
protected ObjectCache enableCache(Dao<?, ?> dao) throws Exception {
ReferenceObjectCache cache = ReferenceObjectCache.makeWeakCache();
dao.setObjectCache(cache);
return cache;
}
}
代码示例来源:origin: j256/ormlite-core
@Override
protected ObjectCache enableCache(Dao<?, ?> dao) throws Exception {
LruObjectCache cache = new LruObjectCache(10);
dao.setObjectCache(cache);
return cache;
}
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testSetObjectCache() throws Exception {
@SuppressWarnings("unchecked")
Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
dao.setObjectCache(false);
replay(dao);
rtDao.setObjectCache(false);
verify(dao);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testSetObjectCacheCache() throws Exception {
@SuppressWarnings("unchecked")
Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
dao.setObjectCache(null);
replay(dao);
rtDao.setObjectCache(null);
verify(dao);
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = RuntimeException.class)
public void testSetObjectCacheThrow() throws Exception {
@SuppressWarnings("unchecked")
Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
dao.setObjectCache(false);
expectLastCall().andThrow(new SQLException("Testing catch"));
replay(dao);
rtDao.setObjectCache(false);
verify(dao);
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = RuntimeException.class)
public void testSetObjectCacheCacheThrow() throws Exception {
@SuppressWarnings("unchecked")
Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
dao.setObjectCache(null);
expectLastCall().andThrow(new SQLException("Testing catch"));
replay(dao);
rtDao.setObjectCache(null);
verify(dao);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testEnableBoolean() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
dao.setObjectCache(true);
Foo foo = new Foo();
int val = 12312321;
foo.val = val;
assertEquals(1, dao.create(foo));
Foo result = dao.queryForId(foo.id);
assertSame(foo, result);
dao.setObjectCache(false);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testQueryAll() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
dao.setObjectCache(true);
Foo foo = new Foo();
int val = 12312321;
foo.val = val;
assertEquals(1, dao.create(foo));
dao.clearObjectCache();
List<Foo> results = dao.queryForAll();
assertEquals(1, results.size());
assertEquals(foo.id, results.get(0).id);
assertNotSame(foo, results.get(0));
Foo foo2 = dao.queryForId(foo.id);
assertNotNull(foo2);
assertEquals(foo.id, results.get(0).id);
assertSame(results.get(0), foo2);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testDisableAlreadyDisabled() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
dao.setObjectCache(false);
Foo foo = new Foo();
int val = 12312321;
foo.val = val;
assertEquals(1, dao.create(foo));
Foo result = dao.queryForId(foo.id);
assertNotSame(foo, result);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testReplaceCache() throws Exception {
Dao<Foo, Object> dao = createDao(Foo.class, true);
ReferenceObjectCache cache1 = new ReferenceObjectCache(true);
dao.setObjectCache(cache1);
Foo foo = new Foo();
int val = 12312321;
foo.val = val;
assertEquals(1, dao.create(foo));
Foo result = dao.queryForId(foo.id);
assertSame(foo, result);
// enable a new cache
dao.setObjectCache(new ReferenceObjectCache(true));
assertEquals(0, cache1.size(Foo.class));
result = dao.queryForId(foo.id);
assertNotSame(foo, result);
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testBasicCacheStuff() throws Exception {
Dao<AllTypes, Integer> allTypesDao = createDao(AllTypes.class, true);
allTypesDao.setObjectCache(true);
Dao<ForeignWrapper, Integer> wrapperDao = createDao(ForeignWrapper.class, true);
wrapperDao.setObjectCache(true);
AllTypes allTypes1 = new AllTypes();
assertEquals(1, allTypesDao.create(allTypes1));
ForeignWrapper wrapper = new ForeignWrapper();
wrapper.foreign = allTypes1;
assertEquals(1, wrapperDao.create(wrapper));
ForeignWrapper wrapperResult = wrapperDao.queryForId(wrapper.id);
assertSame(wrapper, wrapperResult);
AllTypes allTypesResult = allTypesDao.queryForId(allTypes1.id);
assertSame(allTypes1, allTypesResult);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testBasic() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
enableCache(dao);
Foo foo = new Foo();
int val = 12312321;
foo.val = val;
assertEquals(1, dao.create(foo));
Foo result = dao.queryForId(foo.id);
assertSame(foo, result);
List<Foo> results = dao.queryForAll();
assertEquals(1, results.size());
assertSame(result, results.get(0));
// disable cache
dao.setObjectCache(null);
result = dao.queryForId(foo.id);
assertNotSame(foo, result);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testQueryForId() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
int val = 12312321;
foo.val = val;
assertEquals(1, dao.create(foo));
LruObjectCache cache = new LruObjectCache(1024);
dao.setObjectCache(cache);
Foo foo2 = dao.queryForId(foo.id);
assertNotSame(foo, foo2);
Foo foo3 = dao.queryForId(foo.id);
assertSame(foo2, foo3);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testForeignLinkageWithCache() throws Exception {
Dao<EagerConnection, Integer> multipleDao = createDao(EagerConnection.class, true);
multipleDao.setObjectCache(true);
Dao<EagerNode, Integer> foreignDao = createDao(EagerNode.class, true);
foreignDao.setObjectCache(true);
EagerNode foreign1 = new EagerNode();
assertEquals(1, foreignDao.create(foreign1));
EagerNode foreign2 = new EagerNode();
assertEquals(1, foreignDao.create(foreign2));
EagerConnection multiple1 = new EagerConnection();
multiple1.from = foreign1;
multiple1.to = foreign2;
assertEquals(1, multipleDao.create(multiple1));
EagerNode result = foreignDao.queryForId(foreign1.id);
assertNotNull(result.froms);
EagerConnection[] array = result.froms.toArray(new EagerConnection[result.froms.size()]);
assertEquals(1, array.length);
assertSame(foreign1, array[0].from);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testForeignInCache() throws Exception {
Dao<ForeignParent, Integer> parentDao = createDao(ForeignParent.class, true);
Dao<ForeignForeign, Integer> foreignDao = createDao(ForeignForeign.class, true);
foreignDao.setObjectCache(true);
ForeignForeign foreign = new ForeignForeign();
foreign.stuff = "hello";
foreignDao.create(foreign);
assertSame(foreign, foreignDao.queryForId(foreign.id));
ForeignParent parent = new ForeignParent();
parent.foreign = foreign;
parentDao.create(parent);
ForeignParent result = parentDao.queryForId(parent.id);
assertNotSame(parent, result);
assertSame(foreign, result.foreign);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testClear() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
LruObjectCache cache = new LruObjectCache(2);
dao.setObjectCache(cache);
Foo foo = new Foo();
int val = 12312321;
foo.val = val;
assertEquals(1, dao.create(foo));
assertEquals(1, cache.size(Foo.class));
Foo result = dao.queryForId(foo.id);
assertSame(foo, result);
dao.clearObjectCache();
result = dao.queryForId(foo.id);
assertNotSame(foo, result);
}
内容来源于网络,如有侵权,请联系作者删除!