Example usage for android.content ContentValues remove

List of usage examples for android.content ContentValues remove

Introduction

In this page you can find the example usage for android.content ContentValues remove.

Prototype

public void remove(String key) 

Source Link

Document

Remove a single value.

Usage

From source file:org.most.persistence.DBAdapter.java

/**
 * Flushes all currently buffered data to the database. This method
 * <em>does not</em> require to acquire the DB lock beforehand.
 *//*  ww  w. ja v  a  2  s  . co  m*/
public void flushData() {
    Log.d(TAG, "Flushing MoST db.");
    logger.info("Flushing MoST db.");
    _runningDump.set(true);
    long start = System.currentTimeMillis();
    if (open() == null) {
        Log.e(TAG, "Unable to write data to db.");
        logger.error("Unable to write data to db.");
        _runningDump.set(false);
        return;
    }
    updateList();
    int linesCount = 0;
    _db.beginTransaction();
    try {
        LinkedBlockingQueue<ContentValues> list;
        while ((list = _dataToDump.poll()) != null) {
            for (ContentValues data : list) {
                String tableName = data.getAsString(FLD_TABLE);
                data.remove(FLD_TABLE);
                _db.insert(tableName, null, data);
                linesCount++;
            }
        }
        // commit on successful write
        _db.setTransactionSuccessful();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        _db.endTransaction();
        close();
        start = System.currentTimeMillis() - start;
        Log.i(TAG, "DB write time: " + start + "ms for " + linesCount + " entries.");
        _runningDump.set(false);
    }
}

From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java

/**
 * Updates the persons table./*w  w  w.  j  a v  a2s  . co  m*/
 * @param values Values
 * @return Affected rows
 */
public int updatePersons(List<ContentValues> values) {
    int affectedRows = 0;
    for (ContentValues item : values) {
        item.remove("person_id");
        // update table
        affectedRows += updateTable(item, "person");
    }
    return affectedRows;
}

From source file:bander.notepad.NoteEditAppCompat.java

@Override
protected void onPause() {
    super.onPause();

    if (mUri != null) {
        String bodyText = mBodyText.getText().toString();
        int length = bodyText.length();

        if ((mState == STATE_INSERT) && isFinishing() && (length == 0)) {
            // If inserting and finishing and no text then delete the note.
            setResult(RESULT_CANCELED);/*from   w ww. j av a2 s.c o  m*/
            deleteNote();
        } else {
            ContentValues values = mOriginalNote.getContentValues();
            if (values.containsKey(Note._ID))
                values.remove(Note._ID);

            if (mState == STATE_INSERT) {
                String[] lines = bodyText.split("[\n\\.]");
                String title = (lines.length > 0) ? lines[0] : getString(android.R.string.untitled);
                if (title.length() > 30) {
                    int lastSpace = title.lastIndexOf(' ');
                    if (lastSpace > 0) {
                        title = title.substring(0, lastSpace);
                    }
                }
                values.put(Note.TITLE, title);
            }
            values.put(Note.BODY, bodyText);
            values.put(Note.CURSOR, mBodyText.getSelectionStart());
            values.put(Note.SCROLL_Y, mBodyText.getScrollY());

            getContentResolver().update(mUri, values, null, null);
        }
    }
}

From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java

/**
 * Updates the patients table./*from w  w  w.j a va2  s .  c  o m*/
  * @param values Values
 * @return Affected rows
 */
public int updatePatients(List<ContentValues> values) {
    int affectedRows = 0;
    for (ContentValues item : values) {
        // prepare relations to locale IDs
        item.remove("patient_id");
        String uuid = item.getAsString("uuid");
        item.remove("uuid");
        int id = getPersonIDByUUID(uuid);
        item.put("patient_id", id);
        // update table
        affectedRows += updatePatientTable(item);
    }
    return affectedRows;
}

From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java

/**
 * Updates the obs table.//from  ww  w  .jav a 2 s.  c o m
  * @param values Values
 * @return Affected rows
 */
