com.lidroid.xutils.exception.DbException Java Examples

The following examples show how to use com.lidroid.xutils.exception.DbException. 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 Project: android-open-project-demo   Author: android-cn   File: DbUtils.java    License: Apache License 2.0 6 votes vote down vote up
public void saveBindingIdAll(List<?> entities) throws DbException {
    if (entities == null || entities.size() == 0) return;
    try {
        beginTransaction();

        createTableIfNotExist(entities.get(0).getClass());
        for (Object entity : entities) {
            if (!saveBindingIdWithoutTransaction(entity)) {
                throw new DbException("saveBindingId error, transaction will not commit!");
            }
        }

        setTransactionSuccessful();
    } finally {
        endTransaction();
    }
}
 
Example #2
Source Project: Gizwits-SmartBuld_Android   Author: gizwits   File: GosScheduleData.java    License: MIT License 6 votes vote down vote up
private void immediatelySetToSite(final Handler handler) {
	siteTool.setCommadOnSite(getDate(), getTime(), getRepeat(), getAttrsMapFromDate(), new OnResponListener() {

		@Override
		public void OnRespon(int result, String arg0) {
			if (result == 0) {
				// 数据库已经存在
				setRuleID(arg0);// 创建成功后记录id
				setDeleteOnsite(false);// 更新删除状态
				setViewContent();// 更新显示内容
				try {
					dbUtils.saveOrUpdate(GosScheduleData.this);// 更新整条数据
				} catch (DbException e) {
					e.printStackTrace();
				}
				handler.sendEmptyMessage(GosScheduleListActivity.handler_key.SET.ordinal());
			} else {
				handler.sendEmptyMessage(GosScheduleListActivity.handler_key.FAIL.ordinal());
			}
		}
	});
}
 
Example #3
Source Project: Gizwits-SmartBuld_Android   Author: gizwits   File: GosScheduleData.java    License: MIT License 6 votes vote down vote up
/**
 * Description:将此数据从云端中删除
 * 
 * @param handler
 *            利用handler来进行结果的异步回调
 */
public void deleteOnSite(final Handler handler) {
	siteTool.deleteTimeOnSite(getRuleID(), new OnResponListener() {

		@Override
		public void OnRespon(int result, String arg0) {
			if (result == 0) {
				setDeleteOnsite(true);// 更新删除状态
				setViewContent();// 更新显示内容
				try {
					dbUtils.saveOrUpdate(GosScheduleData.this);// 更新整条数据
				} catch (DbException e) {
					e.printStackTrace();
				}
				handler.sendEmptyMessage(GosScheduleListActivity.handler_key.DELETE.ordinal());
			}
		}
	});

}
 
Example #4
Source Project: Gizwits-SmartBuld_Android   Author: gizwits   File: GosScheduleListActivity.java    License: MIT License 6 votes vote down vote up
private void initDate() {
	siteTool = new GosScheduleSiteTool(this, device, spf.getString("Token", ""));
	DbUtils.DaoConfig config = new DaoConfig(this);
	config.setDbName("gizwits");
	config.setDbVersion(1); // db版本
	dbUtils = DbUtils.create(config);// db还有其他的一些构造方法,比如含有更新表版本的监听器的DbUtils
	try {
		// 创建一张表
		dbUtils.createTableIfNotExist(GosScheduleData.class);
	} catch (DbException e) {
		e.printStackTrace();
	}
	GosScheduleData.setSiteTool(siteTool);
	GosScheduleData.setDbUtils(dbUtils);
	GosScheduleData.setContext(getApplicationContext());
	setProgressDialog(getResources().getString(R.string.site_setting_time), true, false);
}
 
