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

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

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

Dao.delete介绍

[英]Delete the objects that match the prepared statement parameter.
[中]删除与prepared语句参数匹配的对象。

代码示例

代码示例来源:origin: BaronZ88/MinimalistWeather

  1. private void delete(Weather data) throws SQLException {
  2. weatherDaoOperation.delete(data);
  3. }

代码示例来源: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. /**
  2. * @see Dao#delete(Collection)
  3. */
  4. @Override
  5. public int delete(Collection<T> datas) {
  6. try {
  7. return dao.delete(datas);
  8. } catch (SQLException e) {
  9. logMessage(e, "delete threw exception on: " + datas);
  10. throw new RuntimeException(e);
  11. }
  12. }

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

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

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

  1. /**
  2. * A short cut to {@link Dao#delete(PreparedDelete)}.
  3. */
  4. public int delete() throws SQLException {
  5. return dao.delete(prepare());
  6. }

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

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

代码示例来源:origin: com.octo.android.robospice/robospice-ormlite

  1. public <T> void deleteFromDataBase(ForeignCollection<T> modelObjectCollection, Class<T> modelObjectClass) throws SQLException {
  2. if (modelObjectCollection != null) {
  3. Dao<T, ?> dao = getDao(modelObjectClass);
  4. dao.delete(modelObjectCollection);
  5. }
  6. }

代码示例来源:origin: org.mycontroller.standalone/mycontroller-core

  1. @Override
  2. public void delete(ResourcesLogs resourcesLogs) {
  3. try {
  4. int count = this.getDao().delete(resourcesLogs);
  5. _logger.debug("ResourcesLogs:[{}] deleted, Delete count:{}", resourcesLogs, count);
  6. } catch (SQLException ex) {
  7. _logger.error("unable to delete a log:[{}]", resourcesLogs, ex);
  8. }
  9. }

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

  1. /**
  2. * A short cut to {@link Dao#delete(PreparedDelete)}.
  3. */
  4. public int delete() throws SQLException {
  5. return dao.delete(prepare());
  6. }

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

  1. @Test(expected = RuntimeException.class)
  2. public void testDeleteThrow() 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.delete((Foo) null)).andThrow(new SQLException("Testing catch"));
  7. replay(dao);
  8. rtDao.delete((Foo) null);
  9. verify(dao);
  10. }

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

  1. @Test(expected = RuntimeException.class)
  2. public void testDeleteCollectionThrow() 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.delete((Collection<Foo>) null)).andThrow(new SQLException("Testing catch"));
  7. replay(dao);
  8. rtDao.delete((Collection<Foo>) null);
  9. verify(dao);
  10. }

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

  1. @Test(expected = RuntimeException.class)
  2. public void testDeletePreparedThrow() 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.delete((PreparedDelete<Foo>) null)).andThrow(new SQLException("Testing catch"));
  7. replay(dao);
  8. rtDao.delete((PreparedDelete<Foo>) null);
  9. verify(dao);
  10. }

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

  1. @Test
  2. public void testDeleteObjectsNone() throws Exception {
  3. Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
  4. List<Foo> fooList = new ArrayList<Foo>();
  5. assertEquals(fooList.size(), fooDao.delete(fooList));
  6. assertEquals(0, fooDao.queryForAll().size());
  7. }

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

  1. @Test(expected = SQLException.class)
  2. public void testDeleteObjectsNoId() throws Exception {
  3. Dao<NoId, Object> noIdDao = createDao(NoId.class, true);
  4. NoId noId = new NoId();
  5. noId.stuff = "1";
  6. assertEquals(1, noIdDao.create(noId));
  7. ArrayList<NoId> noIdList = new ArrayList<NoId>();
  8. noIdList.add(noId);
  9. noIdDao.delete(noIdList);
  10. }

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

  1. @Override
  2. public Void call() throws Exception {
  3. // we do the delete
  4. assertEquals(1, accountDao.delete(account));
  5. assertNull(accountDao.queryForId(account.getId()));
  6. // but then (as an example) we throw an exception which rolls back the delete
  7. throw new Exception("We throw to roll back!!");
  8. }
  9. });

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

  1. @Test
  2. public void testDeleteNull() throws Exception {
  3. Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
  4. assertEquals(0, fooDao.delete((Foo) null));
  5. }

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

  1. @Test
  2. public void testDelete() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. Foo foo = new Foo();
  5. assertEquals(1, dao.create(foo));
  6. assertNotNull(dao.queryForId(foo.id));
  7. assertEquals(1, dao.delete(foo));
  8. assertNull(dao.queryForId(foo.id));
  9. assertEquals(0, dao.queryForAll().size());
  10. }

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

  1. @Test
  2. public void testCreateReserverdTable() throws Exception {
  3. Dao<Where, String> whereDao = createDao(Where.class, true);
  4. String id = "from-string";
  5. Where where = new Where();
  6. where.id = id;
  7. whereDao.create(where);
  8. Where where2 = whereDao.queryForId(id);
  9. assertEquals(id, where2.id);
  10. assertEquals(1, whereDao.delete(where2));
  11. assertNull(whereDao.queryForId(id));
  12. }

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

  1. @Test
  2. public void testCreateReserverdTable() throws Exception {
  3. Dao<Where, String> dao = createDao(Where.class, true);
  4. String id = "from-string";
  5. Where where = new Where();
  6. where.id = id;
  7. dao.create(where);
  8. Where where2 = dao.queryForId(id);
  9. assertEquals(id, where2.id);
  10. assertEquals(1, dao.delete(where2));
  11. assertNull(dao.queryForId(id));
  12. }

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

  1. @Test
  2. public void testCreateReserverdTable() throws Exception {
  3. Dao<Create, String> whereDao = createDao(Create.class, true);
  4. String id = "from-string";
  5. Create where = new Create();
  6. where.id = id;
  7. assertEquals(1, whereDao.create(where));
  8. Create where2 = whereDao.queryForId(id);
  9. assertEquals(id, where2.id);
  10. assertEquals(1, whereDao.delete(where2));
  11. assertNull(whereDao.queryForId(id));
  12. }

相关文章