Beispiel #1
0
 public DBHelper getHelper() {
   if (this.dbhelper == null) {
     context = SisApp.getAppContext();
     this.dbhelper = OpenHelperManager.getHelper(this.context, DBHelper.class);
   }
   return this.dbhelper;
 }
  private void checkIfBackgrounded() {
    if (activityStack.size() == 0) {
      this.backgrounded = true;

      DataHelper.setDatabaseHelper(OpenHelperManager.getHelper(context, DatabaseHelper.class));
      DataHelper.refreshData(
          new DataHelperDelegate() {

            private int callCounter = 0;

            @Override
            public void dataReceivedThreaded(Method methodCalled, Object data) {
              callCounter++;
              if (callCounter
                  >= 3) { // we only want to set the database helper to null after all refresh data
                // callbacks have been made
                DataHelper.setDatabaseHelper(null);
                MyPlateApplication.setWorkingDateStamp(null);
              }
            }

            @Override
            public boolean errorOccurredThreaded(
                Method methodCalled, Exception error, String errorMessage) {
              return false;
            }
          });
    }
  }
  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);
    }
  }
Beispiel #4
0
  public static void saveToDatabase(Context context, final List<Account> items) {
    final DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);

    try {
      final Dao<Account, String> dao = helper.getAccountDao();
      dao.callBatchTasks(
          new Callable<Void>() {

            public Void call() throws Exception {
              // Delete all
              int removed = dao.delete(dao.deleteBuilder().prepare());
              if (Flags.DEBUG) {
                Log.d(LOG_TAG, "Deleted " + removed + " from database");
              }

              for (Account item : items) {
                dao.create(item);
              }
              if (Flags.DEBUG) {
                Log.d(LOG_TAG, "Inserted " + items.size() + " into database");
              }
              return null;
            }
          });
    } catch (Exception e) {
      if (Flags.DEBUG) {
        e.printStackTrace();
      }
    } finally {
      OpenHelperManager.releaseHelper();
    }
  }
 private DatabaseHelper getHelper() {
   if (databaseHelper == null) {
     databaseHelper =
         OpenHelperManager.getHelper(
             MemoryGameApplication.getMemoryGameInstance(), DatabaseHelper.class);
   }
   return databaseHelper;
 }
  private void readCurrentUser() {
    dbHelper = OpenHelperManager.getHelper(getApplicationContext(), WTDbHelper.class);
    RuntimeExceptionDao<User, String> userDao = dbHelper.getUserDao();

    SharedPreferences sp =
        getApplicationContext().getSharedPreferences("SettingInfo", MODE_PRIVATE);

    mUser = userDao.queryForId(sp.getString("CurrentSchoolNumber", ""));
  }
  public void updateUserDB(String jsonStr) throws Exception {
    JSONObject data = new JSONObject(jsonStr);
    JSONObject userStr = data.getJSONObject("User");

    Gson gson = new Gson();

    User user = gson.fromJson(userStr.toString(), User.class);

    // 写入user到数据库
    dbHelper = OpenHelperManager.getHelper(getApplicationContext(), WTDbHelper.class);
    RuntimeExceptionDao<User, String> userDao = dbHelper.getUserDao();
    userDao.update(user);
  }
Beispiel #8
0
  @Override
  public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (databaseHelper == null) {
      databaseHelper =
          OpenHelperManager.getHelper(getActivity().getApplicationContext(), DatabaseHelper.class);
    }

    if (getArguments().containsKey(ARG_ITEM_ID)) {
      marcaItem =
          databaseHelper.getMarcaDAO().queryForEq("id", getArguments().getLong(ARG_ITEM_ID)).get(0);
      // marcaItem =
      // Marca.ITEM_MAP.get(getArguments().getLong(ARG_ITEM_ID));
    }
  }