Example #5
Source Project: AndroidAppCodeFramework   Author: Frank-Zhu   File: DownloadManager.java    License: Apache License 2.0 6 votes vote down vote up
public void addNewDownload(String url, String fileName, String target,
                           boolean autoResume, boolean autoRename,
                           final RequestCallBack<File> callback) throws DbException {
    final DownloadInfo downloadInfo = new DownloadInfo();
    downloadInfo.setDownloadUrl(url);
    downloadInfo.setAutoRename(autoRename);
    downloadInfo.setAutoResume(autoResume);
    downloadInfo.setFileName(fileName);
    downloadInfo.setFileSavePath(target);
    HttpUtils http = new HttpUtils();
    http.configRequestThreadPoolSize(maxDownloadThread);
    HttpHandler<File> handler = http.download(url, target, autoResume, autoRename, new ManagerCallBack(downloadInfo, callback));
    downloadInfo.setHandler(handler);
    downloadInfo.setState(handler.getState());
    downloadInfoList.add(downloadInfo);
    db.saveBindingId(downloadInfo);
}
 
Example #6
Source Project: android-open-project-demo   Author: android-cn   File: DbUtils.java    License: Apache License 2.0 6 votes vote down vote up
public List<DbModel> findDbModelAll(DbModelSelector selector) throws DbException {
    if (!tableIsExist(selector.getEntityType())) return null;

    List<DbModel> dbModelList = new ArrayList<DbModel>();

    Cursor cursor = execQuery(selector.toString());
    if (cursor != null) {
        try {
            while (cursor.moveToNext()) {
                dbModelList.add(CursorUtils.getDbModel(cursor));
            }
        } catch (Throwable e) {
            throw new DbException(e);
        } finally {
            IOUtils.closeQuietly(cursor);
        }
    }
    return dbModelList;
}
 
Example #7
Source Project: AndroidAppCodeFramework   Author: Frank-Zhu   File: DownloadManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onLoading(long total, long current, boolean isUploading) {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    downloadInfo.setFileLength(total);
    downloadInfo.setProgress(current);
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onLoading(total, current, isUploading);
    }
}
 
Example #8
Source Project: AndroidAppCodeFramework   Author: Frank-Zhu   File: DownloadManager.java    License: Apache License 2.0 6 votes vote down vote up
public void addNewDownload(String url, String fileName, String target,
                           boolean autoResume, boolean autoRename,
                           final RequestCallBack<File> callback) throws DbException {
    final DownloadInfo downloadInfo = new DownloadInfo();
    downloadInfo.setDownloadUrl(url);
    downloadInfo.setAutoRename(autoRename);
    downloadInfo.setAutoResume(autoResume);
    downloadInfo.setFileName(fileName);
    downloadInfo.setFileSavePath(target);
    HttpUtils http = new HttpUtils();
    http.configRequestThreadPoolSize(maxDownloadThread);
    HttpHandler<File> handler = http.download(url, target, autoResume, autoRename, new ManagerCallBack(downloadInfo, callback));
    downloadInfo.setHandler(handler);
    downloadInfo.setState(handler.getState());
    downloadInfoList.add(downloadInfo);
    db.saveBindingId(downloadInfo);
}
 
Example #9
Source Project: AndroidAppCodeFramework   Author: Frank-Zhu   File: DownloadManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onLoading(long total, long current, boolean isUploading) {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    downloadInfo.setFileLength(total);
    downloadInfo.setProgress(current);
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onLoading(total, current, isUploading);
    }
}
 
Example #10
Source Project: ALLGO   Author: HsingPeng   File: MyEventLogicImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void saveEvent(ArrayList<EventVo> eventsData) {
	
	SharedPreferences sharedPref = context.getSharedPreferences("userdata",Context.MODE_PRIVATE);
	int uid = sharedPref.getInt("uid", -1) ;
   	try{
	    DbUtils db = DbUtils.create(context,uid + ".db");
	    db.configAllowTransaction(true);
        db.configDebug(true);
        db.deleteAll(MyEventVo.class);
        Log.i("DB", "deleteAll =saveBindingId=>" + eventsData.size()) ;
        for(int i=0 ; i<20 && i<eventsData.size() ; i++){
        	db.save(ChangEventVo.event2MyEvent(eventsData.get(i)));
        }
		}catch(DbException e){
	    	Log.e("DB", "error :" + e.getMessage() + "\n");
	    }

}
 
