本文整理了Java中com.j256.ormlite.dao.Dao.refresh()
方法的一些代码示例,展示了Dao.refresh()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.refresh()
方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:refresh
[英]Does a query for the data parameter's id and copies in each of the field values from the database to refresh the data parameter. Any local object changes to persisted fields will be overwritten. If the database has been updated this brings your local object up to date.
[中]查询数据参数的id,并从数据库中复制每个字段值以刷新数据参数。对持久化字段的任何本地对象更改都将被覆盖。如果数据库已更新,则会使本地对象更新。
代码示例来源: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: j256/ormlite-core
@Override
public int refresh(T data) throws SQLException {
if (dao == null) {
return 0;
} else {
return dao.refresh(data);
}
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
@Override
public int refresh(T data) throws SQLException {
if (dao == null) {
return 0;
} else {
return dao.refresh(data);
}
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
@Override
public int refreshAll() throws SQLException {
int updatedC = 0;
for (T data : results) {
updatedC += dao.refresh(data);
}
return updatedC;
}
代码示例来源:origin: j256/ormlite-core
@Override
public int refreshAll() throws SQLException {
int updatedC = 0;
for (T data : results) {
updatedC += dao.refresh(data);
}
return updatedC;
}
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#refresh(Object)
*/
@Override
public int refresh(T data) {
try {
return dao.refresh(data);
} catch (SQLException e) {
logMessage(e, "refresh threw exception on: " + data);
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.octo.android.robospice/robospice-ormlite
public <T> void refreshFromDatabase(T modelObject, Class<T> modelObjectClass) throws SQLException {
if (modelObject != null) {
Dao<T, ?> dao = getDao(modelObjectClass);
dao.refresh(modelObject);
}
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* @see Dao#refresh(Object)
*/
@Override
public int refresh(T data) {
try {
return dao.refresh(data);
} catch (SQLException e) {
logMessage(e, "refresh threw exception on: " + data);
throw new RuntimeException(e);
}
}
代码示例来源:origin: j256/ormlite-core
/**
* A call through to the {@link Dao#refresh(Object)}.
*/
public int refresh() throws SQLException {
checkForDao();
@SuppressWarnings("unchecked")
T t = (T) this;
return dao.refresh(t);
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* A call through to the {@link Dao#refresh(Object)}.
*/
public int refresh() throws SQLException {
checkForDao();
@SuppressWarnings("unchecked")
T t = (T) this;
return dao.refresh(t);
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = RuntimeException.class)
public void testRefreshThrow() 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.refresh(null)).andThrow(new SQLException("Testing catch"));
replay(dao);
rtDao.refresh(null);
verify(dao);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testUuidDefault() throws Exception {
System.out.println(UUID.randomUUID().toString());
Dao<UuidClassDefault, Object> dao = createDao(UuidClassDefault.class, true);
UuidClassDefault foo = new UuidClassDefault();
dao.create(foo);
assertNull(foo.uuid);
dao.refresh(foo);
assertNotNull(foo.uuid);
assertEquals(UUID.fromString(DEFAULT_VALUE), foo.uuid);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testRefreshNotFound() throws Exception {
Dao<LocalFoo, Object> fooDao = createDao(LocalFoo.class, true);
LocalFoo foo1 = new LocalFoo();
foo1.id = "foo";
// hasn't been created yet
assertEquals(0, fooDao.refresh(foo1));
// now it is created
assertEquals(1, fooDao.create(foo1));
// now it should refresh
assertEquals(1, fooDao.refresh(foo1));
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testDefaultValue() throws Exception {
Dao<BigDecimalDefaultValue, Object> dao = createDao(BigDecimalDefaultValue.class, true);
BigDecimalDefaultValue foo = new BigDecimalDefaultValue();
dao.create(foo);
assertNull(foo.bigDecimal);
dao.refresh(foo);
assertEquals(new BigDecimal(DEFAULT_VALUE), foo.bigDecimal);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testDefaultValue() throws Exception {
Dao<BigIntegerDefaultValue, Object> dao = createDao(BigIntegerDefaultValue.class, true);
BigIntegerDefaultValue foo = new BigIntegerDefaultValue();
dao.create(foo);
assertNull(foo.bigInteger);
dao.refresh(foo);
assertEquals(new BigInteger(DEFAULT_VALUE), foo.bigInteger);
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testDateRefresh() throws Exception {
Dao<LocalDate, Object> dao = createDao(LocalDate.class, true);
LocalDate localDate = new LocalDate();
// note: this does not have milliseconds
Date date = new Date(2131232000);
localDate.date = date;
assertEquals(1, dao.create(localDate));
assertEquals(1, dao.refresh(localDate));
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testRefreshNoId() throws Exception {
Dao<NoId, Object> noIdDao = createDao(NoId.class, true);
NoId noId = new NoId();
noId.stuff = "1";
assertEquals(1, noIdDao.create(noId));
noIdDao.refresh(noId);
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testUuidInvalidDefault() throws Exception {
Dao<UuidClassInvalidDefault, Object> dao = createDao(UuidClassInvalidDefault.class, true);
UuidClassInvalidDefault foo = new UuidClassInvalidDefault();
dao.create(foo);
assertNull(foo.uuid);
dao.refresh(foo);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testJustIdInsert() throws Exception {
Dao<JustId, Object> dao = createDao(JustId.class, true);
JustId foo = new JustId();
assertEquals(1, dao.create(foo));
assertEquals(1, dao.refresh(foo));
assertEquals(0, dao.update(foo));
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testRefreshThrow() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
try {
conn.close();
dao.refresh(foo);
} finally {
connectionSource.releaseConnection(conn);
}
}
内容来源于网络,如有侵权,请联系作者删除!