public int updateObs(List<ContentValues> values) {
    int affectedRows = 0;
    for (ContentValues item : values) {
        // prepare relations to locale IDs
        item.remove("obs_id");
        String personUUID = item.getAsString("person_id");
        String encounterUUID = item.getAsString("encounter_id");
        String obsGroupUUID = item.getAsString("obs_group_id");
        item.remove("person_id");
        item.remove("encounter_id");
        item.remove("obs_group_id");
        item.put("person_id", getPersonIDByUUID(personUUID));
        item.put("encounter_id", getEncounterIDByUUID(encounterUUID));
        if (obsGroupUUID != null) {
            item.put("obs_group_id", getObsIDByUUID(obsGroupUUID));
        }
        affectedRows += updateTable(item, "obs");
    }
    return affectedRows;
}

From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java

/**
 * Updates the tables with relation to the person table.
  * @param values Values/*from   ww w  .j a  v  a  2  s  .com*/
 * @param table Table
 * @param relationColumn Name of relation column
 * @return Affected rows
 */
public int updatePersonChildren(List<ContentValues> values, String table, String relationColumn) {
    int affectedRows = 0;
    for (ContentValues item : values) {
        // prepare relations to locale IDs
        String relationUUID = item.getAsString(relationColumn);
        item.remove(relationColumn);
        item.put(relationColumn, getPersonIDByUUID(relationUUID));
        // update table
        affectedRows += updateTable(item, table);
    }
    return affectedRows;
}

From source file:p1.nd.khan.jubair.mohammadd.popularmovies.adapter.MovieDetailsAdapter.java

/**
 * Method to check if movie is favorite.
 *
 * @param movieId to check./*w ww.  ja  va 2  s.c om*/
 * @return movie title after addition else null
 */
private String addToFavorites(int movieId) {
    String title = null;
    String[] projection = new String[] { "*" };
    String selection = MovieEntry.C_MOVIE_ID + "=?";
    String[] selectionArgs = { String.valueOf(movieId) };

    ContentResolver contentResolver = mContext.getContentResolver();
    Cursor cMovies = null;
    Cursor cTrailers = null;
    Cursor cReviews = null;

    try {
        cMovies = contentResolver.query(MovieEntry.CONTENT_URI, projection, selection, selectionArgs, null);
        if (null != cMovies && cMovies.moveToFirst()) {
            ContentValues contentValues = new ContentValues();
            DatabaseUtils.cursorRowToContentValues(cMovies, contentValues);
            contentValues.remove("_id");
            title = contentValues.getAsString(MovieEntry.C_ORIGINAL_TITLE);
            contentResolver.insert(MovieEntry.FAVORITES_CONTENT_URI, contentValues);
        }
        cTrailers = contentResolver.query(TrailersEntry.CONTENT_URI, projection, selection, selectionArgs,
                null);
        while (null != cTrailers && cTrailers.moveToNext()) {
            ContentValues contentValues = new ContentValues();
            DatabaseUtils.cursorRowToContentValues(cTrailers, contentValues);
            contentValues.remove("_id");
            contentResolver.insert(TrailersEntry.FAVORITES_CONTENT_URI, contentValues);
        }
        cReviews = contentResolver.query(ReviewsEntry.CONTENT_URI, projection, selection, selectionArgs, null);
        while (null != cReviews && cReviews.moveToNext()) {
            ContentValues contentValues = new ContentValues();
            DatabaseUtils.cursorRowToContentValues(cReviews, contentValues);
            contentValues.remove("_id");
            contentResolver.insert(ReviewsEntry.FAVORITES_CONTENT_URI, contentValues);
        }
    } catch (SQLException e) {
        Log.e(LOG_TAG, "SQLException!");
    } finally {
        if (null != cMovies)
            cMovies.close();
        if (null != cTrailers)
            cTrailers.close();
        if (null != cReviews)
            cReviews.close();
    }
    return title;
}

From source file:id.ridon.keude.UpdateService.java

private ContentProviderOperation updateExistingApp(App app) {
    Uri uri = AppProvider.getContentUri(app);
    ContentValues values = app.toContentValues();
    for (String toIgnore : APP_FIELDS_TO_IGNORE) {
        if (values.containsKey(toIgnore)) {
            values.remove(toIgnore);
        }/*ww w  .  j  a  v a2  s  .c  o m*/
    }
    return ContentProviderOperation.newUpdate(uri).withValues(values).build();
}

From source file:org.opendatakit.common.android.provider.impl.FormsProviderImpl.java

