Java Code Examples for com.j256.ormlite.stmt.UpdateBuilder#update()

The following examples show how to use com.j256.ormlite.stmt.UpdateBuilder#update() . 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: OrmLiteDao.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
/**
 * 如果更新记录字段值为null则忽略不更新
 *
 * @param t
 * @return
 */
private int updateIfValueNotNull(T t) throws SQLException, IllegalAccessException {
    UpdateBuilder updateBuilder = ormLiteDao.updateBuilder();
    Map<String, Object> map = getFieldsIfValueNotNull(t);
    if (map.isEmpty()) {
        throw new SQLException("all field value is null.");
    }
    if (map.get("id") == null) {
        throw new SQLException("id is null.");
    }
    updateBuilder.where().idEq(map.get("id"));
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        if (entry.getKey().equals("id")) {
            continue;
        }
        updateBuilder.updateColumnValue(entry.getKey(), entry.getValue());
    }
    return updateBuilder.update();
}
 
Example 2
Source File: GameRankingBiz.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
/**
 * 把没有用户的数据更新为当前用户的信息
 * 
 * @param userName
 */
public int updateRecordToNewUser(String userName)
{
	UpdateBuilder<GameRanking, ?> ub = getDao().updateBuilder();
	try
	{
		ub.updateColumnValue("user_name", userName);
		ub.updateColumnValue("nickname", userName);
		ub.where().isNull("user_name").or().eq("user_name", "");

		return ub.update();
	}
	catch (SQLException e)
	{
		e.printStackTrace();
	}

	return -1;
}
 
Example 3
Source File: LocalSqliteDriverImpl.java    From mae-annotation with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean updateTagText(ExtentTag tag, String text) throws MaeDBException {
    try {
        UpdateBuilder<ExtentTag, String> updateBuilder = eTagDao.updateBuilder();
        updateBuilder.where().eq(TAB_TAG_COL_TID, tag.getId());
        updateBuilder.updateColumnValue(TAB_ETAG_COL_TEXT,  text);
        if (updateBuilder.update() == 1) {
            setAnnotationChanged(true);
            eTagDao.refresh(tag);
            return true;
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return false;

}
 
Example 4
Source File: DBController.java    From AndroidDownloader with Apache License 2.0 5 votes vote down vote up
@Override
public void pauseAllDownloading() {

    try {
        UpdateBuilder<MyDownloadInfLocal, String> myDownloadInfLocalIntegerUpdateBuilder = myDownloadInfLocalDao
                .updateBuilder();
        myDownloadInfLocalIntegerUpdateBuilder.updateColumnValue("status", STATUS_PAUSED).where()
                .ne("status", STATUS_COMPLETED);
        myDownloadInfLocalIntegerUpdateBuilder.update();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: CoursePreviewInfo.java    From file-downloader with Apache License 2.0 5 votes vote down vote up
@Override
public void onDownloadFileUpdated(DownloadFileInfo downloadFileInfo, Type type) {

    if (downloadFileInfo != null && downloadFileInfo.getUrl() != null && downloadFileInfo.getUrl().equals
            (mCourseUrl)) {
        if (this.mDownloadFileInfo == null) {
            try {
                if (mCourseDbHelper == null) {
                    return;
                }
                UpdateBuilder builder = mCourseDbHelper.getDao(CoursePreviewInfo.class).updateBuilder();
                builder.where().eq(CoursePreviewInfo.COLUMN_NAME_OF_FIELD_COURSE_URL, downloadFileInfo.getUrl());
                int result = builder.update();
                if (result == 1) {
                    this.mDownloadFileInfo = downloadFileInfo;
                } else {
                    Dao<CoursePreviewInfo, Integer> dao = mCourseDbHelper.getDao(CoursePreviewInfo.class);
                    CreateOrUpdateStatus status = dao.createOrUpdate(this);
                    if (status.isCreated() || status.isUpdated()) {
                        this.mDownloadFileInfo = downloadFileInfo;
                    }
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}
 
Example 6
Source File: DatabaseHelper.java    From android-viewer-for-khan-academy with GNU General Public License v3.0 5 votes vote down vote up
private void resetDownloadStatusAndDlmId(long dlm_id) {
	try {
		UpdateBuilder<Video, String> q = getVideoDao().updateBuilder();
		q.where().eq("dlm_id", dlm_id);
		q.updateColumnValue("dlm_id", 0);
		q.updateColumnValue("download_status", Video.DL_STATUS_NOT_STARTED);
		q.update();
	} catch (SQLException e) {
		e.printStackTrace();
	}
}