com.j256.ormlite.dao.Dao.update()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(371)

本文整理了Java中com.j256.ormlite.dao.Dao.update()方法的一些代码示例,展示了Dao.update()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.update()方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:update

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

  1. private void updateWeather(Weather weather) throws SQLException {
  2. weatherDaoOperation.update(weather);
  3. apiDaoOperation.update(weather.getAirQualityLive());
  4. //先删除旧数据
  5. DeleteBuilder<WeatherForecast, Long> forecastDeleteBuilder = forecastDaoOperation.deleteBuilder();
  6. forecastDeleteBuilder.where().eq(WeatherForecast.CITY_ID_FIELD_NAME, weather.getCityId());
  7. PreparedDelete<WeatherForecast> forecastPrepared = forecastDeleteBuilder.prepare();
  8. forecastDaoOperation.delete(forecastPrepared);
  9. //再插入新数据
  10. for (WeatherForecast weatherForecast : weather.getWeatherForecasts()) {
  11. forecastDaoOperation.create(weatherForecast);
  12. }
  13. //先删除旧数据
  14. DeleteBuilder<LifeIndex, Long> lifeIndexDeleteBuilder = lifeIndexesDaoOperation.deleteBuilder();
  15. lifeIndexDeleteBuilder.where().eq(LifeIndex.CITY_ID_FIELD_NAME, weather.getCityId());
  16. PreparedDelete<LifeIndex> lifeIndexPrepared = lifeIndexDeleteBuilder.prepare();
  17. lifeIndexesDaoOperation.delete(lifeIndexPrepared);
  18. //再插入新数据
  19. for (LifeIndex index : weather.getLifeIndexes()) {
  20. lifeIndexesDaoOperation.create(index);
  21. }
  22. realTimeDaoOperation.update(weather.getWeatherLive());
  23. }
  24. }

代码示例来源:origin: j256/ormlite-core

  1. @Test
  2. public void testUpdateTwoNullsInSeperateStatements() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. UpdateBuilder<Foo, Integer> ub = dao.updateBuilder();
  5. ub.updateColumnValue(Foo.STRING_COLUMN_NAME, null);
  6. dao.update(ub.prepare());
  7. ub = dao.updateBuilder();
  8. ub.updateColumnValue(Foo.EQUAL_COLUMN_NAME, null);
  9. dao.update(ub.prepare());
  10. }

代码示例来源:origin: magefree/mage

  1. public void update(UserStats userStats) {
  2. try {
  3. dao.update(userStats);
  4. } catch (SQLException ex) {
  5. Logger.getLogger(UserStatsRepository.class).error("Error updating a user_stats in DB - ", ex);
  6. }
  7. }

代码示例来源:origin: j256/ormlite-core

  1. @Test
  2. public void testUpdateTwoNulls() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. UpdateBuilder<Foo, Integer> ub = dao.updateBuilder();
  5. ub.updateColumnValue(Foo.STRING_COLUMN_NAME, null);
  6. ub.updateColumnValue(Foo.EQUAL_COLUMN_NAME, null);
  7. dao.update(ub.prepare());
  8. }

代码示例来源:origin: magefree/mage

  1. public void update(AuthorizedUser authorizedUser) {
  2. try {
  3. dao.update(authorizedUser);
  4. } catch (SQLException ex) {
  5. Logger.getLogger(AuthorizedUserRepository.class).error("Error updating authorized_user", ex);
  6. }
  7. }

