Пример #1
0
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    Log.d(TAG, "delete() uri " + uri);
    int uriType = sURIMatcher.match(uri);
    int rowsDeleted = 0;
    String id;
    SQLiteDatabase sqlDB = database.getWritableDatabase();

    switch (uriType) {
      case EVENTS:
        rowsDeleted = sqlDB.delete(TABLE_EVENTS, selection, selectionArgs);
        break;
      case RECORDS:
        rowsDeleted = sqlDB.delete(TABLE_RECORDS, selection, selectionArgs);
        break;
      case EMPLOYEES:
        rowsDeleted = sqlDB.delete(TABLE_EMPLOYEES, selection, selectionArgs);
        break;
      case EVENT_ID:
        id = uri.getLastPathSegment();
        rowsDeleted =
            sqlDB.delete(TABLE_EVENTS, EventManager.EventQuery.SELECTION_ID, new String[] {id});
        break;
      case EMPLOYEE_ID:
        id = uri.getLastPathSegment();
        rowsDeleted =
            sqlDB.delete(TABLE_EMPLOYEES, EventManager.EventQuery.SELECTION_ID, new String[] {id});
        break;
      default:
        break;
    }
    getContext().getContentResolver().notifyChange(uri, null);
    Log.d(TAG, "delete() rowsDeleted " + rowsDeleted);
    return rowsDeleted;
  }
Пример #2
0
  @Override
  public Uri insert(Uri uri, ContentValues values) {
    Log.d(TAG, "insert()" + "uri = [" + uri + "], values = [" + values + "]");
    int uriType = sURIMatcher.match(uri);

    long id = 0;
    // ziska odkaz na databazi
    SQLiteDatabase sqlDB = database.getWritableDatabase();

    switch (uriType) {
      case EVENTS:
        // muze vlozit jen 1 zaznam
        id = sqlDB.insert(TABLE_EVENTS, null, values);
        break;
      case EMPLOYEES:
        id = sqlDB.insert(TABLE_EMPLOYEES, null, values);
        break;
      case RECORDS:
        id = sqlDB.insert(TABLE_RECORDS, null, values);
      default:
        break;
    }

    uri = Uri.withAppendedPath(uri, String.valueOf(id));
    getContext().getContentResolver().notifyChange(uri, null);
    Log.d(TAG, "insert() uri " + uri);
    return uri;
  }
Пример #3
0
  static {
    sURIMatcher.addURI(AppConsts.AUTHORITY1, TABLE_EVENTS, EVENTS);
    sURIMatcher.addURI(AppConsts.AUTHORITY1, TABLE_RECORDS, RECORDS);
    sURIMatcher.addURI(AppConsts.AUTHORITY1, TABLE_EVENTS + "/#", EVENT_ID);
    sURIMatcher.addURI(AppConsts.AUTHORITY1, TABLE_RECORDS + "/#", RECORD_ID);

    sURIMatcher.addURI(AppConsts.AUTHORITY2, TABLE_EMPLOYEES, EMPLOYEES);
    sURIMatcher.addURI(AppConsts.AUTHORITY2, TABLE_EMPLOYEES + "/#", EMPLOYEE_ID);

    sURIMatcher.addURI(AppConsts.AUTHORITY3, TABLE_EMPLOYEES, EMPLOYEES);
    sURIMatcher.addURI(AppConsts.AUTHORITY3, TABLE_EMPLOYEES + "/#", EMPLOYEE_ID);
  }
Пример #4
0
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Log.d(
        TAG,
        "uri = ["
            + uri
            + "], projection = ["
            + projection
            + "], "
            + "selection = ["
            + selection
            + "], selectionArgs = ["
            + Arrays.toString(selectionArgs)
            + "], "
            + "sortOrder = ["
            + sortOrder
            + "]");
    Log.d(TAG, "query() uri " + uri);
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();

    int uriType = sURIMatcher.match(uri);
    switch (uriType) {
      case EVENTS:
        // vsechny radky tabulky
        queryBuilder.setTables(TABLE_EVENTS);
        break;
      case RECORDS:
        // vsechny radky tabulky
        queryBuilder.setTables(TABLE_RECORDS);
        break;
      case EMPLOYEES:
        queryBuilder.setTables(TABLE_EMPLOYEES);
        break;
      default:
        break;
    }

    SQLiteDatabase db = database.getWritableDatabase();

    Cursor cursor =
        queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
    Log.d(TAG, "query() cursor size " + cursor.getCount());

    cursor.setNotificationUri(getContext().getContentResolver(), uri);

    return cursor;
  }
  @Override
  public FilterDirector handleRequest(
      HttpServletRequest request, ReadableHttpServletResponse response) {
    FilterDirector filterDirector = new FilterDirectorImpl();
    filterDirector.setResponseStatus(HttpStatusCode.UNAUTHORIZED);
    filterDirector.setFilterAction(FilterAction.RETURN);

    final String uri = request.getRequestURI();
    LOG.debug("Uri is " + uri);
    if (uriMatcher.isUriOnWhiteList(uri)) {
      filterDirector.setFilterAction(FilterAction.PASS);
      LOG.debug("Uri is on whitelist!  Letting request pass through.");
    } else {
      filterDirector = this.authenticate(request);
    }

    return filterDirector;
  }
Пример #6
0
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    Log.d(TAG, "update uri " + uri);
    int rowsUpdated = 0;

    int uriType = sURIMatcher.match(uri);
    String id;
    SQLiteDatabase sqlDB = database.getWritableDatabase();

    switch (uriType) {
      case EVENTS:
        rowsUpdated = sqlDB.update(TABLE_EVENTS, values, selection, selectionArgs);
        break;
      case RECORDS:
        rowsUpdated = sqlDB.update(TABLE_RECORDS, values, selection, selectionArgs);
        break;
      case RECORD_ID:
        id = uri.getLastPathSegment();
        rowsUpdated = sqlDB.update(TABLE_RECORDS, values, Record.COL_ID + "=" + id, null);
        break;
      case EMPLOYEE_ID:
        id = uri.getLastPathSegment();
        rowsUpdated = sqlDB.update(TABLE_EMPLOYEES, values, Employee.COL_ID + "=" + id, null);
        break;
      case EMPLOYEES:
        rowsUpdated = sqlDB.update(TABLE_EMPLOYEES, values, selection, selectionArgs);
        if (rowsUpdated > 0) uri = Uri.withAppendedPath(uri, selectionArgs[0]);
        break;
      case EVENT_ID:
        id = uri.getLastPathSegment();
        rowsUpdated = sqlDB.update(TABLE_EVENTS, values, Event.COL_ID + "=" + id, null);
        break;
      default:
        break;
    }
    getContext().getContentResolver().notifyChange(uri, null);

    return rowsUpdated;
  }