本文整理了Java中com.j256.ormlite.dao.Dao.queryForId()
方法的一些代码示例,展示了Dao.queryForId()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.queryForId()
方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:queryForId
[英]Retrieves an object associated with a specific ID.
[中]检索与特定ID关联的对象。
代码示例来源:origin: BaronZ88/MinimalistWeather
public Weather queryWeather(String cityId) throws SQLException {
return TransactionManager.callInTransaction(WeatherDatabaseHelper.getInstance(context).getConnectionSource(), () -> {
Weather weather = weatherDaoOperation.queryForId(cityId);
if (weather != null) {
weather.setAirQualityLive(apiDaoOperation.queryForId(cityId));
weather.setWeatherForecasts(forecastDaoOperation.queryForEq(WeatherForecast.CITY_ID_FIELD_NAME, cityId));
weather.setLifeIndexes(lifeIndexesDaoOperation.queryForEq(WeatherForecast.CITY_ID_FIELD_NAME, cityId));
weather.setWeatherLive(realTimeDaoOperation.queryForId(cityId));
}
return weather;
});
}
代码示例来源:origin: BaronZ88/MinimalistWeather
/**
* 查询数据库中的所有已添加的城市
*
* @return 结果集中只包括城市信息,天气数据不在其中
* @throws SQLException
*/
public List<Weather> queryAllSaveCity() throws SQLException {
return TransactionManager.callInTransaction(WeatherDatabaseHelper.getInstance(context).getConnectionSource(), () -> {
List<Weather> weatherList = weatherDaoOperation.queryForAll();
for (Weather weather : weatherList) {
String cityId = weather.getCityId();
weather.setAirQualityLive(apiDaoOperation.queryForId(cityId));
weather.setWeatherForecasts(forecastDaoOperation.queryForEq(WeatherForecast.CITY_ID_FIELD_NAME, cityId));
weather.setLifeIndexes(lifeIndexesDaoOperation.queryForEq(WeatherForecast.CITY_ID_FIELD_NAME, cityId));
weather.setWeatherLive(realTimeDaoOperation.queryForId(cityId));
}
return weatherList;
});
}
代码示例来源:origin: tianshaojie/AndroidFine
public User get(int id) {
try {
return userDaoOpe.queryForId(id);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
代码示例来源:origin: tianshaojie/AndroidFine
/**
* 通过Id得到一篇文章
*
* @param id
* @return
*/
public Article get(int id)
{
Article article = null;
try
{
article = articleDaoOpe.queryForId(id);
} catch (SQLException e)
{
e.printStackTrace();
}
return article;
}
代码示例来源:origin: tianshaojie/AndroidFine
/**
* 通过Id得到一个Article
*
* @param id
* @return
*/
@SuppressWarnings("unchecked")
public Article getArticleWithUser(int id)
{
Article article = null;
try
{
article = articleDaoOpe.queryForId(id);
helper.getDao(User.class).refresh(article.getUser());
} catch (SQLException e)
{
e.printStackTrace();
}
return article;
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* @see Dao#queryForId(Object)
*/
@Override
public T queryForId(ID id) {
try {
return dao.queryForId(id);
} catch (SQLException e) {
logMessage(e, "queryForId threw exception on: " + id);
throw new RuntimeException(e);
}
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = RuntimeException.class)
public void testQueryForIdThrow() throws Exception {
@SuppressWarnings("unchecked")
Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
expect(dao.queryForId(isA(String.class))).andThrow(new SQLException("Testing catch"));
replay(dao);
rtDao.queryForId("wow");
verify(dao);
}
代码示例来源:origin: j256/ormlite-core
@Override
public Void call() throws Exception {
assertEquals(1, dao.create(foo1));
assertNotNull(dao.queryForId(foo1.id));
return null;
}
});
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Override
public Void call() throws Exception {
// we do the delete
assertEquals(1, accountDao.delete(account));
assertNull(accountDao.queryForId(account.getId()));
// but then (as an example) we throw an exception which rolls back the delete
throw new Exception("We throw to roll back!!");
}
});
代码示例来源:origin: j256/ormlite-core
@Test
public void testCreateReserverdTable() throws Exception {
Dao<Where, String> whereDao = createDao(Where.class, true);
String id = "from-string";
Where where = new Where();
where.id = id;
whereDao.create(where);
Where where2 = whereDao.queryForId(id);
assertEquals(id, where2.id);
assertEquals(1, whereDao.delete(where2));
assertNull(whereDao.queryForId(id));
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testCreateReserverdTable() throws Exception {
Dao<Create, String> whereDao = createDao(Create.class, true);
String id = "from-string";
Create where = new Create();
where.id = id;
assertEquals(1, whereDao.create(where));
Create where2 = whereDao.queryForId(id);
assertEquals(id, where2.id);
assertEquals(1, whereDao.delete(where2));
assertNull(whereDao.queryForId(id));
}
代码示例来源: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 testBigIntegerId() throws Exception {
Dao<BigIntegerId, BigInteger> dao = createDao(BigIntegerId.class, true);
BigIntegerId foo = new BigIntegerId();
dao.create(foo);
assertEquals(BigInteger.ONE, foo.id);
BigIntegerId result = dao.queryForId(BigInteger.ONE);
assertNotNull(result);
assertEquals(foo.id, result.id);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testUuidDao() throws Exception {
Dao<UuidClass, Integer> dao = createDao(UuidClass.class, true);
UuidClass uuid = new UuidClass();
uuid.uuid = null;
assertEquals(1, dao.create(uuid));
UuidClass uuidResult = dao.queryForId(uuid.id);
assertNotNull(uuidResult);
assertNull(uuidResult.uuid);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void shouldStoreEntityWithStringIdAndLoadFromDbOnCreateOrUpdate() throws Exception {
Dao<EntityWithStringId, String> dao = createDao(EntityWithStringId.class, true);
EntityWithStringId data = new EntityWithStringId();
data.id = "generated_id_from_factory";
data.value = "some value";
dao.createOrUpdate(data);
EntityWithStringId found = dao.queryForId(data.id);
assertNotNull(found);
assertEquals(found.id, data.id);
assertEquals(found.value, data.value);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testByteArrayId() throws Exception {
Class<ByteArrayId> clazz = ByteArrayId.class;
Dao<ByteArrayId, Object> dao = createDao(clazz, true);
ByteArrayId foo = new ByteArrayId();
foo.id = new byte[] { 1, 2, 3, 4, 5 };
assertEquals(1, dao.create(foo));
ByteArrayId result = dao.queryForId(foo.id);
assertNotNull(result);
assertArrayEquals(foo.id, result.id);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testForeignNull() throws Exception {
Dao<Foreign, Integer> dao = createDao(Foreign.class, true);
Foreign foreign = new Foreign();
foreign.foo = null;
assertEquals(1, dao.create(foreign));
Foreign foreign2 = dao.queryForId(foreign.id);
assertNotNull(foreign2);
assertNull(foreign2.foo);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testForeignIntIdNull() throws Exception {
Dao<ForeignIntId, Integer> dao = createDao(ForeignIntId.class, true);
ForeignIntId foreign = new ForeignIntId();
foreign.one = null;
assertEquals(1, dao.create(foreign));
ForeignIntId foreign2 = dao.queryForId(foreign.id);
assertNotNull(foreign2);
assertNull(foreign2.one);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void shouldStoreEntityWithCustomTypeIdAndLoadFromDbOnCreate() throws Exception {
Dao<EntityWithCustomTypeId, EntityId> dao = createDao(EntityWithCustomTypeId.class, true);
EntityWithCustomTypeId data = new EntityWithCustomTypeId();
data.id = EntityId.entityId("generated_id_from_factory");
data.value = "some value";
dao.create(data);
EntityWithCustomTypeId found = dao.queryForId(data.id);
assertNotNull(found);
assertEquals(found.id, data.id);
assertEquals(found.value, data.value);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testBaseClassAnnotations() throws Exception {
Sub sub = new Sub();
String stuff = "djeqpodjewdopjed";
sub.stuff = stuff;
Dao<Sub, Object> dao = createDao(Sub.class, true);
assertEquals(0, sub.id);
assertEquals(1, dao.create(sub));
Sub sub2 = dao.queryForId(sub.id);
assertNotNull(sub2);
assertEquals(sub.stuff, sub2.stuff);
}
内容来源于网络,如有侵权,请联系作者删除!