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 File: DBManager.java From qingyang with Apache License 2.0 | 6 votes |
/** * 获取上传资源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 #2
Source File: SqlInfoBuilder.java From android-open-project-demo with Apache License 2.0 | 6 votes |
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 #3
Source File: GosScheduleListActivity.java From Gizwits-SmartBuld_Android with MIT License | 6 votes |
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 #4
Source File: GosScheduleData.java From Gizwits-SmartBuld_Android with MIT License | 6 votes |
/** * 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 #5
Source File: GosScheduleData.java From Gizwits-SmartBuld_Android with MIT License | 6 votes |
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 #6
Source File: DbUtils.java From android-open-project-demo with Apache License 2.0 | 6 votes |
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 #7
Source File: DbUtils.java From android-open-project-demo with Apache License 2.0 | 6 votes |
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 #8
Source File: DownloadManager.java From AndroidAppCodeFramework with Apache License 2.0 | 6 votes |
@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 #9
Source File: DbUtils.java From android-open-project-demo with Apache License 2.0 | 6 votes |
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 #10
Source File: DBManager.java From qingyang with Apache License 2.0 | 6 votes |
/** * 删除上传信息 * * @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 #11
Source File: DownloadManager.java From AndroidAppCodeFramework with Apache License 2.0 | 6 votes |
@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 #12
Source File: DownloadManager.java From AndroidAppCodeFramework with Apache License 2.0 | 6 votes |
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 #13
Source File: DbUtils.java From android-open-project-demo with Apache License 2.0 | 6 votes |
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 #14
Source File: MyEventLogicImpl.java From ALLGO with Apache License 2.0 | 6 votes |
@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 #15
Source File: DownloadManager.java From AndroidAppCodeFramework with Apache License 2.0 | 6 votes |
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 #16
Source File: DbUtils.java From android-open-project-demo with Apache License 2.0 | 5 votes |
public void replace(Object entity) throws DbException { try { beginTransaction(); createTableIfNotExist(entity.getClass()); execNonQuery(SqlInfoBuilder.buildReplaceSqlInfo(this, entity)); setTransactionSuccessful(); } finally { endTransaction(); } }
Example #17
Source File: XHttpHelper.java From AndroidAppCodeFramework with Apache License 2.0 | 5 votes |
/** * 下载文件 */ public void downloadHttpRequest(){ if(downloadInfo != null && downloadManager != null){ try { downloadManager.addNewDownload(downloadInfo.getDownloadUrl(), downloadInfo.getFileName(), downloadInfo.getFileSavePath(), downloadInfo.isAutoResume(), // 如果目标文件存在,接着未完成的部分继续下载。服务器不支持RANGE时将从新下载。 downloadInfo.isAutoRename(), // 如果从请求返回信息中获取到文件名,下载完成后自动重命名。 downloadCallback); } catch (DbException e) { e.printStackTrace(); } } }
Example #18
Source File: MyEventLogicImpl.java From ALLGO with Apache License 2.0 | 5 votes |
@Override public void initEvent() { new AsyncTask<Void, Void, ArrayList<EventVo>>() { @Override protected ArrayList<EventVo> doInBackground(Void... params) { SharedPreferences sharedPref = context.getSharedPreferences("userdata",Context.MODE_PRIVATE); int uid = sharedPref.getInt("uid", -1) ; ArrayList<EventVo> events =new ArrayList<EventVo>(); try{ DbUtils db = DbUtils.create(context,uid + ".db"); db.configAllowTransaction(true); db.configDebug(true); List<EventVo> event = db.findAll(Selector.from(MyEventVo.class)); if(event != null){ Log.i("DB", "initMyEvent.size()==>" + event.size()); for(int i=0 ; i<event.size() ; i++) { events.add(ChangEventVo.event2Event(event.get(i))) ; //Log.i("DB", "=initMyEvent=>" + event.get(i).toString()); } } }catch(DbException e){ Log.e("DB", "error :" + e.getMessage() + "\n"); } return events; } @Override protected void onPostExecute(ArrayList<EventVo> result) { super.onPostExecute(result); ArrayListUtil.sortEventVo(result); refresh.refresh(result, 1); } }.execute(); }
Example #19
Source File: DbUtils.java From android-open-project-demo with Apache License 2.0 | 5 votes |
public void saveOrUpdate(Object entity) throws DbException { try { beginTransaction(); createTableIfNotExist(entity.getClass()); saveOrUpdateWithoutTransaction(entity); setTransactionSuccessful(); } finally { endTransaction(); } }
Example #20
Source File: DbUtils.java From android-open-project-demo with Apache License 2.0 | 5 votes |
public void saveOrUpdateAll(List<?> entities) throws DbException { if (entities == null || entities.size() == 0) return; try { beginTransaction(); createTableIfNotExist(entities.get(0).getClass()); for (Object entity : entities) { saveOrUpdateWithoutTransaction(entity); } setTransactionSuccessful(); } finally { endTransaction(); } }
Example #21
Source File: CommonEventLogicImpl.java From ALLGO with Apache License 2.0 | 5 votes |
/** * 初始化所有活动列表,从数据库得到数据 * @param context */ @Override public void initEvent() { new AsyncTask<Void, Void, ArrayList<EventVo>>() { @Override protected ArrayList<EventVo> doInBackground(Void... params) { SharedPreferences sharedPref = context.getSharedPreferences("userdata",Context.MODE_PRIVATE); int uid = sharedPref.getInt("uid", -1) ; ArrayList<EventVo> events =new ArrayList<EventVo>(); try{ DbUtils db = DbUtils.create(context,uid + ".db"); db.configAllowTransaction(true); db.configDebug(true); List<EventVo> event = db.findAll(Selector.from(CommonEventVo.class)); if(event != null){ Log.i("DB", "initcommonEvent.size()==>" + event.size()); for(int i=0 ; i<event.size() ; i++) { events.add(ChangEventVo.event2Event(event.get(i))) ; } } }catch(DbException e){ Log.e("DB", "error :" + e.getMessage() + "\n"); } return events; } @Override protected void onPostExecute(ArrayList<EventVo> result) { super.onPostExecute(result); ArrayListUtil.sortEventVo(result); refresh.refresh(result, 1); } }.execute(); }
Example #22
Source File: DbUtils.java From android-open-project-demo with Apache License 2.0 | 5 votes |
public long count(Selector selector) throws DbException { Class<?> entityType = selector.getEntityType(); if (!tableIsExist(entityType)) return 0; Table table = Table.get(this, entityType); DbModelSelector dmSelector = selector.select("count(" + table.id.getColumnName() + ") as count"); return findDbModelFirst(dmSelector).getLong("count"); }
Example #23
Source File: DownloadManager.java From AndroidAppCodeFramework with Apache License 2.0 | 5 votes |
@Override public void onSuccess(ResponseInfo<File> responseInfo) { HttpHandler<File> handler = downloadInfo.getHandler(); if (handler != null) { downloadInfo.setState(handler.getState()); } try { db.saveOrUpdate(downloadInfo); } catch (DbException e) { LogUtils.e(e.getMessage(), e); } if (baseCallBack != null) { baseCallBack.onSuccess(responseInfo); } }
Example #24
Source File: DownloadManager.java From AndroidAppCodeFramework with Apache License 2.0 | 5 votes |
@Override public void onStopped() { HttpHandler<File> handler = downloadInfo.getHandler(); if (handler != null) { downloadInfo.setState(handler.getState()); } try { db.saveOrUpdate(downloadInfo); } catch (DbException e) { LogUtils.e(e.getMessage(), e); } if (baseCallBack != null) { baseCallBack.onStopped(); } }
Example #25
Source File: DownloadManager.java From AndroidAppCodeFramework with Apache License 2.0 | 5 votes |
@Override public void onStart() { HttpHandler<File> handler = downloadInfo.getHandler(); if (handler != null) { downloadInfo.setState(handler.getState()); } try { db.saveOrUpdate(downloadInfo); } catch (DbException e) { LogUtils.e(e.getMessage(), e); } if (baseCallBack != null) { baseCallBack.onStart(); } }
Example #26
Source File: DownloadManager.java From AndroidAppCodeFramework with Apache License 2.0 | 5 votes |
public void backupDownloadInfoList() throws DbException { for (DownloadInfo downloadInfo : downloadInfoList) { HttpHandler<File> handler = downloadInfo.getHandler(); if (handler != null) { downloadInfo.setState(handler.getState()); } } db.saveOrUpdateAll(downloadInfoList); }
Example #27
Source File: DownloadManager.java From AndroidAppCodeFramework with Apache License 2.0 | 5 votes |
public void stopAllDownload() throws DbException { for (DownloadInfo downloadInfo : downloadInfoList) { HttpHandler<File> handler = downloadInfo.getHandler(); if (handler != null && !handler.isStopped()) { handler.stop(); } else { downloadInfo.setState(HttpHandler.State.STOPPED); } } db.saveOrUpdateAll(downloadInfoList); }
Example #28
Source File: DownloadManager.java From AndroidAppCodeFramework with Apache License 2.0 | 5 votes |
public void stopDownload(DownloadInfo downloadInfo) throws DbException { HttpHandler<File> handler = downloadInfo.getHandler(); if (handler != null && !handler.isStopped()) { handler.stop(); } else { downloadInfo.setState(HttpHandler.State.STOPPED); } db.saveOrUpdate(downloadInfo); }
Example #29
Source File: DownloadManager.java From AndroidAppCodeFramework with Apache License 2.0 | 5 votes |
public void removeDownload(DownloadInfo downloadInfo) throws DbException { HttpHandler<File> handler = downloadInfo.getHandler(); if (handler != null && !handler.isStopped()) { handler.stop(); } downloadInfoList.remove(downloadInfo); db.delete(downloadInfo); }
Example #30
Source File: DbUtils.java From android-open-project-demo with Apache License 2.0 | 5 votes |
public void delete(Class<?> entityType, WhereBuilder whereBuilder) throws DbException { if (!tableIsExist(entityType)) return; try { beginTransaction(); execNonQuery(SqlInfoBuilder.buildDeleteSqlInfo(this, entityType, whereBuilder)); setTransactionSuccessful(); } finally { endTransaction(); } }