Example #11
Source Project: android-open-project-demo   Author: android-cn   File: SqlInfoBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public static SqlInfo buildDeleteSqlInfo(DbUtils db, Object entity) throws DbException {
    SqlInfo result = new SqlInfo();

    Class<?> entityType = entity.getClass();
    Table table = Table.get(db, entityType);
    Id id = table.id;
    Object idValue = id.getColumnValue(entity);

    if (idValue == null) {
        throw new DbException("this entity[" + entity.getClass() + "]'s id value is null");
    }
    StringBuilder sb = new StringBuilder(buildDeleteSqlByTableName(table.tableName));
    sb.append(" WHERE ").append(WhereBuilder.b(id.getColumnName(), "=", idValue));

    result.setSql(sb.toString());

    return result;
}
 
Example #12
Source Project: android-open-project-demo   Author: android-cn   File: DbUtils.java    License: Apache License 2.0 6 votes vote down vote up
private long getLastAutoIncrementId(String tableName) throws DbException {
    long id = -1;
    Cursor cursor = execQuery("SELECT seq FROM sqlite_sequence WHERE name='" + tableName + "'");
    if (cursor != null) {
        try {
            if (cursor.moveToNext()) {
                id = cursor.getLong(0);
            }
        } catch (Throwable e) {
            throw new DbException(e);
        } finally {
            IOUtils.closeQuietly(cursor);
        }
    }
    return id;
}
 
Example #13
Source Project: android-open-project-demo   Author: android-cn   File: DbUtils.java    License: Apache License 2.0 6 votes vote down vote up
public boolean tableIsExist(Class<?> entityType) throws DbException {
    Table table = Table.get(this, entityType);
    if (table.isCheckedDatabase()) {
        return true;
    }

    Cursor cursor = execQuery("SELECT COUNT(*) AS c FROM sqlite_master WHERE type='table' AND name='" + table.tableName + "'");
    if (cursor != null) {
        try {
            if (cursor.moveToNext()) {
                int count = cursor.getInt(0);
                if (count > 0) {
                    table.setCheckedDatabase(true);
                    return true;
                }
            }
        } catch (Throwable e) {
            throw new DbException(e);
        } finally {
            IOUtils.closeQuietly(cursor);
        }
    }

    return false;
}
 
Example #14
Source Project: qingyang   Author: zqingyang521   File: DBManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 删除上传信息
 * 
 * @param uploadfilepath
 * @return
 */
public boolean delUpload(String uploadfilepath) {

	Selector selector = Selector.from(Upload.class);

	selector.where(WhereBuilder.b("uploadfilepath", "=", uploadfilepath));

	try {
		Upload upload = db.findFirst(selector);

		db.delete(upload);
	} catch (DbException e) {
		e.printStackTrace();
		return false;
	}
	return true;
}
 
Example #15
Source Project: qingyang   Author: zqingyang521   File: DBManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取上传资源Id
 * 
 * @param uploadfilepath
 * @return
 */
public String getBindId(String uploadfilepath) {

	Selector selector = Selector.from(Upload.class);

	selector.where(WhereBuilder.b("uploadfilepath", "=", uploadfilepath));

	String bindId = "";

	try {
		Upload upload = db.findFirst(selector);

		if (upload == null) {
			return "";
		}
		bindId = upload.getSourceid();
	} catch (DbException e) {
		e.printStackTrace();
		return "";
	}
	return bindId;
}
 
