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();
    }
  }
Example #2
0
 @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());
 }
Example #3
0
 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;
 }
Example #4
0
 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;
 }
Example #5
0
 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;
 }
 @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>();
   }
 }
Example #7
0
 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;
 }
  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;
 }
Example #10
0
 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;
 }
Example #11
0
 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;
 }
Example #12
0
 @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<>();
 }
Example #13
0
 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;
 }
Example #14
0
 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;
 }
Example #15
0
 /**
  * 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 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 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;
  }
  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;
     * }
     */

  }
Example #19
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 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;
  }
Example #21
0
 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;
 }
  @Override
  public CalendarModel obtainTournaments() {
    CalendarModel model = new CalendarModel();
    List<TournamentModel> tournaments = new ArrayList<>();

    try {
      QueryBuilder<TournamentModel, String> builder = daoTournaments.queryBuilder();
      builder.orderBy("DATE", false); // true for ascending, false for descending
      builder.where().ge("DATE", new Date(System.currentTimeMillis()));
      tournaments = daoTournaments.query(builder.prepare());
    } catch (SQLException e) {
      Log.e(LOGTAG, "Error while obtaining messages from BBDD", e);
    }

    model.setTournaments(tournaments);
    return model;
  }
Example #23
0
  public ArrayList<Feed> getUnsyncedItems() throws SQLException {
    Dao<DBFeed, Long> feedReaderDAO =
        InfoWallApplication.getInstance().getDatabaseHelper().getFeedReaderDAO();
    // get our query builder from the DAO
    QueryBuilder<DBFeed, Long> queryBuilder = feedReaderDAO.queryBuilder();
    queryBuilder.where().eq(DBFeed.SYNCSTATUS_FIELD_NAME, false);
    PreparedQuery<DBFeed> preparedQuery = queryBuilder.prepare();
    List<DBFeed> dbFeeds = feedReaderDAO.query(preparedQuery);

    ArrayList<Feed> unsycedFeeds = new ArrayList<Feed>();
    if (dbFeeds != null || !dbFeeds.isEmpty()) {
      for (DBFeed dbFeed : dbFeeds) {
        unsycedFeeds.add(mapDBFeedToFeed(dbFeed));
      }
    }
    return unsycedFeeds;
  }
  /** Returns highest score row from DB. */
  public void getHighestScore() {
    try {
      Dao<UserScoreData, Integer> usersScoreData = getHelper().getUserScoreData();
      QueryBuilder<UserScoreData, Integer> builder = usersScoreData.queryBuilder();
      builder.orderBy("score", false);
      UserScoreData result = usersScoreData.queryForFirst(builder.prepare());

      mPresenterNotifier.PostNotification(IPresenterNotifier.NOTIFICATION_HIGHEST_SCORE, result);
    } catch (SQLException e) {
      e.printStackTrace();
    }

    if (databaseHelper != null) {
      OpenHelperManager.releaseHelper();
      databaseHelper = null;
    }
  }
Example #25
0
 public static ArrayList<Colleage> queryAll(String userId) {
   try {
     QueryBuilder<Colleage, String> queryBuilder = getDao().queryBuilder();
     Where<Colleage, String> where = queryBuilder.where();
     where.eq(Colleage.USER_ID, userId);
     queryBuilder.orderBy(Colleage.CREATETIME, false);
     List<Colleage> resultList = getDao().query(queryBuilder.prepare());
     if (TextUtil.isValidate(resultList)) {
       return (ArrayList<Colleage>) resultList;
     }
   } catch (SQLException e) {
     e.printStackTrace();
   } catch (DBNotInitializeException e) {
     e.printStackTrace();
   }
   return null;
 }