Beispiel #9
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;
  }
 private void cargarListadoIntereses() {
   OrmLiteSqliteOpenHelper helper = null;
   try {
     helper = OpenHelperManager.getHelper(this, DatabaseHelper.class);
     Dao<Interes, Integer> interesDao = helper.getDao(Interes.class);
     List<Interes> intereses = interesDao.queryForAll();
     interesesAdapter =
         new ArrayAdapter<Interes>(this, android.R.layout.simple_list_item_1, intereses);
     listViewIntereses.setAdapter(interesesAdapter);
   } catch (Exception e) {
     Log.e(TAG, "Error al cargar los clientes", e);
     GuiUtils.mostrarToast(this, R.string.operacion_error, null);
   } finally {
     try {
       OpenHelperManager.releaseHelper();
     } catch (Exception e2) {
       Log.e(TAG, "Error en el release", e2);
     }
   }
 }
Beispiel #11
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");
  }
Beispiel #12
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SQLiteDatabase.loadLibs(this);
    mDBHelper = OpenHelperManager.getHelper(this, DBHelper.class);
    mTemp = mDBHelper.getRuntimeExceptionDao(Temp.class);

    // 添加数据库数据库源
    findViewById(R.id.add_data)
        .setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                Temp mtep = new Temp();
                mtep.name = "aaaaa";
                mtep.pwd = "bbbb";
                mTemp.create(mtep);
              }
            });
    // 查询数据
    findViewById(R.id.query_data)
        .setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                try {
                  List<Temp> list = mTemp.queryForAll();
                  for (int i = 0; i < list.size(); i++) {
                    System.out.println("temp->" + list.get(i));
                  }
                } catch (Exception e) {
                }
              }
            });
  }
 public OrmLiteMovementManager(Context context) throws Exception {
   movementDao = OpenHelperManager.getHelper(context, OrmLiteHelper.class).getMovementDao();
   accountDao = OpenHelperManager.getHelper(context, OrmLiteHelper.class).getAccountDao();
 }
 public DatabaseHelper getDatabaseHelper() {
   if (databaseHelper == null) {
     databaseHelper = OpenHelperManager.getHelper(this, DatabaseHelper.class);
   }
   return databaseHelper;
 }
 protected ImonggoDBHelper getHelper() {
   if (dbHelper == null) dbHelper = OpenHelperManager.getHelper(this, ImonggoDBHelper.class);
   return dbHelper;
 }
 private DatabaseHelper getHelper() {
   if (databaseHelper == null) {
     databaseHelper = OpenHelperManager.getHelper(getActivity(), DatabaseHelper.class);
   }
   return databaseHelper;
 }
 /**
  * This is called internally by the class to populate the helper object instance. This should not
  * be called directly by client code unless you know what you are doing. Use {@link #getHelper()}
  * to get a helper instance. If you are managing your own helper creation, override this method to
  * supply this activity with a helper instance.
  *
  * <p><b> NOTE: </b> If you override this method, you most likely will need to override the {@link
  * #releaseHelper(OrmLiteSqliteOpenHelper)} method as well.
  */
 protected DatabaseHelper getHelperInternal(Context context) {
   DatabaseHelper newHelper =
       (DatabaseHelper) OpenHelperManager.getHelper(context, DatabaseHelper.class);
   return newHelper;
 }
Beispiel #18
0
 private DatabaseHelper getDatabaseHelper() {
   if (mDatabaseHelper == null) {
     mDatabaseHelper = OpenHelperManager.getHelper(this, DatabaseHelper.class);
   }
   return mDatabaseHelper;
 }
 /** Gets a reference to the DB. If it fails, it returns null instead. */
 protected DatabaseHelper getHelper() {
   if (databaseHelper == null) {
     databaseHelper = OpenHelperManager.getHelper(this.getBaseContext(), DatabaseHelper.class);
   }
   return databaseHelper;
 }
 public ReviewData(Context context) {
   databaseHelper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
   runtimeExceptionDao = databaseHelper.getReviewModelsDao();
 }