private void patchUpValues(String appName, ContentValues values) {
    // don't let users put in a manual FORM_FILE_PATH
    if (values.containsKey(FormsColumns.APP_RELATIVE_FORM_FILE_PATH)) {
        values.remove(FormsColumns.APP_RELATIVE_FORM_FILE_PATH);
    }//from   w  w  w . j a va  2  s . c  om

    // don't let users put in a manual FORM_PATH
    if (values.containsKey(FormsColumns.FORM_PATH)) {
        values.remove(FormsColumns.FORM_PATH);
    }

    // don't let users put in a manual DATE
    if (values.containsKey(FormsColumns.DATE)) {
        values.remove(FormsColumns.DATE);
    }

    // don't let users put in a manual md5 hash
    if (values.containsKey(FormsColumns.MD5_HASH)) {
        values.remove(FormsColumns.MD5_HASH);
    }

    // don't let users put in a manual json md5 hash
    if (values.containsKey(FormsColumns.JSON_MD5_HASH)) {
        values.remove(FormsColumns.JSON_MD5_HASH);
    }

    // if we are not updating FORM_MEDIA_PATH, we don't need to recalc any
    // of the above
    if (!values.containsKey(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH)) {
        return;
    }

    // Normalize path...

    // First, construct the full file path...
    String path = values.getAsString(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH);
    File mediaPath;
    if (path.startsWith(File.separator)) {
        mediaPath = new File(path);
    } else {
        mediaPath = ODKFileUtils.asAppFile(appName, path);
    }

    // require that the form directory actually exists
    if (!mediaPath.exists()) {
        throw new IllegalArgumentException(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH
                + " directory does not exist: " + mediaPath.getAbsolutePath());
    }

    if (!ODKFileUtils.isPathUnderAppName(appName, mediaPath)) {
        throw new IllegalArgumentException(
                "Form definition is not contained within the application: " + appName);
    }

    values.put(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH, ODKFileUtils.asRelativePath(appName, mediaPath));

    // require that it contain a formDef file
    File formDefFile = new File(mediaPath, ODKFileUtils.FORMDEF_JSON_FILENAME);
    if (!formDefFile.exists()) {
        throw new IllegalArgumentException(
                ODKFileUtils.FORMDEF_JSON_FILENAME + " does not exist in: " + mediaPath.getAbsolutePath());
    }

    // date is the last modification date of the formDef file
    Long now = formDefFile.lastModified();
    values.put(FormsColumns.DATE, now);

    // ODK2: FILENAME_XFORMS_XML may not exist if non-ODK1 fetch path...
    File xformsFile = new File(mediaPath, ODKFileUtils.FILENAME_XFORMS_XML);
    if (xformsFile.exists()) {
        values.put(FormsColumns.APP_RELATIVE_FORM_FILE_PATH, ODKFileUtils.asRelativePath(appName, xformsFile));
    }

    // compute FORM_PATH...
    String formPath = ODKFileUtils.getRelativeFormPath(appName, formDefFile);
    values.put(FormsColumns.FORM_PATH, formPath);

    String md5;
    if (xformsFile.exists()) {
        md5 = ODKFileUtils.getMd5Hash(appName, xformsFile);
    } else {
        md5 = "-none-";
    }
    values.put(FormsColumns.MD5_HASH, md5);

    md5 = ODKFileUtils.getMd5Hash(appName, formDefFile);
    values.put(FormsColumns.JSON_MD5_HASH, md5);
}

From source file:com.odoo.support.provider.OContentProvider.java

private HashMap<String, List<Integer>> getManyToManyRecords(ContentValues values) {
    HashMap<String, List<Integer>> ids = new HashMap<String, List<Integer>>();
    for (OColumn col : model.getRelationColumns()) {
        if (col.getRelationType() == RelationType.ManyToMany) {
            if (values.containsKey(col.getName())) {
                List<Integer> record_ids = new ArrayList<Integer>();
                try {
                    record_ids.addAll(// w  w  w .j  a v  a  2  s.c  om
                            JSONUtils.<Integer>toList(new JSONArray(values.get(col.getName()).toString())));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                ids.put(col.getName(), record_ids);
                values.remove(col.getName());
            }
        }
    }
    return ids;
}