本文整理了Java中com.j256.ormlite.dao.Dao.deleteBuilder()
方法的一些代码示例,展示了Dao.deleteBuilder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.deleteBuilder()
方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:deleteBuilder
[英]Like #queryBuilder() but allows you to build an DELETE statement. You can then call call DeleteBuilder#prepare() and pass the returned PreparedDelete to #delete(PreparedDelete).
[中]类似于#queryBuilder(),但允许您生成DELETE语句。然后可以调用call DeleteBuilder#prepare(),并将返回的PreparedDelete传递给#delete(PreparedDelete)。
代码示例来源:origin: stackoverflow.com
//Get helper
DatabaseHelper helper = OpenHelperManager.getHelper(App.getContext(), DatabaseHelper.class);
//get dao
Dao dao = helper.getDao(YOUR_CLASS.class);
//delete elements from table in field by arg
DeleteBuilder<CanteenLog, Integer> deleteBuilder = dao.deleteBuilder();
deleteBuilder.where().eq("FIELD_NAME", arg);
deleteBuilder.delete();
代码示例来源: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: magefree/mage
public void remove(final String userName) {
try {
DeleteBuilder<AuthorizedUser, Object> db = dao.deleteBuilder();
db.where().eq("name", new SelectArg(userName));
db.delete();
} catch (SQLException ex) {
Logger.getLogger(AuthorizedUserRepository.class).error("Error removing a user from DB - ", ex);
}
}
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#deleteBuilder()
*/
@Override
public DeleteBuilder<T, ID> deleteBuilder() {
return dao.deleteBuilder();
}
代码示例来源:origin: magefree/mage
public static void updateVersion(ConnectionSource connectionSource, String entityName, long version) throws SQLException {
TableUtils.createTableIfNotExists(connectionSource, DatabaseVersion.class);
Dao<DatabaseVersion, Object> dbVersionDao = DaoManager.createDao(connectionSource, DatabaseVersion.class);
QueryBuilder<DatabaseVersion, Object> queryBuilder = dbVersionDao.queryBuilder();
queryBuilder.where().eq("entity", new SelectArg(entityName));
List<DatabaseVersion> dbVersions = dbVersionDao.query(queryBuilder.prepare());
if (!dbVersions.isEmpty()) {
DeleteBuilder<DatabaseVersion, Object> deleteBuilder = dbVersionDao.deleteBuilder();
deleteBuilder.where().eq("entity", new SelectArg(entityName));
deleteBuilder.delete();
}
DatabaseVersion databaseVersion = new DatabaseVersion();
databaseVersion.setEntity(entityName);
databaseVersion.setVersion(version);
dbVersionDao.create(databaseVersion);
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public void deleteBySensorVariableRefId(int sensorValueRefId) {
try {
DeleteBuilder<MetricsCounterTypeDevice, Object> deleteBuilder = this.getDao().deleteBuilder();
deleteBuilder.where().eq(MetricsCounterTypeDevice.KEY_SENSOR_VARIABLE_ID, sensorValueRefId);
int count = deleteBuilder.delete();
_logger.debug("Metric-sensorValueRefId:[{}] deleted, Delete count:{}", sensorValueRefId, count);
} catch (SQLException ex) {
_logger.error("unable to delete metric-sensorValueRefId:[{}]", sensorValueRefId, ex);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
public void delete(String key, Object value) {
try {
DeleteBuilder<Tdao, Tid> deleteBuilder = this.getDao().deleteBuilder();
deleteBuilder.where().eq(key, value);
int deleteCount = deleteBuilder.delete();
_logger.debug("Deleted count:{}, for key:{}, value:{}", deleteCount, key, value);
} catch (SQLException ex) {
_logger.error("unable to delete item, key:{}, value:{}", key, value, ex);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public void deleteBySensorVariableRefId(int sensorValueRefId) {
try {
DeleteBuilder<MetricsDoubleTypeDevice, Object> deleteBuilder = this.getDao().deleteBuilder();
deleteBuilder.where().eq(MetricsDoubleTypeDevice.KEY_SENSOR_VARIABLE_ID, sensorValueRefId);
int count = deleteBuilder.delete();
_logger.debug("Metric-sensorValueRefId:[{}] deleted, Delete count:{}", sensorValueRefId, count);
} catch (SQLException ex) {
_logger.error("unable to delete metric-sensorValueRefId:[{}]", sensorValueRefId, ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public void deleteByNodeId(int nodeId) {
try {
DeleteBuilder<MetricsBatteryUsage, Object> deleteBuilder = this.getDao().deleteBuilder();
deleteBuilder.where().eq(MetricsBatteryUsage.KEY_NODE_ID, nodeId);
int count = deleteBuilder.delete();
_logger.debug("Metric-nodeId:[{}] deleted, Delete count:{}", nodeId, count);
} catch (SQLException ex) {
_logger.error("unable to delete metric-nodeId:[{}]", nodeId, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: PaNaVTEC/Clean-Contacts
private void internalDeleteContacts(List<String> deleteMd5s) throws SQLException {
DeleteBuilder<BddContact, Integer> deleteBuilder = daoContacts.deleteBuilder();
deleteBuilder.where().in(BddContact.FIELD_MD5, deleteMd5s);
deleteBuilder.delete();
}
}
代码示例来源:origin: mycontroller-org/mycontroller
public void delete(String key, Object value) {
try {
DeleteBuilder<Tdao, Tid> deleteBuilder = this.getDao().deleteBuilder();
deleteBuilder.where().eq(key, value);
int deleteCount = deleteBuilder.delete();
_logger.debug("Deleted count:{}, for key:{}, value:{}", deleteCount, key, value);
} catch (SQLException ex) {
_logger.error("unable to delete item, key:{}, value:{}", key, value, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
public void delete(String key, List<?> values) {
try {
DeleteBuilder<Tdao, Tid> deleteBuilder = this.getDao().deleteBuilder();
deleteBuilder.where().in(key, values);
int deleteCount = deleteBuilder.delete();
_logger.debug("Deleted count:{}, for key:{}, values:{}", deleteCount, key, values);
} catch (SQLException ex) {
_logger.error("unable to delete item, key:{}, values:{}", key, values, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public void deleteBySensorVariableRefId(int sensorValueRefId) {
try {
DeleteBuilder<MetricsGPSTypeDevice, Object> deleteBuilder = this.getDao().deleteBuilder();
deleteBuilder.where().eq(MetricsGPSTypeDevice.KEY_SENSOR_VARIABLE_ID, sensorValueRefId);
int count = deleteBuilder.delete();
_logger.debug("Metric-sensorValueRefId:[{}] deleted, Delete count:{}", sensorValueRefId, count);
} catch (SQLException ex) {
_logger.error("unable to delete metric-sensorValueRefId:[{}]", sensorValueRefId, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public void delete(Integer typeId, Integer versionId) {
DeleteBuilder<Firmware, Integer> deleteBuilder = getDao().deleteBuilder();
try {
deleteBuilder.where().eq(Firmware.KEY_TYPE_ID, typeId).and().eq(Firmware.KEY_VERSION_ID, versionId);
int count = deleteBuilder.delete();
_logger.error("Deleted Firmware(s) count:[{}]", count);
} catch (SQLException ex) {
_logger.error("unable to delete Firmware:[typeId:{},versionId:{}]", typeId, versionId, ex);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public void deleteAll(RESOURCE_TYPE resourceType, Integer resourceId) {
try {
DeleteBuilder<ResourcesLogs, Integer> deleteBuilder = this.getDao().deleteBuilder();
this.updateWhereQuery(deleteBuilder.where(), resourceType, resourceId);
int deleteCount = deleteBuilder.delete();
_logger.debug("Deleted Resource:[Type:{}, KEY_ID:{}], delete count:{}", resourceType.getText(),
resourceId,
deleteCount);
} catch (SQLException ex) {
_logger.error("unable to delete Resource:[Type:{}, KEY_ID:{}]", resourceType.getText(), resourceId, ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public void delete(Integer typeId, Integer versionId) {
DeleteBuilder<Firmware, Integer> deleteBuilder = getDao().deleteBuilder();
try {
deleteBuilder.where().eq(Firmware.KEY_TYPE_ID, typeId).and().eq(Firmware.KEY_VERSION_ID, versionId);
int count = deleteBuilder.delete();
_logger.error("Deleted Firmware(s) count:[{}]", count);
} catch (SQLException ex) {
_logger.error("unable to delete Firmware:[typeId:{},versionId:{}]", typeId, versionId, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: QuickBlox/q-municate-android
public void deleteByUserId(int userId) {
try {
DeleteBuilder<UserRequest, Long> deleteBuilder = dao.deleteBuilder();
deleteBuilder.where().eq(QMUserColumns.ID, userId);
if (deleteBuilder.delete() > 0) {
//TODO VT need to think how to send ID to observers
notifyObserversDeletedById(userId);
}
} catch (SQLException e) {
ErrorUtils.logError(e);
}
}
代码示例来源:origin: QuickBlox/q-municate-android
public void deleteById(String dialogId) {
try {
DeleteBuilder<Dialog, Long> deleteBuilder = dao.deleteBuilder();
deleteBuilder.where().eq(Dialog.Column.ID, dialogId);
if (deleteBuilder.delete() > 0){
//TODO VT need to think how to send ID to observers
notifyObserversDeletedById(dialogId);
}
} catch (SQLException e) {
ErrorUtils.logError(e);
}
}
代码示例来源:origin: QuickBlox/q-municate-android
@Override
public void deleteUserByExternalId(String externalId) {
try {
DeleteBuilder<QMUser, Long> deleteBuilder = dao.deleteBuilder();
deleteBuilder.where().eq(EXTERNAL_ID,externalId);
PreparedDelete<QMUser> preparedQuery = deleteBuilder.prepare();
dao.delete(preparedQuery);
notifyObservers(OBSERVE_KEY);
} catch (SQLException e) {
ErrorUtils.logError(e);
}
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testDeletePreparedThrow() 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.delete(dao.deleteBuilder().prepare());
} finally {
connectionSource.releaseConnection(conn);
}
}
内容来源于网络,如有侵权,请联系作者删除!