本文整理了Java中com.j256.ormlite.dao.Dao.delete()
方法的一些代码示例,展示了Dao.delete()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.delete()
方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:delete
[英]Delete the objects that match the prepared statement parameter.
[中]删除与prepared语句参数匹配的对象。
代码示例来源:origin: BaronZ88/MinimalistWeather
private void delete(Weather data) throws SQLException {
weatherDaoOperation.delete(data);
}
代码示例来源: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
/**
* @see Dao#delete(Collection)
*/
@Override
public int delete(Collection<T> datas) {
try {
return dao.delete(datas);
} catch (SQLException e) {
logMessage(e, "delete threw exception on: " + datas);
throw new RuntimeException(e);
}
}
代码示例来源:origin: j256/ormlite-core
/**
* A call through to the {@link Dao#delete(Object)}.
*/
public int delete() throws SQLException {
checkForDao();
@SuppressWarnings("unchecked")
T t = (T) this;
return dao.delete(t);
}
代码示例来源:origin: j256/ormlite-core
/**
* A short cut to {@link Dao#delete(PreparedDelete)}.
*/
public int delete() throws SQLException {
return dao.delete(prepare());
}
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#delete(PreparedDelete)
*/
@Override
public int delete(PreparedDelete<T> preparedDelete) {
try {
return dao.delete(preparedDelete);
} catch (SQLException e) {
logMessage(e, "delete threw exception on: " + preparedDelete);
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.octo.android.robospice/robospice-ormlite
public <T> void deleteFromDataBase(ForeignCollection<T> modelObjectCollection, Class<T> modelObjectClass) throws SQLException {
if (modelObjectCollection != null) {
Dao<T, ?> dao = getDao(modelObjectClass);
dao.delete(modelObjectCollection);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public void delete(ResourcesLogs resourcesLogs) {
try {
int count = this.getDao().delete(resourcesLogs);
_logger.debug("ResourcesLogs:[{}] deleted, Delete count:{}", resourcesLogs, count);
} catch (SQLException ex) {
_logger.error("unable to delete a log:[{}]", resourcesLogs, ex);
}
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* A short cut to {@link Dao#delete(PreparedDelete)}.
*/
public int delete() throws SQLException {
return dao.delete(prepare());
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = RuntimeException.class)
public void testDeleteThrow() 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.delete((Foo) null)).andThrow(new SQLException("Testing catch"));
replay(dao);
rtDao.delete((Foo) null);
verify(dao);
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = RuntimeException.class)
public void testDeleteCollectionThrow() 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.delete((Collection<Foo>) null)).andThrow(new SQLException("Testing catch"));
replay(dao);
rtDao.delete((Collection<Foo>) null);
verify(dao);
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = RuntimeException.class)
public void testDeletePreparedThrow() 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.delete((PreparedDelete<Foo>) null)).andThrow(new SQLException("Testing catch"));
replay(dao);
rtDao.delete((PreparedDelete<Foo>) null);
verify(dao);
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testDeleteObjectsNone() throws Exception {
Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
List<Foo> fooList = new ArrayList<Foo>();
assertEquals(fooList.size(), fooDao.delete(fooList));
assertEquals(0, fooDao.queryForAll().size());
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testDeleteObjectsNoId() throws Exception {
Dao<NoId, Object> noIdDao = createDao(NoId.class, true);
NoId noId = new NoId();
noId.stuff = "1";
assertEquals(1, noIdDao.create(noId));
ArrayList<NoId> noIdList = new ArrayList<NoId>();
noIdList.add(noId);
noIdDao.delete(noIdList);
}
代码示例来源: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: com.j256.ormlite/ormlite-jdbc
@Test
public void testDeleteNull() throws Exception {
Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
assertEquals(0, fooDao.delete((Foo) null));
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testDelete() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
assertNotNull(dao.queryForId(foo.id));
assertEquals(1, dao.delete(foo));
assertNull(dao.queryForId(foo.id));
assertEquals(0, dao.queryForAll().size());
}
代码示例来源: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: j256/ormlite-core
@Test
public void testCreateReserverdTable() throws Exception {
Dao<Where, String> dao = createDao(Where.class, true);
String id = "from-string";
Where where = new Where();
where.id = id;
dao.create(where);
Where where2 = dao.queryForId(id);
assertEquals(id, where2.id);
assertEquals(1, dao.delete(where2));
assertNull(dao.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));
}
内容来源于网络,如有侵权,请联系作者删除!