Java Code Examples for com.j256.ormlite.stmt.DeleteBuilder#delete()

The following examples show how to use com.j256.ormlite.stmt.DeleteBuilder#delete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatabaseHelper.java    From android-overlay-protection with Apache License 2.0 6 votes vote down vote up
/**
 * This is called when your application is upgraded and it has a higher version number. This allows you to adjust
 * the various data to match the new version number.
 */
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
    try {
        Log.i(TAG, "onUpgrade");
        TableUtils.dropTable(connectionSource, SuspectedApp.class, true);
        Log.d(TAG, String.format("Dropped suspected app table!"));
        Dao<WhiteEntry, Integer> whiteListDao = getWhiteListDao();
        DeleteBuilder<WhiteEntry, Integer> deleteBuilder = whiteListDao.deleteBuilder();
        deleteBuilder.where().eq("systemEntry", Boolean.TRUE);
        int deleted = deleteBuilder.delete();
        Log.d(TAG, String.format("Delete %d old system whitelist entries", deleted));
        onCreate(db, connectionSource);
    } catch (SQLException e) {
        Log.e(TAG, "Can't drop databases", e);
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: LocalAlbumBiz.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
@Override
public int deleteAll()
{
	try
	{
		DeleteBuilder<FocusItemInfo, Long> deleteBuilder = mFocusItemInfoDao.deleteBuilder();
		deleteBuilder.where().isNotNull("id");
		return deleteBuilder.delete();
	}
	catch (SQLException e)
	{
		e.printStackTrace();
	}
	
	return super.deleteAll();
}
 
Example 3
Source File: MyFavoritesBiz.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
@Override
public int deleteAll()
{
	try
	{
		DeleteBuilder<MyFavorites, Long> deleteBuilder = mMyFavoritesDao.deleteBuilder();
		deleteBuilder.where().isNotNull("albumid");
		
		return deleteBuilder.delete();
	}
	catch (SQLException e)
	{
		e.printStackTrace();
	}
	
	return super.deleteAll();
}
 
Example 4
Source File: PhotoBiz.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param albumid
 * @return
 */
public int deleteByAlbumid(String albumid)
{
	try
	{
		DeleteBuilder<PhotoInfo, Long> deleteBuilder = mPhotoDao.deleteBuilder();
		deleteBuilder.where().eq("albumid", albumid);
		return deleteBuilder.delete();
	}
	catch (SQLException e)
	{
		e.printStackTrace();
	}
	
	return super.deleteAll();
}
 
Example 5
Source File: AlbumBiz.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
@Override
public int deleteAll()
{
	try
	{
		DeleteBuilder<AlbumInfo, Long> deleteBuilder = mAlbumDao.deleteBuilder();
		deleteBuilder.where().isNotNull("albumid");
		return deleteBuilder.delete();
	}
	catch (SQLException e)
	{
		e.printStackTrace();
	}
	
	return super.deleteAll();
}
 
Example 6
Source File: MessageDataManager.java    From q-municate-android with Apache License 2.0 6 votes vote down vote up
public void deleteTempMessages(List<Long> dialogOccupantsIdsList) {
    try {
        DeleteBuilder<Message, Long> deleteBuilder = dao.deleteBuilder();

        Where<Message, Long> where = deleteBuilder.where();
        where.and(
                where.in(DialogOccupant.Column.ID, dialogOccupantsIdsList),
                where.or(
                        where.eq(Message.Column.STATE, State.TEMP_LOCAL),
                        where.eq(Message.Column.STATE, State.TEMP_LOCAL_UNREAD)
                )
        );

        if (deleteBuilder.delete() > 0) {
            //TODO VT need to think how to send IDs to observers
            notifyObserversDeletedById(dialogOccupantsIdsList);
        }
    } catch (SQLException e) {
        ErrorUtils.logError(e);
    }

}
 
Example 7
Source File: DialogDataManager.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 8
Source File: DetectedOverlayFragment.java    From android-overlay-protection with Apache License 2.0 5 votes vote down vote up
private void clearHistory() {
    try {
        Dao<DetectedOverlay, Integer> detectedOverlayDao = DatabaseHelper.getHelper(getActivity()).getDetectedOverlayDao();
        DeleteBuilder<DetectedOverlay, Integer> deleteBuilder = detectedOverlayDao.deleteBuilder();
        deleteBuilder.where().gt("id", 0);
        int deleted = deleteBuilder.delete();
        Log.i(getTag(), "Deleted " + deleted + " entries from DetectedOverlay");
    } catch (SQLException e) {
        Log.e(getTag(), "Failed to deleted entries", e);
    }
    mAdapter.clear();
}
 
Example 9
Source File: QMAbstractBaseCache.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
@Override
public void clear() {
    DeleteBuilder<T, ID> deleteBuilder = dao.deleteBuilder();
    try {
        deleteBuilder.delete();
    } catch (SQLException e) {
        ErrorUtils.logError(e);
    }
}
 
Example 10
Source File: UserRequestDataManager.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
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);
    }

}
 
