예제 #1
0
  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;
  }
예제 #2
0
 @Test(expected = SQLException.class)
 public void testQueryRawColumnsNotQuery() throws Exception {
   Dao<Foo, String> dao = createDao(Foo.class, true);
   QueryBuilder<Foo, String> qb = dao.queryBuilder();
   qb.selectRaw("COUNT(*)");
   // we can't get Foo objects with the COUNT(*)
   dao.query(qb.prepare());
 }
예제 #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;
 }
예제 #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;
 }
예제 #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;
 }
예제 #6
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;
 }
예제 #7
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;
 }
예제 #8
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<>();
 }
예제 #9
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;
 }
예제 #10
0
  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;
     * }
     */

  }
예제 #11
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;
 }
예제 #12
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;
 }
예제 #13
0
  public <E> List<E> retireveProjectsForUser(String UserID) {
    List<ProjectBean> projectList = new ArrayList<ProjectBean>();
    try {

      List<UserProjectMapping> users = userProjectMappingDao.queryForAll();
      userProjectsQuery.setArgumentHolderValue(
          0, UserDAOManager.getInstance().userDetailDao.queryForId(Integer.parseInt(UserID)));
      projectList = projectDao.query(userProjectsQuery);

    } catch (NumberFormatException e) {
      logger.error("Error parsing user ID : " + e.getMessage());
    } catch (SQLException e) {
      logger.error("Error fetching projects for user " + UserID + " : " + e.getMessage());
    }
    return (List<E>) projectList;
  }
  @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;
  }
예제 #15
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;
  }
예제 #16
0
  public static List<Account> getFromDatabase(Context context) {
    final DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
    List<Account> items = null;

    try {
      final Dao<Account, String> dao = helper.getAccountDao();
      items = dao.query(dao.queryBuilder().prepare());
    } catch (SQLException e) {
      if (Flags.DEBUG) {
        e.printStackTrace();
      }
    } finally {
      OpenHelperManager.releaseHelper();
    }

    return items;
  }
예제 #17
0
  public static List<TodoItem> getSortedItems() {
    List<TodoItem> items = new ArrayList<>();

    final Dao<TodoItem, Integer> todoDao;
    try {
      todoDao = TodoApp.get().getDbHelper().getTodoDao();

      QueryBuilder<TodoItem, Integer> todoQb = todoDao.queryBuilder();
      PreparedQuery<TodoItem> preparedQuery =
          todoQb.orderBy(TodoEntry.COLUMN_URGENT, false).prepare();

      items = todoDao.query(preparedQuery);

    } catch (SQLException e) {
      e.printStackTrace();
    }
    return items;
  }
예제 #18
0
  @Test
  public void testOffsetWorks() throws Exception {
    Dao<Foo, Integer> dao = createDao(Foo.class, true);
    Foo foo1 = new Foo();
    assertEquals(1, dao.create(foo1));
    Foo foo2 = new Foo();
    assertEquals(1, dao.create(foo2));

    assertEquals(2, dao.queryForAll().size());

    QueryBuilder<Foo, Integer> qb = dao.queryBuilder();
    long offset = 1;
    long limit = 2;
    qb.offset(offset);
    qb.limit(limit);
    List<Foo> results = dao.query(qb.prepare());

    assertEquals(1, results.size());
  }
예제 #19
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);
          }
        });
  }
  /**
   * Returns all the data from Table in sorted order by score.
   *
   * @param isWriting isQuery purpose to write/update data
   * @return all data list in table
   */
  public List<UserScoreData> getAllUsersData(boolean isWriting) {
    List<UserScoreData> resultList = null;
    try {
      Dao<UserScoreData, Integer> usersScoreData = getHelper().getUserScoreData();
      QueryBuilder<UserScoreData, Integer> builder = usersScoreData.queryBuilder();
      builder.orderBy("score", false);
      resultList = usersScoreData.query(builder.prepare());
      if (!isWriting && (resultList.size() > 0)) {
        AllUsersRecord usersList = new AllUsersRecord();
        usersList.setUserScoreDataList(resultList);
        mPresenterNotifier.PostNotification(IPresenterNotifier.NOTIFICATION_ALL_RECORDS, usersList);
      }

    } catch (SQLException e) {
      e.printStackTrace();
    }

    if (databaseHelper != null) {
      OpenHelperManager.releaseHelper();
      databaseHelper = null;
    }
    return resultList;
  }
