public boolean onContextItemSelected(MenuItem item) {

    AdapterView.AdapterContextMenuInfo info =
        (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int menuItemIndex = item.getItemId();

    Interes interes = interesesAdapter.getItem(info.position);

    switch (menuItemIndex) {
      case R.id.ItemMenuBorrar:
        OrmLiteSqliteOpenHelper helper = null;
        try {
          helper = OpenHelperManager.getHelper(this, DatabaseHelper.class);
          Dao<Interes, Integer> interesesDao = helper.getDao(Interes.class);
          interesesDao.delete(interes);
          interesesAdapter.remove(interes);
        } catch (Exception e) {
          Log.e(TAG, "Error al listar los intereses", e);
          GuiUtils.mostrarToast(this, R.string.operacion_error, null);
        } finally {
          try {
            OpenHelperManager.releaseHelper();
          } catch (Exception e2) {
          }
        }

        return true;
      case R.id.ItemMenuEditar:
        mostrarDatosInteres(interes);
        return true;
      default:
        return super.onContextItemSelected(item);
    }
  }
Esempio n. 2
0
 public void delete(CarInfo carInfo) {
   try {
     carInfoDao.delete(carInfo);
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Esempio n. 3
0
 public void delete(Notebook notebook) {
   try {
     notebookDaoOpe.delete(notebook);
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Esempio n. 4
0
 public void deleteall() {
   try {
     locationsesDao.delete(queryForAll());
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
  @Test
  public void
      addManySideEntities_ClearCacheQueryForAllAndRemoveSomeEntities_TestIfEntitiesGetCorrectlyRemove()
          throws Exception {
    RelationEntities.LazyOneSide oneSide1 = new RelationEntities.LazyOneSide("One 1");
    oneSideDao.create(oneSide1);

    RelationEntities.LazyOneSide oneSide2 = new RelationEntities.LazyOneSide("One 2");
    oneSideDao.create(oneSide2);

    RelationEntities.LazyManySide manySide1 = new RelationEntities.LazyManySide("Many 1");
    RelationEntities.LazyManySide manySide2 = new RelationEntities.LazyManySide("Many 2");
    RelationEntities.LazyManySide manySide3 = new RelationEntities.LazyManySide("Many 3");
    RelationEntities.LazyManySide manySide4 = new RelationEntities.LazyManySide("Many 4");
    RelationEntities.LazyManySide manySide5 = new RelationEntities.LazyManySide("Many 5");
    RelationEntities.LazyManySide manySide6 = new RelationEntities.LazyManySide("Many 6");

    oneSide1.getManySides().add(manySide1);
    oneSide1.getManySides().add(manySide2);
    oneSide1.getManySides().add(manySide3);

    oneSide2.getManySides().add(manySide4);
    oneSide2.getManySides().add(manySide5);
    oneSide2.getManySides().add(manySide6);

    oneSideDao.clearObjectCache();
    manySideDao.clearObjectCache();

    List<RelationEntities.LazyOneSide> persistedEntities = oneSideDao.queryForAll();
    RelationEntities.LazyOneSide persistedOneSide1 = persistedEntities.get(0);
    RelationEntities.LazyOneSide persistedOneSide2 = persistedEntities.get(1);

    RelationEntities.LazyManySide persistedManySide2 = persistedOneSide1.getManySides().get(1);
    RelationEntities.LazyManySide persistedManySide3 = persistedOneSide1.getManySides().get(2);
    manySideDao.delete(persistedManySide2);
    manySideDao.delete(persistedManySide3);

    Assert.assertEquals(1, persistedOneSide1.getManySides().size());
    Assert.assertNull(persistedManySide2.getId());
    Assert.assertNull(persistedManySide2.getOneSide());
    Assert.assertNull(persistedManySide3.getId());
    Assert.assertNull(persistedManySide3.getOneSide());

    oneSideDao.delete(persistedOneSide2);
    Assert.assertNull(persistedOneSide2.getId());
    Assert.assertEquals(0, persistedOneSide2.getManySides().size());
  }
Esempio n. 6
0
 public static void deleteItem(TodoItem item) {
   try {
     final Dao<TodoItem, Integer> todoDao = TodoApp.get().getDbHelper().getTodoDao();
     todoDao.delete(item);
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Esempio n. 7
0
 <T> void deleteByPaymentGroup(Dao<T, Long> dao, PaymentGroup group) {
   DeleteBuilder<T, Long> builder = dao.deleteBuilder();
   try {
     builder.where().eq("paymentGroup_id", group.id);
     dao.delete(builder.prepare());
   } catch (SQLException e) {
     Logger.e(e);
   }
 }
Esempio n. 8
0
  public void remove(Remind item) {
    try {
      remindDao.delete(item);

      Log.i(TAG, String.format("%s: %d", "remove at base, id", item.getId()));
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
 public void clearLocal(Dao<NoiseEntry, Long> noiseDao, Dao<CommentEntry, Long> commDao) {
   this.is_local = false;
   this.my_capacity = 0.0;
   this.my_crowd = 0.0;
   this.my_productivity = 0.0;
   this.my_n_surveys = 0;
   try {
     // delete local noise data
     DeleteBuilder<NoiseEntry, Long> deletion = noiseDao.deleteBuilder();
     deletion.where().eq(NoiseEntry.COLUMN_NAME_IS_LOCAL, Boolean.TRUE);
     noiseDao.delete(deletion.prepare());
     // delete local comment data
     DeleteBuilder<CommentEntry, Long> deletion2 = commDao.deleteBuilder();
     deletion2.where().eq(CommentEntry.COLUMN_NAME_IS_LOCAL, Boolean.TRUE);
     commDao.delete(deletion2.prepare());
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Esempio n. 10
0
  public void remove() throws SQLException {
    Scanner sc = new Scanner(System.in);
    String id = sc.next();
    Dao<Account, String> accountDao = connect();

    accountDao.delete(accountDao.queryForId(id));
    System.out.println("Enter some string to continue");
    sc.next();
    connectionSource.close();
  }
Esempio n. 11
0
  /** 根据编号删除信息* */
  private void deleteByLocationNum(Locations locations) {
    try {
      List<Locations> locationsList =
          locationsesDao.queryBuilder().where().eq("locationsid", locations.locationsid).query();

      if (null != locationsList && locationsList.size() != 0) {
        locationsesDao.delete(locationsList.get(0));
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Esempio n. 12
0
 private void delete(MenuItem item) {
   AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
   Player player = (Player) getListAdapter().getItem(info.position);
   if (player == null && listener != null) {
     listener.onPlayerItemDeleteError(
         null, new Exception("Unable to locate Player on List Adapter"));
   } else if (listener == null || listener.onPlayerItemPreDelete(null)) {
     try {
       dao.delete(player);
       if (listener != null) listener.onPlayerItemPostDelete(player);
     } catch (SQLException e) {
       Log.d(TAG, "Delete Error for Player: " + player, e);
       if (listener != null) listener.onPlayerItemDeleteError(player, e);
     }
   }
 }
Esempio n. 13
0
 /**
  * Removes the last object returned by next() by calling delete on the dao associated with the
  * object.
  *
  * @throws IllegalStateException If there was no previous next() call.
  * @throws SQLException If the delete failed.
  */
 public void removeThrow() throws SQLException {
   if (last == null) {
     throw new IllegalStateException(
         "No last " + dataClass + " object to remove. Must be called after a call to next.");
   }
   if (classDao == null) {
     // we may never be able to get here since it should only be null for queryForAll methods
     throw new IllegalStateException(
         "Cannot remove " + dataClass + " object because classDao not initialized");
   }
   try {
     classDao.delete(last);
   } finally {
     // if we've try to delete it, clear the last marker
     last = null;
   }
 }
Esempio n. 14
0
 protected void removeOldAppointments(RecurringAction recurringAction) {
   Collection<Event> events = recurringAction.getEvents();
   for (Event event : events) {
     eventRepository.deleteEvent(event.getUri());
     recurringAction.removeEvent(event);
     event.setRecurringAction(null);
     try {
       eventDao.delete(event);
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
   try {
     recurringActionDao.update(recurringAction);
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
  /**
   * 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);
  }
Esempio n. 16
0
  @Override
  public int delete(int id) {
    final String methodName = "delete";
    Log.i(TAG, "START: " + methodName);
    long time = System.currentTimeMillis();

    int rows = 0;
    try {
      DeleteBuilder<Route, Integer> db = routetDao.deleteBuilder();
      db.where().eq("id", id);
      rows = routetDao.delete(db.prepare());
    } catch (SQLException e) {
      Log.e(TAG, methodName + " - blad przy usuwaniu trasy. " + e.getMessage());
      e.printStackTrace();
    }

    Log.i(TAG, "END: " + methodName + " TIME: " + (System.currentTimeMillis() - time));
    return rows;
  }
Esempio n. 17
0
  /** Do our sample database stuff. */
  private void doSampleDatabaseStuff(String action, TextView tv) {
    try {
      // get our dao
      Dao<SimpleData, Integer> simpleDao = getHelper().getSimpleDataDao();
      // query for all of the data objects in the database
      List<SimpleData> list = simpleDao.queryForAll();
      // our string builder for building the content-view
      StringBuilder sb = new StringBuilder();
      sb.append("got ").append(list.size()).append(" entries in ").append(action).append("\n");

      // if we already have items in the database
      if (list.size() > 0) {
        // output the first one
        SimpleData simple = list.get(0);
        sb.append("--------------------------------\n");
        sb.append("[0] = ").append(simple).append("\n");
        sb.append("--------------------------------\n");
        // delete it
        int ret = simpleDao.delete(simple);
        sb.append("deleted entry = ").append(ret).append("\n");
        Log.i(LOG_TAG, "deleting simple(" + simple.millis + ") returned " + ret);
      }

      // create a new simple object
      long millis = System.currentTimeMillis();
      SimpleData simple = new SimpleData(millis);
      // store it in the database
      int ret = simpleDao.create(simple);
      Log.i(LOG_TAG, "creating simple(" + millis + ") returned " + ret);

      // output it
      sb.append("created new entry = ").append(ret).append("\n");
      sb.append("--------------------------------\n");
      sb.append("new entry = ").append(simple).append("\n");
      sb.append("--------------------------------\n");
      tv.setText(sb.toString());
    } catch (SQLException e) {
      Log.e(LOG_TAG, "Database exception", e);
      return;
    }
  }
Esempio n. 18
0
  private void reset() {
    try {
      stopService(new Intent(ProxyDroid.this, ProxyDroidService.class));
    } catch (Exception e) {
      // Nothing
    }

    CopyAssets();

    try {
      DatabaseHelper helper = OpenHelperManager.getHelper(ProxyDroid.this, DatabaseHelper.class);
      Dao<DNSResponse, String> dnsCacheDao = helper.getDNSCacheDao();
      List<DNSResponse> list = dnsCacheDao.queryForAll();
      for (DNSResponse resp : list) {
        dnsCacheDao.delete(resp);
      }
    } catch (Exception ignore) {
      // Nothing
    }

    Utils.runRootCommand(
        Utils.getIptables()
            + " -t nat -F OUTPUT\n"
            + ProxyDroidService.BASE
            + "proxy.sh stop\n"
            + "kill -9 `cat /data/data/org.proxydroid/tproxy.pid`\n"
            + "kill -9 `cat /data/data/org.proxydroid/stunnel.pid`\n"
            + "kill -9 `cat /data/data/org.proxydroid/shrpx.pid`\n"
            + "kill -9 `cat /data/data/org.proxydroid/cntlm.pid`\n");

    Utils.runRootCommand(
        "chmod 700 /data/data/org.proxydroid/iptables\n"
            + "chmod 700 /data/data/org.proxydroid/redsocks\n"
            + "chmod 700 /data/data/org.proxydroid/proxy.sh\n"
            + "chmod 700 /data/data/org.proxydroid/cntlm\n"
            + "chmod 700 /data/data/org.proxydroid/tproxy\n"
            + "chmod 700 /data/data/org.proxydroid/stunnel\n"
            + "chmod 700 /data/data/org.proxydroid/shrpx\n");
  }
  public void handleMessage(Message msg) {
    // Receiving a message when the activity is not available will likely cause a fatal error.
    if (!SDLActivity.isActivityAvailable()) {
      Log.w("Received message when activity is not ready. Ignoring.");
      return;
    }

    switch (Command.values()[msg.arg1]) {
      case GAME_LOAD_ERROR:
        SharedPreferences prefs = activityContext.app.getPreferences();
        Editor editor = prefs.edit();
        editor.putInt("last_version", 0);
        editor.putBoolean("wizard_run", false);
        editor.apply();
        Dialog errorDialog = DialogFactory.createErrorDialog(activityContext);

        errorDialog.show();

        break;

      case SHOW_ABOUT_DIALOG:
        if (aboutDialog == null) {
          aboutDialog = DialogFactory.createAboutDialog(activityContext);
        }
        aboutDialog.show();
        break;

      case HIDE_KEYBOARD:
        /* mgr = (InputMethodManager) activityContext
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        mgr.hideSoftInputFromWindow(SDLActivity.mSurface.getWindowToken(), 0); */
        break;
      case SHOW_KEYBOARD:
        new SDLActivity.ShowTextInputTask(0, 0, 0, 0).run();
        break;
      case QUICK_LOAD:
        if (Files.doesFileExist(
            activityContext.app.configuration.getSaveGamesPath()
                + File.separator
                + activityContext.getString(R.string.quicksave_name))) {
          SDLActivity.cthLoadGame(activityContext.getString(R.string.quicksave_name));
        } else {
          Toast.makeText(activityContext, R.string.no_quicksave, Toast.LENGTH_SHORT).show();
        }
        break;
      case QUICK_SAVE:
        SDLActivity.cthSaveGame(activityContext.getString(R.string.quicksave_name));
        break;
      case RESTART_GAME:
        SDLActivity.cthRestartGame();
        break;

      case SHOW_LOAD_DIALOG:
        if (loadDialog == null) {
          loadDialog =
              new LoadDialog(activityContext, activityContext.app.configuration.getSaveGamesPath());
        }
        try {
          loadDialog.refreshSaves(activityContext);
          loadDialog.show();
        } catch (IOException e) {
          Reporting.reportWithToast(activityContext, "Problem loading load dialog", e);
        }
        break;

      case SHOW_SAVE_DIALOG:
        if (saveDialog == null) {
          saveDialog =
              new SaveDialog(activityContext, activityContext.app.configuration.getSaveGamesPath());
        }
        try {
          saveDialog.refreshSaves(activityContext);
          saveDialog.show();
        } catch (IOException e) {
          Reporting.reportWithToast(activityContext, "Problem loading save dialog", e);
        }

        break;
      case SHOW_MENU:
        activityContext.mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
        activityContext.mDrawerLayout.openDrawer(GravityCompat.START);
        break;
      case HIDE_MENU:
        activityContext.mDrawerLayout.closeDrawers();
        activityContext.mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        break;
      case PAUSE_GAME:
        SDLActivity.cthGameSpeed(0);
        break;
      case SHOW_SETTINGS_DIALOG:
        activityContext.startActivity(new Intent(activityContext, PrefsActivity.class));
        break;
      case GAME_SPEED_UPDATED:
        activityContext.app.configuration.setGameSpeed((Integer) msg.obj);
        break;
      case START_VIBRATION:
        Integer vibrationCode = (Integer) msg.obj;
        Log.d("Vibrating: " + vibrationCode);
        if (app.configuration.getHaptic()) {
          activityContext.playVibration(vibrationCode);
        }
        break;
      case STOP_VIBRATION:
        activityContext.stopVibration();
        playingEarthquake = false;
        break;
      case CHANGE_TITLE:
        // Do nothing
        break;
      case UNUSED:
        // Do nothing
        break;
      case TEXTEDIT_HIDE:
        activityContext.hideTextEdit();
        break;
      case SET_KEEP_SCREEN_ON:
        activityContext.setScreenOn((Integer) msg.obj != 0);
        break;
      case GAME_SAVE_UPDATED:
        Log.d("Game save updated");
        SaveData data = (SaveData) msg.obj;

        try {
          Dao<SaveData, String> dao = persistence.getDao(SaveData.class);
          // This doesn't work for some reason
          // Dao.CreateOrUpdateStatus status = dao.createOrUpdate(data);
          // Log.d("Saved game entries changed: " + status.getNumLinesChanged() + ". Created? " +
          // status.isCreated() + ". Updated? " + status.isUpdated());
          // So delete and recreate
          dao.delete(data);
          dao.create(data);

        } catch (SQLException e) {
          Reporting.report(e);
        }

        break;
      case SHOW_JUKEBOX:
        Log.d("Showing jukebox");
        SDLActivity.cthShowJukebox();
        break;
      default:
        break;
    }
  }
Esempio n. 20
0
 public <T, ID> int delete(T object) throws SQLException {
   @SuppressWarnings("unchecked")
   Class<T> clazz = (Class<T>) object.getClass();
   Dao<T, ID> dao = createDao(clazz);
   return dao.delete(object);
 }
 public int delete(RedmineAttachment item) throws SQLException {
   int count = dao.delete(item);
   return count;
 }
Esempio n. 22
0
 public int delete(RedmineRole item) throws SQLException {
   int count = dao.delete(item);
   return count;
 }