Example 11
Source File: RemoveAllPendingGroupApprovalsForScope.java    From passopolis-server with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected MitroRPC processCommand(MitroRequestContext context) throws IOException, SQLException, MitroServletException {
  RPC.RemoveAllPendingGroupApprovalsForScopeRequest in = gson.fromJson(context.jsonRequest, RPC.RemoveAllPendingGroupApprovalsForScopeRequest.class);
  
  // TODO: verify auth
  
  DeleteBuilder<DBPendingGroup, Integer> deleter = context.manager.pendingGroupDao.deleteBuilder();
  deleter.where().eq(DBPendingGroup.SCOPE_NAME, new SelectArg(in.scope));
  deleter.delete();
  
  context.manager.addAuditLog(DBAudit.ACTION.REMOVE_PENDING_GROUP_SYNC, context.requestor, null, /*group*/null, null, in.scope);
  return new MitroRPC();
}
 
Example 12
Source File: DataColumnConstraintsDao.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * Delete using the unique columns
 */
@Override
public int delete(DataColumnConstraints dataColumnConstraints)
		throws SQLException {

	DeleteBuilder<DataColumnConstraints, Void> db = deleteBuilder();

	setUniqueWhere(db.where(), dataColumnConstraints.getConstraintName(),
			dataColumnConstraints.getConstraintType(),
			dataColumnConstraints.getValue());

	int deleted = db.delete();

	return deleted;
}
 
Example 13
Source File: OrmLiteDao.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * 通过表列名来删除
 *
 * @param map key是列名,value是列对应的值
 * @return
 */
public boolean deleteByColumnName(Map<String, Object> map) throws SQLException {
    DeleteBuilder deleteBuilder = ormLiteDao.deleteBuilder();
    Where where = deleteBuilder.where();
    where.isNotNull("id");
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        where.and().eq(entry.getKey(), entry.getValue());
    }
    return deleteBuilder.delete() > 0;
}
 
Example 14
Source File: OrmLiteDao.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * 清空表数据
 *
 * @return
 */
public boolean clearTableData() throws SQLException {
    long count = ormLiteDao.countOf();
    if (count == 0) {
        return true;
    }
    DeleteBuilder deleteBuilder = ormLiteDao.deleteBuilder();
    deleteBuilder.where().isNotNull("id");
    return deleteBuilder.delete() > 0;
}
 
Example 15
Source File: ExtensionsDao.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Delete by extension name
 * 
 * @param extensionName
 *            extension name
 * @return deleted count
 * @throws SQLException
 *             upon failure
 */
public int deleteByExtension(String extensionName) throws SQLException {

	DeleteBuilder<Extensions, Void> db = deleteBuilder();
	db.where().eq(Extensions.COLUMN_EXTENSION_NAME, extensionName);

	int deleted = db.delete();

	return deleted;
}
 
Example 16
Source File: ExtensionsDao.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Delete by extension name and table name
 * 
 * @param extensionName
 *            extension name
 * @param tableName
 *            table name
 * @return deleted count
 * @throws SQLException
 *             upon failure
 */
public int deleteByExtension(String extensionName, String tableName)
		throws SQLException {

	DeleteBuilder<Extensions, Void> db = deleteBuilder();

	setUniqueWhere(db.where(), extensionName, true, tableName, false, null);

	int deleted = db.delete();

	return deleted;
}
 
Example 17
Source File: ExtensionsDao.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Delete by table name
 * 
 * @param tableName
 *            table name
 * @return rows deleted
 * @throws SQLException
 *             upon failure
 * @since 1.1.8
 */
public int deleteByTableName(String tableName) throws SQLException {

	DeleteBuilder<Extensions, Void> db = deleteBuilder();

	db.where().eq(Extensions.COLUMN_TABLE_NAME, tableName);

	int deleted = db.delete();

	return deleted;
}
 
Example 18
Source File: ExtensionsDao.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Delete all extensions
 * 
 * @return rows deleted
 * @throws SQLException
 *             upon failure
 * @since 1.1.8
 */
public int deleteAll() throws SQLException {

	DeleteBuilder<Extensions, Void> db = deleteBuilder();
	int deleted = db.delete();

	return deleted;
}
 
Example 19
Source File: OrmLiteDao.java    From AndroidBase with Apache License 2.0 2 votes vote down vote up
/**
 * 删除小于指定列的值的所有数据
 *
 * @param columnName 指定列名
 * @param value      指定数值,小于该值的数据将被删除
 * @return 删除的条数
 */
public int deleteLtValue(String columnName, Object value) throws SQLException {
    DeleteBuilder deleteBuilder = ormLiteDao.deleteBuilder();
    deleteBuilder.where().lt(columnName, value);
    return deleteBuilder.delete();
}
 
Example 20
Source File: OrmLiteDao.java    From AndroidBase with Apache License 2.0 2 votes vote down vote up
/**
 * 按条件删除
 *
 * @param columnName 指定删除条件列名
 * @param value      删除条件对应的值
 * @return
 */
public boolean deleteByColumnName(String columnName, Object value) throws SQLException {
    DeleteBuilder deleteBuilder = ormLiteDao.deleteBuilder();
    deleteBuilder.where().eq(columnName, value);
    return deleteBuilder.delete() > 0;
}