예제 #21
0
  private void GrabComparisionBuoys() {

    // If we've grabbed compare buoys already in the specified timespan, don't grab them again.
    // Use shared prefs to store this data
    long lastComparison =
        PreferenceManager.getDefaultSharedPreferences(this)
            .getLong(SHARED_PREF_LAST_BUOY_COMPARISION, -1);

    Log.d(LOG_TAG, "Grabbed last comparison time - " + lastComparison);

    if (System.currentTimeMillis() - lastComparison < NUM_MSECONDS_COMPARISON_BUOYS_GOOD_FOR) {
      // TODO: Reset all loading spinners in myspots frag.
      Log.d(LOG_TAG, "Last comparison was less than threshold. Not grabbing comparison buoys.");

      return;
    }

    try {

      // List<Buoy> closeBuoys = BuoySearch.SearchForBuoys(32.5f, 117.0f, 20);
      Dao<BuoyDataPointBase, Integer> buoyDataPointBaseDao = getHelper().getBuoyDataPointBaseDao();
      Dao<TidalDataPoint, Integer> tidalDataPointDao = getHelper().getTidalDataPointDao();

      List<BuoyDataPointBase> buoys =
          buoyDataPointBaseDao.query(
              buoyDataPointBaseDao
                  .queryBuilder()
                  .groupBy(BuoyDataPointBase.BUOY_DATA_POINT_BASE_BUOYID)
                  .prepare());

      Log.d(LOG_TAG, "Starting regular buoy comparison service.");
      for (BuoyDataPointBase b : buoys) {
        BuoyUpdateRequest request = new BuoyUpdateRequest(b.getbuoyID(), BuoyUpdateType.RSS);

        Intent intent = new Intent(this, BuoyUpdateService.class);
        intent.putExtra(BuoyUpdateService.BUOYUPDATESERVICE_PARCELABLE, request);
        this.startService(intent);
      }

      List<TidalDataPoint> tideBuoys =
          tidalDataPointDao.query(
              tidalDataPointDao
                  .queryBuilder()
                  .groupBy(BuoyDataPointBase.BUOY_DATA_POINT_BASE_BUOYID)
                  .prepare());

      Log.d(LOG_TAG, "Starting tidal buoy comparison service.");
      for (TidalDataPoint b : tideBuoys) {
        BuoyUpdateRequest request = new BuoyUpdateRequest(b.getbuoyID(), BuoyUpdateType.Tide);

        Intent intent = new Intent(this, BuoyUpdateService.class);
        intent.putExtra(BuoyUpdateService.BUOYUPDATESERVICE_PARCELABLE, request);
        this.startService(intent);
      }
    } catch (Exception ex) {
      Log.e(LOG_TAG, "Error occured while grabbing comparison buoys.", ex);
    }

    Log.d(LOG_TAG, "Saving last comparison time.");
    // Set shared pref so we know the last time we got the buoys
    PreferenceManager.getDefaultSharedPreferences(this)
        .edit()
        .putLong(SHARED_PREF_LAST_BUOY_COMPARISION, System.currentTimeMillis())
        .commit();
  }
예제 #22
0
  private List<RecurringAction> getActiveActions() throws SQLException {
    QueryBuilder<RecurringAction, Integer> queryBuilder = recurringActionDao.queryBuilder();

    queryBuilder.where().le("firstDay", getStartDate());
    return recurringActionDao.query(queryBuilder.prepare());
  }