本文整理了Java中com.j256.ormlite.dao.Dao.update()
方法的一些代码示例,展示了Dao.update()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.update()
方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:update
[英]Update all rows in the table according to the prepared statement parameter. To use this, the UpdateBuilder must have set-columns applied to it using the UpdateBuilder#updateColumnValue(String,Object) or UpdateBuilder#updateColumnExpression(String,String) methods.
[中]根据prepared statement参数更新表中的所有行。要使用此方法,UpdateBuilder必须使用UpdateBuilder#updateColumnValue(String,Object)或UpdateBuilder#updateColumnExpression(String,String)方法对其应用set列。
代码示例来源:origin: BaronZ88/MinimalistWeather
private void updateWeather(Weather weather) throws SQLException {
weatherDaoOperation.update(weather);
apiDaoOperation.update(weather.getAirQualityLive());
//先删除旧数据
DeleteBuilder<WeatherForecast, Long> forecastDeleteBuilder = forecastDaoOperation.deleteBuilder();
forecastDeleteBuilder.where().eq(WeatherForecast.CITY_ID_FIELD_NAME, weather.getCityId());
PreparedDelete<WeatherForecast> forecastPrepared = forecastDeleteBuilder.prepare();
forecastDaoOperation.delete(forecastPrepared);
//再插入新数据
for (WeatherForecast weatherForecast : weather.getWeatherForecasts()) {
forecastDaoOperation.create(weatherForecast);
}
//先删除旧数据
DeleteBuilder<LifeIndex, Long> lifeIndexDeleteBuilder = lifeIndexesDaoOperation.deleteBuilder();
lifeIndexDeleteBuilder.where().eq(LifeIndex.CITY_ID_FIELD_NAME, weather.getCityId());
PreparedDelete<LifeIndex> lifeIndexPrepared = lifeIndexDeleteBuilder.prepare();
lifeIndexesDaoOperation.delete(lifeIndexPrepared);
//再插入新数据
for (LifeIndex index : weather.getLifeIndexes()) {
lifeIndexesDaoOperation.create(index);
}
realTimeDaoOperation.update(weather.getWeatherLive());
}
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testUpdateTwoNullsInSeperateStatements() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
UpdateBuilder<Foo, Integer> ub = dao.updateBuilder();
ub.updateColumnValue(Foo.STRING_COLUMN_NAME, null);
dao.update(ub.prepare());
ub = dao.updateBuilder();
ub.updateColumnValue(Foo.EQUAL_COLUMN_NAME, null);
dao.update(ub.prepare());
}
代码示例来源:origin: magefree/mage
public void update(UserStats userStats) {
try {
dao.update(userStats);
} catch (SQLException ex) {
Logger.getLogger(UserStatsRepository.class).error("Error updating a user_stats in DB - ", ex);
}
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testUpdateTwoNulls() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
UpdateBuilder<Foo, Integer> ub = dao.updateBuilder();
ub.updateColumnValue(Foo.STRING_COLUMN_NAME, null);
ub.updateColumnValue(Foo.EQUAL_COLUMN_NAME, null);
dao.update(ub.prepare());
}
代码示例来源:origin: magefree/mage
public void update(AuthorizedUser authorizedUser) {
try {
dao.update(authorizedUser);
} catch (SQLException ex) {
Logger.getLogger(AuthorizedUserRepository.class).error("Error updating authorized_user", ex);
}
}
代码示例来源:origin: magefree/mage
try {
for (ExpansionInfo exp : updatedSets) {
expansionDao.update(exp);
代码示例来源:origin: j256/ormlite-core
@Override
public int update(T data) throws SQLException {
if (dao == null) {
return 0;
} else {
return dao.update(data);
}
}
代码示例来源:origin: j256/ormlite-core
@Override
public int updateAll() throws SQLException {
int updatedC = 0;
for (T data : results) {
updatedC += dao.update(data);
}
return updatedC;
}
代码示例来源:origin: j256/ormlite-core
/**
* A call through to the {@link Dao#update(Object)}.
*/
public int update() throws SQLException {
checkForDao();
@SuppressWarnings("unchecked")
T t = (T) this;
return dao.update(t);
}
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#update(PreparedUpdate)
*/
@Override
public int update(PreparedUpdate<T> preparedUpdate) {
try {
return dao.update(preparedUpdate);
} catch (SQLException e) {
logMessage(e, "update threw exception on: " + preparedUpdate);
throw new RuntimeException(e);
}
}
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#update(Object)
*/
@Override
public int update(T data) {
try {
return dao.update(data);
} catch (SQLException e) {
logMessage(e, "update threw exception on: " + data);
throw new RuntimeException(e);
}
}
代码示例来源:origin: QuickBlox/q-municate-android
@Override
public void update(Object object) {
try {
dao.update((T) object);
} catch (SQLException e) {
ErrorUtils.logError(e);
}
}
代码示例来源:origin: QuickBlox/q-municate-android
@Override
public void update(Object object, boolean notify) {
try {
dao.update((T) object);
if (notify) {
notifyObservers((T)object, UPDATE_ACTION);
}
} catch (SQLException e) {
ErrorUtils.logError(e);
}
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = RuntimeException.class)
public void testUpdateThrow() 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.update((Foo) null)).andThrow(new SQLException("Testing catch"));
replay(dao);
rtDao.update((Foo) null);
verify(dao);
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = RuntimeException.class)
public void testUpdatePreparedThrow() 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.update((PreparedUpdate<Foo>) null)).andThrow(new SQLException("Testing catch"));
replay(dao);
rtDao.update((PreparedUpdate<Foo>) null);
verify(dao);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testVersion() throws Exception {
Dao<ShortVersion, Integer> dao = createDao(ShortVersion.class, true);
ShortVersion foo = new ShortVersion();
assertNull(foo.version);
assertEquals(1, dao.create(foo));
assertEquals(Short.valueOf((short) 1), foo.version);
assertEquals(1, dao.update(foo));
assertEquals(Short.valueOf((short) 2), foo.version);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testVersion() throws Exception {
Dao<LongVersion, Integer> dao = createDao(LongVersion.class, true);
LongVersion foo = new LongVersion();
assertNull(foo.version);
assertEquals(1, dao.create(foo));
assertEquals(Long.valueOf(1), foo.version);
assertEquals(1, dao.update(foo));
assertEquals(Long.valueOf(2), foo.version);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testUpdate() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
foo.equal = 1;
assertEquals(1, dao.update(foo));
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testForeignNoId() throws Exception {
Dao<Foreign, Integer> dao = createDao(Foreign.class, true);
Foreign foreign = new Foreign();
foreign.foo = null;
assertEquals(1, dao.create(foreign));
foreign.foo = new Foo();
assertEquals(1, dao.update(foreign));
}
代码示例来源: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));
}
内容来源于网络,如有侵权,请联系作者删除!