Example #16
Source Project: android-open-project-demo   Author: android-cn   File: SqlInfoBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public static SqlInfo buildCreateTableSqlInfo(DbUtils db, Class<?> entityType) throws DbException {
    Table table = Table.get(db, entityType);
    Id id = table.id;

    StringBuffer sqlBuffer = new StringBuffer();
    sqlBuffer.append("CREATE TABLE IF NOT EXISTS ");
    sqlBuffer.append(table.tableName);
    sqlBuffer.append(" ( ");

    if (id.isAutoIncrement()) {
        sqlBuffer.append("\"").append(id.getColumnName()).append("\"  ").append("INTEGER PRIMARY KEY AUTOINCREMENT,");
    } else {
        sqlBuffer.append("\"").append(id.getColumnName()).append("\"  ").append(id.getColumnDbType()).append(" PRIMARY KEY,");
    }

    Collection<Column> columns = table.columnMap.values();
    for (Column column : columns) {
        if (column instanceof Finder) {
            continue;
        }
        sqlBuffer.append("\"").append(column.getColumnName()).append("\"  ");
        sqlBuffer.append(column.getColumnDbType());
        if (ColumnUtils.isUnique(column.getColumnField())) {
            sqlBuffer.append(" UNIQUE");
        }
        if (ColumnUtils.isNotNull(column.getColumnField())) {
            sqlBuffer.append(" NOT NULL");
        }
        String check = ColumnUtils.getCheck(column.getColumnField());
        if (check != null) {
            sqlBuffer.append(" CHECK(").append(check).append(")");
        }
        sqlBuffer.append(",");
    }

    sqlBuffer.deleteCharAt(sqlBuffer.length() - 1);
    sqlBuffer.append(" )");
    return new SqlInfo(sqlBuffer.toString());
}
 
Example #17
Source Project: BigApp_Discuz_Android   Author: BigAppOS   File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static List<EmoticonBean> getAllEmojis(Context context) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        return dbUtils.findAll(EmoticonBean.class);
    } catch (DbException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #18
Source Project: BigApp_Discuz_Android   Author: BigAppOS   File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static List<EmoticonBean> getEmojiGroup(Context context, String group) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        return dbUtils.findAll(Selector.from(EmoticonBean.class).where("groupName", "=", group));
    } catch (DbException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #19
Source Project: BigApp_Discuz_Android   Author: BigAppOS   File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static EmoticonBean getEmojiByUnicode(Context context, String unicode) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        return dbUtils.findFirst(Selector.from(EmoticonBean.class).where("content", "=", unicode));
    } catch (DbException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #20
Source Project: android-open-project-demo   Author: android-cn   File: DbUtils.java    License: Apache License 2.0 5 votes vote down vote up
public void update(Object entity, String... updateColumnNames) throws DbException {
    if (!tableIsExist(entity.getClass())) return;
    try {
        beginTransaction();

        execNonQuery(SqlInfoBuilder.buildUpdateSqlInfo(this, entity, updateColumnNames));

        setTransactionSuccessful();
    } finally {
        endTransaction();
    }
}
 
Example #21
Source Project: android-open-project-demo   Author: android-cn   File: ForeignLazyLoader.java    License: Apache License 2.0 5 votes vote down vote up
public List<T> getAllFromDb() throws DbException {
    List<T> entities = null;
    Table table = foreignColumn.getTable();
    if (table != null) {
        entities = table.db.findAll(
                Selector.from(foreignColumn.getForeignEntityType()).
                        where(foreignColumn.getForeignColumnName(), "=", columnValue)
        );
    }
    return entities;
}
 
Example #22
Source Project: BigApp_Discuz_Android   Author: BigAppOS   File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static List<EmoticonSetBean> getAllEmojiSet(Context context) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        List<EmoticonSetBean> setBean = dbUtils.findAll(EmoticonSetBean.class);
        return setBean;
    } catch (DbException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #23
Source Project: BigApp_Discuz_Android   Author: BigAppOS   File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static List<EmoticonSetBean> getEmojiLibraryByGroup(Context context, String name, String group) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        EmoticonSetBean setBean = dbUtils.findFirst(Selector.from(EmoticonSetBean.class).where("name", "=", name));
        List<EmoticonBean> beans = getEmojiGroup(context, group);
        setBean.setEmoticonList(beans);
        List<EmoticonSetBean> list = new ArrayList<EmoticonSetBean>();
        list.add(setBean);
        return list;
    } catch (DbException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #24
Source Project: BigApp_Discuz_Android   Author: BigAppOS   File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static void clear(Context context) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        dbUtils.dropTable(EmoticonSetBean.class);
        dbUtils.dropTable(EmoticonBean.class);
    } catch (DbException e) {
        e.printStackTrace();
    }
}
 