Example #26
0
  public List<Lecture> findBySpeaker(Speaker speaker) {
    List<Lecture> lectures = new ArrayList<Lecture>();

    QueryBuilder<LectureSpeaker, Integer> lectureSpeakerQB = getLectureSpeakerDao().queryBuilder();
    lectureSpeakerQB.selectColumns(LectureSpeaker.LECTURE_ID_FIELD_NAME);
    try {
      lectureSpeakerQB.where().eq(LectureSpeaker.SPEAKER_ID_FIELD_NAME, speaker);
      QueryBuilder<Lecture, Integer> lectureQB = getDao().queryBuilder();
      lectureQB.where().in(Lecture.ID_FIELD_NAME, lectureSpeakerQB);
      PreparedQuery<Lecture> lecturePrepare = lectureQB.prepare();

      return getDao().query(lecturePrepare);
    } catch (SQLException e) {
      e.printStackTrace();
      return lectures;
    }
  }
Example #27
0
 @Override
 public List<Alarm> getAll(int sensorRefId, Boolean enabled) {
   try {
     QueryBuilder<Alarm, Integer> queryBuilder = this.getDao().queryBuilder();
     if (enabled != null) {
       queryBuilder.where().eq(Alarm.ENABLED, enabled).and().eq(Alarm.SENSOR_REF_ID, sensorRefId);
     } else {
       queryBuilder.where().eq(Alarm.SENSOR_REF_ID, sensorRefId);
     }
     List<Alarm> alarms = this.getDao().query(queryBuilder.prepare());
     return alarms;
   } catch (SQLException ex) {
     _logger.error(
         "unable to get all alarms:[selsorRefId:{}, Enabled:{}]", sensorRefId, enabled, ex);
     return null;
   }
 }
  private PreparedQuery<ProjectBean> makeProjectForUserQuery() {

    QueryBuilder<UserProjectMapping, Integer> userPostQb = userProjectMappingDao.queryBuilder();

    userPostQb.selectColumns(UserProjectMapping.PROJECT_ID_FIELD_NAME);
    SelectArg userSelectArg = new SelectArg();
    QueryBuilder<ProjectBean, Integer> projectQb = null;
    try {
      userPostQb.where().eq(UserProjectMapping.USER_ID_FIELD_NAME, userSelectArg);
      projectQb = projectDao.queryBuilder();
      projectQb.where().eq("isDisabled", false).and().in(ProjectBean.ID_FIELD_NAME, userPostQb);
      return projectQb.prepare();
    } catch (SQLException e) {
      logger.error(
          "Error creating prepared query for fetching user mapped projects : " + e.getMessage());
    }
    return null;
  }
  /**
   * Add data into new row of DB. If data already exist it checks whether it needs to overwrite or
   * not.
   *
   * @param name user name
   * @param score user score
   * @param overwrite overwrite data or not if duplicate exist.
   */
  private void writeIntoDB(String name, int score, boolean overwrite) {
    UserScoreData userScore = new UserScoreData(name, score);
    try {
      final Dao<UserScoreData, Integer> userScoreData = getHelper().getUserScoreData();
      if (overwrite) {
        QueryBuilder<UserScoreData, Integer> query = userScoreData.queryBuilder();
        query.where().eq("name", name);
        UserScoreData sub = userScoreData.queryForFirst(query.prepare());
        userScoreData.delete(sub);
        userScoreData.create(userScore);
      } else {
        userScoreData.create(userScore);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }

    mPresenterNotifier.PostNotification(IPresenterNotifier.NOTIFICATION_SAVE_RECORD, userScore);
  }
Example #30
0
  private void showFromDb() {
    Dao<News, String> NewsDao = null;
    List<News> NewsItems = null;

    try {
      NewsDao = getDatabaseHelper().getNewsDao();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    try {
      QueryBuilder<News, String> queryBuilder = NewsDao.queryBuilder();
      queryBuilder.where().eq("mActive", 1);
      queryBuilder.orderBy("mId", false);
      NewsItems = NewsDao.query(queryBuilder.prepare());
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    mNewsItems = (ArrayList<News>) NewsItems;

    mLvNews = new ListView(NewsActivity.this);
    setContentView(mLvNews);
    NewsAdapter newsAdapter = new NewsAdapter(this, mNewsItems);
    mLvNews.setAdapter(newsAdapter);
    mLvNews.setTextFilterEnabled(true);

    mLvNews.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
            News selectedNews = mNewsItems.get(position);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(selectedNews.getURL()));
            startActivity(intent);
          }
        });
  }