代码示例来源:origin: magefree/mage

  1. try {
  2. for (ExpansionInfo exp : updatedSets) {
  3. expansionDao.update(exp);

代码示例来源:origin: j256/ormlite-core

  1. @Override
  2. public int update(T data) throws SQLException {
  3. if (dao == null) {
  4. return 0;
  5. } else {
  6. return dao.update(data);
  7. }
  8. }

代码示例来源:origin: j256/ormlite-core

  1. @Override
  2. public int updateAll() throws SQLException {
  3. int updatedC = 0;
  4. for (T data : results) {
  5. updatedC += dao.update(data);
  6. }
  7. return updatedC;
  8. }

代码示例来源:origin: j256/ormlite-core

  1. /**
  2. * A call through to the {@link Dao#update(Object)}.
  3. */
  4. public int update() throws SQLException {
  5. checkForDao();
  6. @SuppressWarnings("unchecked")
  7. T t = (T) this;
  8. return dao.update(t);
  9. }

代码示例来源:origin: j256/ormlite-core

  1. /**
  2. * @see Dao#update(PreparedUpdate)
  3. */
  4. @Override
  5. public int update(PreparedUpdate<T> preparedUpdate) {
  6. try {
  7. return dao.update(preparedUpdate);
  8. } catch (SQLException e) {
  9. logMessage(e, "update threw exception on: " + preparedUpdate);
  10. throw new RuntimeException(e);
  11. }
  12. }

代码示例来源:origin: j256/ormlite-core

  1. /**
  2. * @see Dao#update(Object)
  3. */
  4. @Override
  5. public int update(T data) {
  6. try {
  7. return dao.update(data);
  8. } catch (SQLException e) {
  9. logMessage(e, "update threw exception on: " + data);
  10. throw new RuntimeException(e);
  11. }
  12. }

代码示例来源:origin: QuickBlox/q-municate-android

  1. @Override
  2. public void update(Object object) {
  3. try {
  4. dao.update((T) object);
  5. } catch (SQLException e) {
  6. ErrorUtils.logError(e);
  7. }
  8. }

代码示例来源:origin: QuickBlox/q-municate-android

  1. @Override
  2. public void update(Object object, boolean notify) {
  3. try {
  4. dao.update((T) object);
  5. if (notify) {
  6. notifyObservers((T)object, UPDATE_ACTION);
  7. }
  8. } catch (SQLException e) {
  9. ErrorUtils.logError(e);
  10. }
  11. }

代码示例来源:origin: j256/ormlite-core

  1. @Test(expected = RuntimeException.class)
  2. public void testUpdateThrow() throws Exception {
  3. @SuppressWarnings("unchecked")
  4. Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
  5. RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
  6. expect(dao.update((Foo) null)).andThrow(new SQLException("Testing catch"));
  7. replay(dao);
  8. rtDao.update((Foo) null);
  9. verify(dao);
  10. }

代码示例来源:origin: j256/ormlite-core

  1. @Test(expected = RuntimeException.class)
  2. public void testUpdatePreparedThrow() throws Exception {
  3. @SuppressWarnings("unchecked")
  4. Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
  5. RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
  6. expect(dao.update((PreparedUpdate<Foo>) null)).andThrow(new SQLException("Testing catch"));
  7. replay(dao);
  8. rtDao.update((PreparedUpdate<Foo>) null);
  9. verify(dao);
  10. }

代码示例来源:origin: j256/ormlite-core

  1. @Test
  2. public void testVersion() throws Exception {
  3. Dao<ShortVersion, Integer> dao = createDao(ShortVersion.class, true);
  4. ShortVersion foo = new ShortVersion();
  5. assertNull(foo.version);
  6. assertEquals(1, dao.create(foo));
  7. assertEquals(Short.valueOf((short) 1), foo.version);
  8. assertEquals(1, dao.update(foo));
  9. assertEquals(Short.valueOf((short) 2), foo.version);
  10. }

代码示例来源:origin: j256/ormlite-core

  1. @Test
  2. public void testVersion() throws Exception {
  3. Dao<LongVersion, Integer> dao = createDao(LongVersion.class, true);
  4. LongVersion foo = new LongVersion();
  5. assertNull(foo.version);
  6. assertEquals(1, dao.create(foo));
  7. assertEquals(Long.valueOf(1), foo.version);
  8. assertEquals(1, dao.update(foo));
  9. assertEquals(Long.valueOf(2), foo.version);
  10. }

代码示例来源:origin: j256/ormlite-core

  1. @Test
  2. public void testUpdate() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. Foo foo = new Foo();
  5. assertEquals(1, dao.create(foo));
  6. foo.equal = 1;
  7. assertEquals(1, dao.update(foo));
  8. }

代码示例来源:origin: j256/ormlite-core

  1. @Test
  2. public void testForeignNoId() throws Exception {
  3. Dao<Foreign, Integer> dao = createDao(Foreign.class, true);
  4. Foreign foreign = new Foreign();
  5. foreign.foo = null;
  6. assertEquals(1, dao.create(foreign));
  7. foreign.foo = new Foo();
  8. assertEquals(1, dao.update(foreign));
  9. }

代码示例来源:origin: j256/ormlite-core

  1. @Test
  2. public void testJustIdInsert() throws Exception {
  3. Dao<JustId, Object> dao = createDao(JustId.class, true);
  4. JustId foo = new JustId();
  5. assertEquals(1, dao.create(foo));
  6. assertEquals(1, dao.refresh(foo));
  7. assertEquals(0, dao.update(foo));
  8. }

相关文章