public static List<TodoItem> markOverdueItems() { List<TodoItem> items = new ArrayList<>(); List<TodoItem> overdueItems = new ArrayList<>(); final Dao<TodoItem, Integer> todoDao; try { todoDao = TodoApp.get().getDbHelper().getTodoDao(); QueryBuilder<TodoItem, Integer> todoQb = todoDao.queryBuilder(); PreparedQuery<TodoItem> preparedQuery = todoQb.where().eq(TodoEntry.COLUMN_STATE, TodoState.Undone).prepare(); items = todoDao.query(preparedQuery); Date currentDate = new Date(); for (TodoItem item : items) { if (item.getDue().before(currentDate)) { item.setState(TodoState.Overdue); createOrUpdateItem(item); overdueItems.add(item); } } } catch (SQLException e) { e.printStackTrace(); } return overdueItems; }
private void addSync() { QueryBuilder<Donor, Integer> queryBuilder = databaseHelper.getDonorListDao().queryBuilder(); // get the WHERE object to build our query Where<Donor, Integer> where = queryBuilder.where(); try { where.eq("status", new Integer(DhenupaApplication.STATUS_DONOR_ADDED)); // and where.or(); where.eq("status", new Integer(DhenupaApplication.STATUS_DONOR_UPDATED)); PreparedQuery<Donor> preparedQuery = queryBuilder.prepare(); List<Donor> donorList = databaseHelper.getDonorListDao().query(preparedQuery); for (Donor donor : donorList) { new DonorManager(this).addNewDonor(donor); // Sleep is added to maintain a different Timestamp between multiple entries try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } catch (SQLException e) { e.printStackTrace(); } }
@Override public long countByProject(int connection_id, long project_id) throws SQLException { QueryBuilder<RedmineRole, ?> builder = dao.queryBuilder(); builder.setCountOf(true).where().eq(RedmineStatus.CONNECTION, connection_id) // .and() // .eq(RedmineStatus.PROJECT_ID, project_id) ; return dao.countOf(builder.prepare()); }
public NoteLite getNoteByMember(int memberid) { try { QueryBuilder<NoteLite, Integer> queryBuilder = getNoteLiteDataDao().queryBuilder(); queryBuilder.where().eq(Constants.memberNotes_UserId, memberid); return queryBuilder.query().get(0); } catch (SQLException e) { e.printStackTrace(); return null; } }
public ExpansionInfo[] getSetsFromBlock(String blockName) { ExpansionInfo[] sets = new ExpansionInfo[0]; try { QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder(); qb.where().eq("blockName", new SelectArg(blockName)); List<ExpansionInfo> expansions = expansionDao.query(qb.prepare()); sets = expansions.toArray(new ExpansionInfo[0]); } catch (SQLException ex) { } return sets; }
public List<ExpansionInfo> getSetsWithBasicLandsByReleaseDate() { List<ExpansionInfo> sets = new LinkedList<ExpansionInfo>(); try { QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder(); qb.orderBy("releaseDate", false); qb.where().eq("basicLands", new SelectArg(true)); sets = expansionDao.query(qb.prepare()); } catch (SQLException ex) { } return sets; }
public long getCount() { long result = 0; try { Dao<Promotion, String> dao = this.getController(); QueryBuilder<Promotion, String> ordersQB = dao.queryBuilder(); ordersQB.where().eq("status", 1); result = ordersQB.countOf(); } catch (SQLException e) { e.printStackTrace(); } return result; }
public Interest get() { Interest result = new Interest(); try { Dao<Interest, String> dao = this.getController(); QueryBuilder<Interest, String> queryBuilder = dao.queryBuilder(); PreparedQuery<Interest> pq = queryBuilder.prepare(); result = dao.queryForFirst(pq); } catch (SQLException e) { e.printStackTrace(); } return result; }
/* 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; }
@Override public List<WidgetConfiguration> findPerTaskId(int taskId) { QueryBuilder<WidgetConfiguration, Integer> qb = dao.queryBuilder(); try { qb.where().eq("taskId", taskId); PreparedQuery<WidgetConfiguration> pq = qb.prepare(); return dao.query(pq); } catch (SQLException e) { Log.e(getContext(), LOG_TAG, "Could not start the query... Returning empty list.", e); return new ArrayList<WidgetConfiguration>(); } }
public ExpansionInfo[] getWithBoostersSortedByReleaseDate() { ExpansionInfo[] sets = new ExpansionInfo[0]; try { QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder(); qb.orderBy("releaseDate", false); qb.where().eq("boosters", new SelectArg(true)); List<ExpansionInfo> expansions = expansionDao.query(qb.prepare()); sets = expansions.toArray(new ExpansionInfo[0]); } catch (SQLException ex) { } return sets; }
public Promotion get(int id) { Promotion result = new Promotion(); try { Dao<Promotion, String> dao = this.getController(); QueryBuilder<Promotion, String> ordersQB = dao.queryBuilder(); ordersQB.where().eq("id", id); PreparedQuery<Promotion> pq = ordersQB.prepare(); result = dao.queryForFirst(pq); } catch (SQLException e) { e.printStackTrace(); } return result; }
public List<Promotion> getPromotionTicker() { List<Promotion> result = new ArrayList<>(); try { Dao<Promotion, String> dao = this.getController(); QueryBuilder<Promotion, String> builder = dao.queryBuilder(); builder.limit(10); builder.orderBy("createDate", false); result = dao.query(builder.prepare()); // returns list of ten items } catch (SQLException e) { e.printStackTrace(); } return result; }
/** * Fetches all profile elements from DB that have the same value of profile_id DB field with the * passed Profile object's id property * * @param Profile profile Profile for which elements should be fetched * @return Set<ProfileElement> set of elements for passed Profile */ public Set<ProfileElement> getProfileElements(Profile profile) { Set<ProfileElement> elements = null; if (profile != null) { try { QueryBuilder<ProfileElement, Integer> builder = this.getProfileElementDAO().queryBuilder(); builder.where().eq(ProfileElement.PROFILE_ID_FIELD, profile.getId()); elements = new HashSet<ProfileElement>(getProfileElementDAO().query(builder.prepare())); } catch (SQLException e) { Log.e(LOG_TAG, "Can't select profile elements. Database error"); } } return elements; }
public List<Data> getDataByDataset(final int datasetId) { try { QueryBuilder<Data, Integer> queryBuilder = getDataDao().queryBuilder(); Where<Data, Integer> where = queryBuilder.where(); where.eq("dataset_id", datasetId); PreparedQuery<Data> preparedQuery = queryBuilder.prepare(); return getDataDao().query(preparedQuery); } catch (SQLException e) { e.printStackTrace(); } return null; }
/** * Fetches all rules from DB that have the same value of condition_id DB field with the passed * Condition object's id property * * @param Condition condition Condition for which rules should be fetched * @return Set<Rule> set of rules for passed Condition */ public Set<Rule> getConditionRules(Condition condition) { Set<Rule> rules = null; if (condition != null) { try { QueryBuilder<TimeRule, Integer> builder = this.getTimeRuleDAO().queryBuilder(); builder.where().eq(TimeRule.CONDITION_ID_FIELD, condition.getId()); rules = new HashSet<Rule>(getTimeRuleDAO().query(builder.prepare())); } catch (SQLException e) { Log.e(LOG_TAG, "Can't select rules. Database error"); } } return rules; }
public ExpansionInfo getSetByCode(String setCode) { ExpansionInfo set = null; try { QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder(); qb.where().eq("code", new SelectArg(setCode)); List<ExpansionInfo> expansions = expansionDao.query(qb.prepare()); if (expansions.size() > 0) { set = expansions.get(0); } } catch (SQLException ex) { } return set; }
public List<SliderTipSeg> getSliderTipSegById(int idTipSeg) { try { Dao<SliderTipSeg, Integer> dao = getHelper().getSliderTipSegDao(); QueryBuilder<SliderTipSeg, Integer> builder = dao.queryBuilder(); builder.setWhere(builder.where().eq("id_tipseg", idTipSeg)); builder.orderBy("order", true); List<SliderTipSeg> items = dao.query(builder.prepare()); return items; } catch (SQLException e) { e.printStackTrace(); } return null; }
@NonNull public static List getAll(long inquirerId) { try { Dao<Question, Integer> qDao = DbHelper.getDbHelper().getQuestionDao(); final QueryBuilder qb = qDao.queryBuilder(); qb.where().eq(INQUIRER_ID, inquirerId); qb.orderBy(ORDER_NUMBER, true); return qDao.query(qb.prepare()); } catch (SQLException e) { e.printStackTrace(); } return new ArrayList<>(); }
public Data getData(final int datasetId, final int fieldId) { try { QueryBuilder<Data, Integer> queryBuilder = getDataDao().queryBuilder(); Where<Data, Integer> where = queryBuilder.where(); where.eq("dataset_id", datasetId); where.and(); where.eq("field_id", fieldId); PreparedQuery<Data> preparedQuery = queryBuilder.prepare(); return getDataDao().queryForFirst(preparedQuery); } catch (SQLException e) { e.printStackTrace(); } return null; }
public void endElement(String uri, String localName, String qName) throws SAXException { super.endElement(uri, localName, qName); if (qName.equals("available")) { available = Integer.parseInt(current.toString()); infoStation.setAvailable(available); } else if (qName.equals("free")) { free = Integer.parseInt(current.toString()); infoStation.setFree(free); } else if (qName.equals("total")) { total = Integer.parseInt(current.toString()); infoStation.setTotal(total); } else if (qName.equals("ticket")) { if (Integer.parseInt(current.toString()) == 1) ticket = true; else ticket = false; infoStation.setTicket(ticket); } else if (qName.equals("open")) { if (Integer.parseInt(current.toString()) == 1) open = true; else open = false; infoStation.setOpen(open); infoStation.setStationVelibId(station.getId()); } else if (qName.equals("updated")) { int updated = Integer.parseInt(current.toString()); infoStation.setUpdated(updated); infoStation.setStationVelibId(station.getId()); try { infoStationDao = DatabaseHelper.getInstance(context).getDao(InfoStation.class); QueryBuilder<InfoStation, ?> queryBuilder = infoStationDao.queryBuilder(); queryBuilder.where().eq(InfoStation.COLUMN_INFO_ID_STATION, station.getId()); PreparedQuery<InfoStation> preparedQuery = queryBuilder.prepare(); List<InfoStation> infoList = infoStationDao.query(preparedQuery); if (infoList.size() == 0) infoStationDao.create(infoStation); else if (infoStation.getUpdated() != updated) infoStationDao.update(infoStation); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /* * if(qName.equals("ticket")){ ticket = current.toString() != null; * } */ }
@Override @Test public void testLimitFormat() throws Exception { connectionSource.setDatabaseType(databaseType); BaseDaoImpl<StringId, String> dao = new BaseDaoImpl<StringId, String>(connectionSource, StringId.class) {}; dao.initialize(); QueryBuilder<StringId, String> qb = dao.queryBuilder(); long limit = 1232; qb.limit(limit); String query = qb.prepareStatementString(); assertTrue( query + " should start with stuff", query.startsWith("SELECT LIMIT 0 " + limit + " ")); }
public static ObservationInstance getFirstRecord(Context context) { ObservationInstance record = null; try { QueryBuilder<ObservationInstance, Integer> query = DatabaseHelper.getInstance(context).getSaveParamsDao().queryBuilder(); query.where().eq("status", StatusType.PENDING); record = DatabaseHelper.getInstance(context).getSaveParamsDao().queryForFirst(query.prepare()); } catch (SQLException e) { e.printStackTrace(); } return record; }
/* 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 List<Interest> getSelectedAll() { List<Interest> result = new ArrayList<>(); try { Dao<Interest, String> dao = this.getController(); // result = dao.queryForAll(); QueryBuilder<Interest, String> ordersQB = dao.queryBuilder(); ordersQB.where().eq("status", 1); // ordersQB.orderByRaw("name ASC"); PreparedQuery<Interest> pq = ordersQB.prepare(); result = dao.query(pq); } catch (SQLException e) { e.printStackTrace(); } return result; }
public static boolean isRecordAvailable(Context context, ObservationInstance sp) { List<ObservationInstance> record = null; try { QueryBuilder<ObservationInstance, Integer> query = DatabaseHelper.getInstance(context).getSaveParamsDao().queryBuilder(); if (sp.getId() == -1) query.where().eq("server_id", sp.getServer_id()).and().eq("id", sp.getId()); // Obv id else query.where().eq("id", sp.getId()); // Obv id record = DatabaseHelper.getInstance(context).getSaveParamsDao().query(query.prepare()); } catch (SQLException e) { e.printStackTrace(); } return record.size() > 0; }
public List<Promotion> getAll() { List<Promotion> result = new ArrayList<>(); try { Dao<Promotion, String> dao = this.getController(); // result = dao.queryForAll(); QueryBuilder<Promotion, String> ordersQB = dao.queryBuilder(); ordersQB.where().eq("status", 1); ordersQB.orderByRaw("createDate DESC"); PreparedQuery<Promotion> pq = ordersQB.prepare(); result = dao.query(pq); } catch (SQLException e) { e.printStackTrace(); } return result; }
public CloseableIterator<PlayerWarnData> findWarnings(long fromTime) throws SQLException { if (fromTime == 0) { return iterator(); } long checkTime = fromTime + DateUtils.getTimeDiff(); QueryBuilder<PlayerWarnData, Integer> query = queryBuilder(); Where<PlayerWarnData, Integer> where = query.where(); where.ge("created", checkTime); query.setWhere(where); return query.iterator(); }
/* 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; }
@Override public RedmineWiki fetchItemByProject(int connection_id, long project_id, long offset, long limit) throws SQLException { QueryBuilder<RedmineWiki, ?> builder = dao.queryBuilder(); builder .limit(limit) .offset(offset) .orderBy(RedmineWiki.TITLE, true) .where() .eq(RedmineWiki.CONNECTION, connection_id) .and() .eq(RedmineWiki.PROJECT_ID, project_id); RedmineWiki item = builder.queryForFirst(); if (item == null) item = new RedmineWiki(); return item; }