Example #25
Source Project: QiQuYing   Author: liuling07   File: DingCaiDAO.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 检查是否点过赞
 * @param userId
 * @param jokeId
 * @return
 */
public DingOrCai getDingOrCai(int userId, int jokeId) {
	DbUtils db = DbUtils.create(context);
	DingOrCai dingOrCai = null;
	try {
		dingOrCai = db.findFirst(Selector.from(DingOrCai.class).where(WhereBuilder.b("user_id", "=", userId).and("joke_id", "=", jokeId)));
		Log.d(TAG, "getDingOrCai success");
	} catch (DbException e) {
		Log.d(TAG, "getDingOrCai failure", e);
	}
	return dingOrCai;
}
 
Example #26
Source Project: android-open-project-demo   Author: android-cn   File: FinderLazyLoader.java    License: Apache License 2.0 5 votes vote down vote up
public T getFirstFromDb() throws DbException {
    T entity = null;
    Table table = finderColumn.getTable();
    if (table != null) {
        entity = table.db.findFirst(
                Selector.from(finderColumn.getTargetEntityType()).
                        where(finderColumn.getTargetColumnName(), "=", finderValue)
        );
    }
    return entity;
}
 
Example #27
Source Project: QiQuYing   Author: liuling07   File: DingCaiDAO.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 修改同步后的数据
 * @param praises
 */
public void upload(List<DingOrCai> praises) {
	for (DingOrCai praise : praises) {
		praise.setIsUpload(DingOrCai.UPLOAD);
	}
	DbUtils db = DbUtils.create(context);
	try {
		db.updateAll(praises, "is_upload");
		Log.d(TAG, "upload praise success");
	} catch (DbException e) {
		Log.d(TAG, "upload praise failure", e);
	}
}
 
Example #28
Source Project: QiQuYing   Author: liuling07   File: CollectDAO.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 检查是否收藏过
 * @param userId
 * @param jokeId
 * @return
 */
public Collect getCollect(int userId, int jokeId) {
	DbUtils db = DbUtils.create(context);
	Collect collect = null;
	try {
		collect = db.findFirst(Selector.from(Collect.class).where(WhereBuilder.b("user_id", "=", userId).and("joke_id", "=", jokeId)));
		Log.d(TAG, "getDingOrCai success");
	} catch (DbException e) {
		Log.e(TAG, "getDingOrCai failure", e);
	}
	return collect;
}
 
Example #29
Source Project: QiQuYing   Author: liuling07   File: CollectDAO.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 取消收藏
 * @param jokeId
 */
public void cancelCollect(int jokeId) {
	DbUtils db = DbUtils.create(context);
	try {
		db.delete(Collect.class, WhereBuilder.b("joke_id", "=", jokeId));
		Log.d(TAG, "cancelCollect success");
	} catch (DbException e) {
		Log.e(TAG, "cancelCollect failure", e);
	}
}
 
Example #30
Source Project: QiQuYing   Author: liuling07   File: CollectDAO.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取我的收藏
 * @param userId
 * @return
 */
public List<Collect> getCollects(int userId) {
	DbUtils db = DbUtils.create(context);
	List<Collect> dbModels = null;
	try {
		dbModels = db.findAll(Selector.from(Collect.class).
				where(WhereBuilder.b("user_id", "=", userId))
				.orderBy("create_at", true));
		Log.d(TAG, "getCollects success");
	} catch (DbException e) {
		Log.e(TAG, "getCollects failure", e);
	}
	return dbModels;
}