/* insert */ public static int insert(DatabaseHelper databaseHelper, system_messageVo system_messageVo) { RuntimeExceptionDao<system_messageVo, Integer> system_messageDao = databaseHelper.getSystem_messageDao(); if (exist(databaseHelper, system_messageVo)) { return 0; } return system_messageDao.create(system_messageVo); }
private void readCurrentUser() { dbHelper = OpenHelperManager.getHelper(getApplicationContext(), WTDbHelper.class); RuntimeExceptionDao<User, String> userDao = dbHelper.getUserDao(); SharedPreferences sp = getApplicationContext().getSharedPreferences("SettingInfo", MODE_PRIVATE); mUser = userDao.queryForId(sp.getString("CurrentSchoolNumber", "")); }
/* select by id */ public static system_messageVo select(DatabaseHelper databaseHelper, int id) { RuntimeExceptionDao<system_messageVo, Integer> system_messageDao = databaseHelper.getSystem_messageDao(); try { return system_messageDao.queryForId(id); } catch (Exception e) { e.printStackTrace(); } return null; }
/* selectRaw */ public static List<system_messageVo> selectRaw2(DatabaseHelper databaseHelper) { RuntimeExceptionDao<system_messageVo, Integer> system_messageDao = databaseHelper.getSystem_messageDao(); QueryBuilder<system_messageVo, Integer> queryBuilder = system_messageDao.queryBuilder(); try { return queryBuilder.query(); } catch (SQLException e) { e.printStackTrace(); } return null; }
public void updateUserDB(String jsonStr) throws Exception { JSONObject data = new JSONObject(jsonStr); JSONObject userStr = data.getJSONObject("User"); Gson gson = new Gson(); User user = gson.fromJson(userStr.toString(), User.class); // 写入user到数据库 dbHelper = OpenHelperManager.getHelper(getApplicationContext(), WTDbHelper.class); RuntimeExceptionDao<User, String> userDao = dbHelper.getUserDao(); userDao.update(user); }
/* exist */ public static boolean exist(DatabaseHelper databaseHelper, system_messageVo system_messageVo) { RuntimeExceptionDao<system_messageVo, Integer> system_messageDao = databaseHelper.getSystem_messageDao(); QueryBuilder<system_messageVo, Integer> queryBuilder = system_messageDao.queryBuilder(); try { queryBuilder.where().eq(system_messageVo.FIELD_Id, String.valueOf(system_messageVo.getId())); // .and() // .eq(AccountVo.FIELD_Device, aAccountVo.getDevice()); return queryBuilder.query().size() > 0 ? true : false; } catch (SQLException e) { e.printStackTrace(); } return false; }
public static int delete( DatabaseHelper databaseHelper, String columnvalue, String originalvalue) { RuntimeExceptionDao<system_messageVo, Integer> system_messageDao = databaseHelper.getSystem_messageDao(); DeleteBuilder<system_messageVo, Integer> deleteBuilder = system_messageDao.deleteBuilder(); try { // 判斷式 哪一欄 = 值 deleteBuilder.where().eq(columnvalue, originalvalue); return deleteBuilder.delete(); } catch (Exception e) { e.printStackTrace(); } return 0; }
/* selectRaw */ public static system_messageVo getSystem_messageVo(DatabaseHelper databaseHelper) { RuntimeExceptionDao<system_messageVo, Integer> system_messageDao = databaseHelper.getSystem_messageDao(); QueryBuilder<system_messageVo, Integer> queryBuilder = system_messageDao.queryBuilder(); try { List<system_messageVo> data = queryBuilder.where().raw("1=1").query(); if (data.size() > 0) { return data.get(0); } return null; } catch (Exception e) { e.printStackTrace(); } return null; }
public XYSeries getYearHistoryData() { XYSeries series = new XYSeries(""); ArrayList<XYSeries> list = new ArrayList<XYSeries>(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); Date date = cal.getTime(); String queryString = "select sum(usetime),substr(datetime,6,2) from rundata where datetime(datetime) > '" + formater.format(date) + "' group by substr(datetime,6,2)"; Log.d(Tag, "getYearHistoryData's query string" + queryString); GenericRawResults<String[]> rawResult = rundataDao.queryRaw(queryString); try { List<String[]> result = rawResult.getResults(); for (int n = 0; n < result.size(); n++) { double y = Double.parseDouble(result.get(n)[0]); double x = Double.parseDouble(result.get(n)[1]); Log.d(Tag, "x:" + x + " y:" + y); series.add(Number2(x), Number2(y / 3600)); list.add(series); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return series; }
public XYSeries getDayHistoryData() { XYSeries series = new XYSeries(""); Date date = new Date(); date.setHours(0); date.setMinutes(0); date.setSeconds(0); String queryString = "select sum(usetime),substr(datetime,12,2) from rundata where datetime(datetime) > '" + formater.format(date) + "' group by substr(datetime,12,2)"; Log.d(Tag, "getDayHistoryData's query string:" + queryString); GenericRawResults<String[]> rawResult = rundataDao.queryRaw(queryString); try { List<String[]> result = rawResult.getResults(); for (int n = 0; n < result.size(); n++) { double y = Double.parseDouble(result.get(n)[0]); double x = Double.parseDouble(result.get(n)[1]); Log.d(Tag, "x:" + x + " y:" + y); series.add(Number2(x), Number2(y / 3600)); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return series; }
public boolean verificaLogin() { boolean cadastrado = false; RuntimeExceptionDao<Usuario, Integer> usrDao = getHelper().getUsuarioRuntimeExceptionDao(); usrDao.create(new Usuario("user1", "1234")); List<Usuario> usrs = usrDao.queryForAll(); // Log.d("demo", usrs.toString()); for (Usuario u : usrs) { // Log.d("demo", u.login); // Log.d("demo", etLogin.getText().toString()); if (u.login.equals(etLogin.getText().toString()) && u.senha.equals(etSenha.getText().toString())) { cadastrado = true; } } return cadastrado; }
private void smsTunnel() { Cursor cursor = null; String sms_id = null; // 数据处理标记,存入SharedPreferences try { RuntimeExceptionDao<SmsStructure, Long> dao = QualityApplication.getApplication(this).getDatabaseHelper().getSmsStructureDAO(); cursor = getContentResolver() .query( SmsContentObserver.SMS_URI, null, "_id > ?", new String[] {sharedPreferences.getString(SmsContentObserver.SMS_FLAG_ID, "0")}, "_ID ASC"); while (cursor.moveToNext()) { sms_id = cursor.getString(cursor.getColumnIndex("_id")); int type = cursor.getInt(cursor.getColumnIndex("type")); String number = cursor.getString(cursor.getColumnIndex("address")); String name = Contacts.lookupPersonName(getApplicationContext(), number, null); DateTime ddate = new DateTime(cursor.getLong(cursor.getColumnIndex("date"))); SmsStructure structure = new SmsStructure( MobileNetType.getPhoneType(getApplicationContext()), MobileNetType.getMobileTypeValue(getApplicationContext()), name, number, type, ddate); dao.create(structure); } } catch (Exception e) { Log.w(TAG, "未能处理当前短信记录数据", e); } finally { try { if (null != cursor) cursor.close(); } catch (Exception e) { } if (!Strings.isEmpty(sms_id)) sharedPreferences.edit().putString(SmsContentObserver.SMS_FLAG_ID, sms_id).commit(); } sendMessage(PhoneStateService.OBSERVER_INSTALL, PhoneStateService.OBSERVER_INSTALL_SMS); }
/* update */ public static int update( DatabaseHelper databaseHelper, String columnvalue, String originalvalue, String column, String value) { RuntimeExceptionDao<system_messageVo, Integer> system_messageDao = databaseHelper.getSystem_messageDao(); UpdateBuilder<system_messageVo, Integer> updateBuilder = system_messageDao.updateBuilder(); try { // 判斷式 哪一欄 = 值 updateBuilder.where().eq(columnvalue, originalvalue); // update the value of your field(s) updateBuilder.updateColumnValue(column, value); return updateBuilder.update(); } catch (Exception e) { e.printStackTrace(); } return 0; }
@Override public View getView(int position, View convertView) { ArticleView view = (ArticleView) convertView; if (view == null) { view = ArticleView_.build(context); } Article article = getItem(position); Source source = sourceDao.queryForId(article.getSourceId()); List<Tag> tags = null; if (source != null) { tags = tagDao.queryForNames(source.getTags()); } view.bind(article, tags); return view; }
public double getWeight() { RuntimeExceptionDao<WeightDiaryEntry, Integer> diaryDao = DataHelper.getDatabaseHelper().getDiaryDao(WeightDiaryEntry.class); List<WeightDiaryEntry> entries; try { entries = diaryDao .queryBuilder() .orderBy(DiaryEntry.DATESTAMP_FIELD_NAME, true) .where() .eq(DiaryEntry.DELETED_FIELD_NAME, false) .query(); if (entries != null && entries.size() > 0) { WeightDiaryEntry weightEntry = (WeightDiaryEntry) entries.get(entries.size() - 1); this.weight = weightEntry.getWeight(); } } catch (SQLException e) { e.printStackTrace(); } return this.weight; }
public static String registerOrUpdate(ReviewModel reviewModel) { try { Dao.CreateOrUpdateStatus status = runtimeExceptionDao.createOrUpdate(reviewModel); if (status.isCreated()) { return "isCreated"; } if (status.isUpdated()) { return "isUpdated"; } return ""; } catch (SQLiteException ex) { ex.printStackTrace(); return ""; } }
/* * 查询跑步次数 */ public int queryRunningNum() { int total_number = 0; GenericRawResults<String[]> rawResults1 = rundataDao.queryRaw("select count(id) from rundata"); List<String[]> results1 = null; try { results1 = rawResults1.getResults(); for (int k = 0; k < results1.size(); k++) { for (int n = 0; n < results1.get(k).length; n++) { total_number = Integer.parseInt(results1.get(k)[n]); } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return total_number; }
public static ListResponsReview getAll(int moviesId) { List<ReviewModel> reviewModelList = new ArrayList<>(); ListResponsReview listResponsReview = new ListResponsReview(); try { List<ReviewModel> list = runtimeExceptionDao.queryForAll(); for (ReviewModel reviewModel : list) { if (reviewModel.getMovieId().equals(String.valueOf(moviesId))) { reviewModelList.add(reviewModel); } } listResponsReview.setResults(reviewModelList); } catch (Exception e) { e.printStackTrace(); } return listResponsReview; }
/* * 查询跑步总用时,单位小时 */ public float querySumRunningTime() { float time = 0f; GenericRawResults<String[]> rawResults2 = rundataDao.queryRaw("select sum(usetime) from rundata"); List<String[]> results2 = null; try { results2 = rawResults2.getResults(); results2 = rawResults2.getResults(); for (int k = 0; k < results2.size(); k++) { for (int n = 0; n < results2.get(k).length; n++) { int total_seconds = Integer.parseInt(results2.get(k)[n]); time = (float) total_seconds / 3600.0f; } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return time; }
/* * 查询跑步总里程 单位公里 */ public float querySumRunningDistance() { float distance = 0f; GenericRawResults<String[]> rawResults3 = rundataDao.queryRaw("select sum(distance) from rundata"); List<String[]> results3 = null; try { results3 = rawResults3.getResults(); for (int k = 0; k < results3.size(); k++) { for (int n = 0; n < results3.get(k).length; n++) { int total_meter = Integer.parseInt(results3.get(k)[n]); distance = (float) total_meter / 1000.0f; } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return distance; }
/* * 更新数据 */ public void updateRundata(RunData rundata) { rundataDao.update(rundata); }
public static ReviewModel getbyId(int id) { return runtimeExceptionDao.queryForId(id); }
public void deleteReview(int movieId) { runtimeExceptionDao.deleteById(movieId); }
public static Person getById(ZulipApp app, int id) { RuntimeExceptionDao<Person, Object> dao = app.getDao(Person.class); return dao.queryForId(id); }
public static List<Person> getAllPeople(ZulipApp app) throws SQLException { RuntimeExceptionDao<Person, Object> dao = app.getDao(Person.class); return dao.queryBuilder().where().eq(Person.ISBOT_FIELD, false).query(); }
/* * 存储数据 */ public void addRundata(RunData rundata) { rundataDao.create(rundata); }
@Override public List<Role> getAll() { return db.queryForAll(); }
private void callsTunnel() { Cursor cursor = null; String calls_id = null; // 数据处理标记,存入SharedPreferences try { RuntimeExceptionDao<CallsStructure, Long> dao = QualityApplication.getApplication(this).getDatabaseHelper().getCallsStructureDAO(); cursor = getContentResolver() .query( CallsContentObserver.CALLS_URI, null, "_id > ?", new String[] { sharedPreferences.getString(CallsContentObserver.CALLS_FLAG_ID, "0") }, CallLog.Calls._ID + " ASC"); while (cursor.moveToNext()) { calls_id = cursor.getString(cursor.getColumnIndex(CallLog.Calls._ID)); int type = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE)); String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER)); String name = Contacts.lookupPersonName( getApplicationContext(), number, cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME))); long duration = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DURATION)); DateTime ddate = new DateTime(cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE))); CallsStructure structure = new CallsStructure( MobileNetType.getPhoneType(getApplicationContext()), MobileNetType.getMobileTypeValue(getApplicationContext()), name, number, type, CallDropCause.UNKNOW.toString(), duration, ddate); dao.create(structure); } } catch (Exception e) { Log.w(TAG, "未能处理当前通话记录数据", e); } finally { try { if (null != cursor) cursor.close(); } catch (Exception e) { } if (!Strings.isEmpty(calls_id)) sharedPreferences.edit().putString(CallsContentObserver.CALLS_FLAG_ID, calls_id).commit(); } try { RuntimeExceptionDao<CallCauseCache, Long> dao = QualityApplication.getApplication(this).getDatabaseHelper().getCallCauseCacheDAO(); RuntimeExceptionDao<CallsStructure, Long> callDao = QualityApplication.getApplication(this).getDatabaseHelper().getCallsStructureDAO(); List<CallCauseCache> caches = dao.queryForAll(); // 遍历 if (null != caches && caches.size() > 0) { for (CallCauseCache cache : caches) { CallsStructure struct = callDao .queryBuilder() .orderBy("ddate", false) .where() .eq("ddate", cache.getDdate()) .queryForFirst(); if (null != struct) { // 更新断开原因 struct.setCause(cache.getCause()); callDao.update(struct); // 删除 dao.deleteById(cache.getId()); } } } } catch (Exception e) { Log.d(TAG, "更新通话断开原因时出现异常"); } sendMessage(PhoneStateService.OBSERVER_INSTALL, PhoneStateService.OBSERVER_INSTALL_CALLS); }