コード例 #1
0
ファイル: UserProvider.java プロジェクト: sanwazi/Servant
  @SuppressLint("LongLogTag")
  @Override
  public Uri insert(Uri uri, ContentValues values) {

    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final int match = sUriMatcher.match(uri);

    Uri returnUri;

    if (match == USERS) {

      try {
        long _id = db.insert(UserContract.UserEntry.TABLE_NAME, null, values);
        returnUri = UserContract.UserEntry.buildUserUri(_id);
      } catch (SQLiteConstraintException e) {
        Log.e("Username unique exception: ", e.toString());
        returnUri = UserContract.UserEntry.buildUserUri(-1);
      }

    } else {
      throw new UnsupportedOperationException("Unknown uri: " + uri);
    }

    if (db != null) db.close();

    getContext().getContentResolver().notifyChange(uri, null);
    return returnUri;
  }
コード例 #2
0
ファイル: SenzHandler.java プロジェクト: coderaashir/homez
  private void handleShareSenz(Senz senz) {
    // SwitchesDB db = new SwitchesDB(context);
    DBSource db = new DBSource(context);
    // if senz already exists in the db, SQLiteConstraintException should throw
    // get gpio and save in database
    // Log.e(TAG,"============="+senz.getAttributes().size());
    try {
      db.deleteTable();
      Log.e(TAG, senz.getAttributes() + "=======================================");

      for (Map.Entry<String, String> entry : senz.getAttributes().entrySet()) {
        String key = entry.getKey();
        if (!key.contains("homez") && !key.contains("time")) {
          db.createSwitch(key);
        }
        if (key.contains("homez")) {
          Log.e(
              TAG,
              "=================App =  "
                  + key
                  + "  User "
                  + senz.getSender().getUsername()
                  + " added to DB======================");
          db.deleteUser(senz.getSender().getUsername());
          db.createUser(senz.getSender().getUsername());
          db.resetUserStatus();
          db.setUserStatus(senz.getSender().getUsername(), 1);
        }
      }

      NotificationUtils.showNotification(
          context,
          context.getString(R.string.new_senz),
          "SmartHome Switches are Shared from @" + senz.getSender().getUsername());
      Log.e(TAG, "Swithes and User are Added To Homes DB");
    } catch (SQLiteConstraintException e) {
      Log.e(TAG, e.toString());
    }
  }
コード例 #3
0
  @Override
  public int bulkInsert(Uri aUri, ContentValues[] aValues) {
    String table = null;
    int result = 0;

    SQLiteDatabase db = mDbHelper.getWritableDatabase();

    final int match = sUriMatcher.match(aUri);
    switch (match) {
      case FORUM:
        table = TABLE_FORUM;
        break;
      case SUBFORUM:
        table = TABLE_SUBFORUM;
        break;
    }

    db.beginTransaction();

    try {
      for (ContentValues value : aValues) {
        db.insert(table, "", value);
        result++;
      }

      db.setTransactionSuccessful();

      if (result > 0) {
        getContext().getContentResolver().notifyChange(aUri, null);
      }
    } catch (SQLiteConstraintException e) {
      Log.i(TAG, e.toString());
    } finally {
      db.endTransaction();
    }

    return result;
  }