public void addClientUser(TwitterSession twitterSession, CreateCompletedListener addedListener) {
   ConnectionSource connectionSource = null;
   try {
     DataBaseHelper helper = new DataBaseHelper(Global.getInstance().getApplicationContext());
     connectionSource = helper.getConnectionSource();
     TableUtils.createTableIfNotExists(connectionSource, ClientUserTable.class);
     Dao<ClientUserTable, String> dao = helper.getDao(ClientUserTable.class);
     ClientUserTable table1 = dao.queryForId("" + twitterSession.getUserId());
     if (table1 == null) {
       ClientUserTable table = new ClientUserTable(twitterSession);
       dao.createOrUpdate(table);
       new ClientUser(
           clientUsers.size(),
           twitterSession,
           clientUser -> {
             clientUsers.add(clientUser);
             addedListener.completed(clientUser);
           },
           TwitterException::printStackTrace);
     } else {
       addedListener.completed(null);
     }
   } catch (SQLException e) {
     e.printStackTrace();
     throw new RuntimeException(e);
   } finally {
     if (connectionSource != null) {
       try {
         connectionSource.close();
       } catch (SQLException e) {
         e.printStackTrace();
       }
     }
   }
 }
Esempio n. 2
0
 public synchronized void createOrUpdate(City city) {
   try {
     mDao.createOrUpdate(city);
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Esempio n. 3
0
  protected int createAppointmentsForTimeSpan(
      RecurringAction recurringAction, Date startDate, Date endDate) {
    List<Event> eventList =
        appointmentFinder.findPossibleAppointments(recurringAction, startDate, endDate);
    int eventsCreated = 0;
    try {
      for (Event event : eventList) {
        // TODO use prefered calendar
        int calendarId = 1;

        Uri cUri =
            eventRepository.insert(
                EventFactory.createContentValueFromEvent(
                    recurringAction.getId(), event, calendarId));
        event.setUri(cUri);
        event.setRecurringAction(recurringAction);
        eventDao.createOrUpdate(event);
        eventsCreated++;
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }

    return eventsCreated;
  }
Esempio n. 4
0
 private <T, ID> void saveList(List<T> list, Class<T> clazz) throws SQLException {
   Dao<T, ID> dao = createDao(clazz);
   T data = null;
   for (int location = 0; location < list.size(); location++) {
     data = list.get(location);
     dao.createOrUpdate(data);
   }
 }
Esempio n. 5
0
  public static void createOrUpdateItem(TodoItem item) {
    try {
      final Dao<TodoItem, Integer> todoDao = TodoApp.get().getDbHelper().getTodoDao();
      todoDao.createOrUpdate(item);

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Esempio n. 6
0
  public boolean createOrUpdate(Object object) {
    boolean ok = false;
    if (object == null) return ok;
    try {
      Dao<DBFeed, Long> feedDAO =
          InfoWallApplication.getInstance().getDatabaseHelper().getFeedReaderDAO();
      Feed feed = (Feed) object;
      feedDAO.createOrUpdate(mapFeedToDBFeed(feed));

      ok = true;
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return ok;
  }