Java Code Examples for android.content.ContentValues#putAll()

The following examples show how to use android.content.ContentValues#putAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseDAO.java    From fingen with Apache License 2.0 6 votes vote down vote up
synchronized void bulkUpdateItem(String where, ContentValues contentValues, boolean resetTS) {
    List<IAbstractModel> inputModels = getModels(where);
    List<IAbstractModel> outputModels = new ArrayList<>();

    if (inputModels.isEmpty()) return;

    ContentValues cv = new ContentValues();
    mDatabase.beginTransaction();
    for (IAbstractModel model : inputModels) {
        cv.clear();
        cv.putAll(contentValues);
        if (resetTS) cv.put(DBHelper.C_SYNC_TS, -1);
        mDatabase.update(mTableName, cv, String.format("%s = %s", C_ID, String.valueOf(model.getID())), null);
        outputModels.add(getModelById(model.getID()));
    }
    mDatabase.setTransactionSuccessful();
    mDatabase.endTransaction();
    if (resetTS)
        EventBus.getDefault().postSticky(new Events.EventOnModelChanged(outputModels, createModelByTable().getModelType(), Events.MODEL_CHANGED));
}
 
Example 2
Source File: DatabaseBackend.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
private void storeIdentityKey(Account account, String name, boolean own, String fingerprint, String base64Serialized, FingerprintStatus status) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(SQLiteAxolotlStore.ACCOUNT, account.getUuid());
    values.put(SQLiteAxolotlStore.NAME, name);
    values.put(SQLiteAxolotlStore.OWN, own ? 1 : 0);
    values.put(SQLiteAxolotlStore.FINGERPRINT, fingerprint);
    values.put(SQLiteAxolotlStore.KEY, base64Serialized);
    values.putAll(status.toContentValues());
    String where = SQLiteAxolotlStore.ACCOUNT + "=? AND " + SQLiteAxolotlStore.NAME + "=? AND " + SQLiteAxolotlStore.FINGERPRINT + " =?";
    String[] whereArgs = {account.getUuid(), name, fingerprint};
    int rows = db.update(SQLiteAxolotlStore.IDENTITIES_TABLENAME, values, where, whereArgs);
    if (rows == 0) {
        db.insert(SQLiteAxolotlStore.IDENTITIES_TABLENAME, null, values);
    }
}
 
Example 3
Source File: Assert.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
public static App insertApp(Context context, String packageName, String name, ContentValues additionalValues) {

        ContentValues values = new ContentValues();
        values.put(AppMetadataTable.Cols.REPO_ID, 1);
        values.put(AppMetadataTable.Cols.Package.PACKAGE_NAME, packageName);
        values.put(AppMetadataTable.Cols.NAME, name);

        // Required fields (NOT NULL in the database).
        values.put(AppMetadataTable.Cols.SUMMARY, "test summary");
        values.put(AppMetadataTable.Cols.DESCRIPTION, "test description");
        values.put(AppMetadataTable.Cols.LICENSE, "GPL?");
        values.put(AppMetadataTable.Cols.IS_COMPATIBLE, 1);

        values.putAll(additionalValues);

        // Don't hard code to 1, let consumers override it in additionalValues then ask for it back.
        int repoId = values.getAsInteger(AppMetadataTable.Cols.REPO_ID);

        Uri uri = AppProvider.getContentUri();

        context.getContentResolver().insert(uri, values);
        App app = AppProvider.Helper.findSpecificApp(context.getContentResolver(), packageName,
                repoId, AppMetadataTable.Cols.ALL);
        assertNotNull(app);
        return app;
    }
 
Example 4
Source File: Assert.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
public static Uri insertApk(Context context, App app, int versionCode, ContentValues additionalValues) {

        ContentValues values = new ContentValues();

        values.put(ApkTable.Cols.APP_ID, app.getId());
        values.put(ApkTable.Cols.VERSION_CODE, versionCode);

        // Required fields (NOT NULL in the database).
        values.put(ApkTable.Cols.REPO_ID, 1);
        values.put(ApkTable.Cols.VERSION_NAME, "The good one");
        values.put(ApkTable.Cols.HASH, "11111111aaaaaaaa");
        values.put(ApkTable.Cols.NAME, "Test Apk");
        values.put(ApkTable.Cols.SIZE, 10000);
        values.put(ApkTable.Cols.IS_COMPATIBLE, 1);

        values.putAll(additionalValues);

        Uri uri = ApkProvider.getContentUri();

        return context.getContentResolver().insert(uri, values);
    }
 
Example 5
Source File: DatabaseBackend.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
private void storeIdentityKey(Account account, String name, boolean own, String fingerprint, String base64Serialized, FingerprintStatus status) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(SQLiteAxolotlStore.ACCOUNT, account.getUuid());
    values.put(SQLiteAxolotlStore.NAME, name);
    values.put(SQLiteAxolotlStore.OWN, own ? 1 : 0);
    values.put(SQLiteAxolotlStore.FINGERPRINT, fingerprint);
    values.put(SQLiteAxolotlStore.KEY, base64Serialized);
    values.putAll(status.toContentValues());
    String where = SQLiteAxolotlStore.ACCOUNT + "=? AND " + SQLiteAxolotlStore.NAME + "=? AND " + SQLiteAxolotlStore.FINGERPRINT + " =?";
    String[] whereArgs = {account.getUuid(), name, fingerprint};
    int rows = db.update(SQLiteAxolotlStore.IDENTITIES_TABLENAME, values, where, whereArgs);
    if (rows == 0) {
        db.insert(SQLiteAxolotlStore.IDENTITIES_TABLENAME, null, values);
    }
}
 
Example 6
Source File: DatabaseBackend.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
public void storePreVerification(Account account, String name, String fingerprint, FingerprintStatus status) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(SQLiteAxolotlStore.ACCOUNT, account.getUuid());
    values.put(SQLiteAxolotlStore.NAME, name);
    values.put(SQLiteAxolotlStore.OWN, 0);
    values.put(SQLiteAxolotlStore.FINGERPRINT, fingerprint);
    values.putAll(status.toContentValues());
    db.insert(SQLiteAxolotlStore.IDENTITIES_TABLENAME, null, values);
}
 
Example 7
Source File: DatabaseSaver.java    From droitatedDB with Apache License 2.0 5 votes vote down vote up
private void updateToOneAssos(final Object key, final Collection<ToOneUpdate> updates) {
	ContentValues values = new ContentValues();
	for (ToOneUpdate toOneUpdate : updates) {
		values.putAll(toOneUpdate.getContentValues());
	}
	EntityData entityData = EntityData.getEntityData(key);
	update(getPrimaryKey(key, entityData), key.getClass(), entityData, values);
}
 
Example 8
Source File: EventsHelper.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public ContentValues onInsert(ContentValues values) {
    ContentValues vals = new ContentValues();
    vals.put(Contract.UUID, UUID.randomUUID().toString());
    vals.put(Contract.EVENT_TYPE, "");
    vals.put(Contract.EVENT_VALUE, "");
    vals.put(Contract.UPLOADED, false);
    vals.put(Contract.SUBJECT, "");
    vals.put(Contract.ENCOUNTER, "");
    vals.put(Contract.OBSERVER, "");
    vals.putAll(values);
    return super.onInsert(vals);
}
 
Example 9
Source File: EncounterTasksHelper.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public ContentValues onInsert(ContentValues values) {
    ContentValues vals = new ContentValues();
    //vals.put(Contract.UUID, UUID.randomUUID().toString());
    //vals.put(Contract.STATUS, Status.ACCEPTED.toString());
    vals.put(Contract.OBSERVER, "");
    vals.put(Contract.ENCOUNTER, "");
    vals.put(Contract.PROCEDURE, "");
    vals.put(Contract.SUBJECT, "");
    String dueStr = values.getAsString(Contract.DUE_DATE);
    Date dueDate = new Date();
    try {
        dueDate = (dueStr != null) ? sdf.parse(dueStr) : new Date();

        Date checkDate;

        String completed = values.getAsString(Contract.COMPLETED);
        if (!TextUtils.isEmpty(completed)) {
            checkDate = sdf.parse(completed);
            vals.put(Contract.COMPLETED, sdf.format(completed));
        }
        String started = values.getAsString(Contract.STARTED);
        if (!TextUtils.isEmpty(started)) {
            checkDate = sdf.parse(started);
            vals.put(Contract.STARTED, sdf.format(started));
        }
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    vals.put(Contract.DUE_DATE, sdf.format(dueDate));

    vals.putAll(values);
    return super.onInsert(vals);
}
 
Example 10
Source File: TableHelper.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sets the creation and modification time to the current date time
 * formatted as {@link org.sana.api.IModel#DATE_FORMAT}
 */
@Override
public ContentValues onInsert(ContentValues values) {
    ContentValues validValues = new ContentValues();
    String value = new SimpleDateFormat(IModel.DATE_FORMAT,
            Locale.US).format(new Date());
    if (!values.containsKey(BaseContract.UUID))
        throw new IllegalArgumentException("Can not insert without uuid");
    //validValues.put(BaseContract.UUID, UUID.randomUUID().toString());
    validValues.put(BaseContract.CREATED, value);
    validValues.put(BaseContract.MODIFIED, value);
    validValues.putAll(values);
    return validValues;
}
 
Example 11
Source File: TableHelper.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sets the modification time to the current date time if not present,
 * formatted as {@link org.sana.api.IModel#DATE_FORMAT}
 */
@Override
public ContentValues onUpdate(Uri uri, ContentValues values) {
    ContentValues validValues = new ContentValues();
    if (!values.containsKey(BaseContract.MODIFIED)) {
        String value = new SimpleDateFormat(IModel.DATE_FORMAT,
                Locale.US).format(new Date());
        validValues.put(BaseContract.MODIFIED, value);
    }
    validValues.putAll(values);
    return validValues;
}
 
Example 12
Source File: DatabaseBackend.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
public void storePreVerification(Account account, String name, String fingerprint, FingerprintStatus status) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(SQLiteAxolotlStore.ACCOUNT, account.getUuid());
    values.put(SQLiteAxolotlStore.NAME, name);
    values.put(SQLiteAxolotlStore.OWN, 0);
    values.put(SQLiteAxolotlStore.FINGERPRINT, fingerprint);
    values.putAll(status.toContentValues());
    db.insert(SQLiteAxolotlStore.IDENTITIES_TABLENAME, null, values);
}
 
Example 13
Source File: TestProvider.java    From Advanced_Android_Development with Apache License 2.0 4 votes vote down vote up
public void testInsertReadProvider() {
    ContentValues testValues = TestUtilities.createNorthPoleLocationValues();

    // Register a content observer for our insert.  This time, directly with the content resolver
    TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
    mContext.getContentResolver().registerContentObserver(LocationEntry.CONTENT_URI, true, tco);
    Uri locationUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, testValues);

    // Did our content observer get called?  Students:  If this fails, your insert location
    // isn't calling getContext().getContentResolver().notifyChange(uri, null);
    tco.waitForNotificationOrFail();
    mContext.getContentResolver().unregisterContentObserver(tco);

    long locationRowId = ContentUris.parseId(locationUri);

    // Verify we got a row back.
    assertTrue(locationRowId != -1);

    // Data's inserted.  IN THEORY.  Now pull some out to stare at it and verify it made
    // the round trip.

    // A cursor is your primary interface to the query results.
    Cursor cursor = mContext.getContentResolver().query(
            LocationEntry.CONTENT_URI,
            null, // leaving "columns" null just returns all the columns.
            null, // cols for "where" clause
            null, // values for "where" clause
            null  // sort order
    );

    TestUtilities.validateCursor("testInsertReadProvider. Error validating LocationEntry.",
            cursor, testValues);

    // Fantastic.  Now that we have a location, add some weather!
    ContentValues weatherValues = TestUtilities.createWeatherValues(locationRowId);
    // The TestContentObserver is a one-shot class
    tco = TestUtilities.getTestContentObserver();

    mContext.getContentResolver().registerContentObserver(WeatherEntry.CONTENT_URI, true, tco);

    Uri weatherInsertUri = mContext.getContentResolver()
            .insert(WeatherEntry.CONTENT_URI, weatherValues);
    assertTrue(weatherInsertUri != null);

    // Did our content observer get called?  Students:  If this fails, your insert weather
    // in your ContentProvider isn't calling
    // getContext().getContentResolver().notifyChange(uri, null);
    tco.waitForNotificationOrFail();
    mContext.getContentResolver().unregisterContentObserver(tco);

    // A cursor is your primary interface to the query results.
    Cursor weatherCursor = mContext.getContentResolver().query(
            WeatherEntry.CONTENT_URI,  // Table to Query
            null, // leaving "columns" null just returns all the columns.
            null, // cols for "where" clause
            null, // values for "where" clause
            null // columns to group by
    );

    TestUtilities.validateCursor("testInsertReadProvider. Error validating WeatherEntry insert.",
            weatherCursor, weatherValues);

    // Add the location values in with the weather data so that we can make
    // sure that the join worked and we actually get all the values back
    weatherValues.putAll(testValues);

    // Get the joined Weather and Location data
    weatherCursor = mContext.getContentResolver().query(
            WeatherEntry.buildWeatherLocation(TestUtilities.TEST_LOCATION),
            null, // leaving "columns" null just returns all the columns.
            null, // cols for "where" clause
            null, // values for "where" clause
            null  // sort order
    );
    TestUtilities.validateCursor("testInsertReadProvider.  Error validating joined Weather and Location Data.",
            weatherCursor, weatherValues);

    // Get the joined Weather and Location data with a start date
    weatherCursor = mContext.getContentResolver().query(
            WeatherEntry.buildWeatherLocationWithStartDate(
                    TestUtilities.TEST_LOCATION, TestUtilities.TEST_DATE),
            null, // leaving "columns" null just returns all the columns.
            null, // cols for "where" clause
            null, // values for "where" clause
            null  // sort order
    );
    TestUtilities.validateCursor("testInsertReadProvider.  Error validating joined Weather and Location Data with start date.",
            weatherCursor, weatherValues);

    // Get the joined Weather data for a specific date
    weatherCursor = mContext.getContentResolver().query(
            WeatherEntry.buildWeatherLocationWithDate(TestUtilities.TEST_LOCATION, TestUtilities.TEST_DATE),
            null,
            null,
            null,
            null
    );
    TestUtilities.validateCursor("testInsertReadProvider.  Error validating joined Weather and Location data for a specific date.",
            weatherCursor, weatherValues);
}
 
Example 14
Source File: ClubStats.java    From android with Apache License 2.0 4 votes vote down vote up
@Override
public void toContentValues(ContentValues values, String columnName, ClubStats value) {
  if (value != null) {
    values.putAll(value.toContentValues());
  }
}
 
Example 15
Source File: AppProviderTest.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
public static App insertApp(ShadowContentResolver contentResolver, Context context, String id, String name, ContentValues additionalValues, long repoId) {

        ContentValues values = new ContentValues();
        values.put(Cols.Package.PACKAGE_NAME, id);
        values.put(Cols.REPO_ID, repoId);
        values.put(Cols.NAME, name);

        // Required fields (NOT NULL in the database).
        values.put(Cols.SUMMARY, "test summary");
        values.put(Cols.DESCRIPTION, "test description");
        values.put(Cols.LICENSE, "GPL?");
        values.put(Cols.IS_COMPATIBLE, 1);

        values.put(Cols.PREFERRED_SIGNER, "eaa1d713b9c2a0475234a86d6539f910");

        values.putAll(additionalValues);

        Uri uri = AppProvider.getContentUri();

        contentResolver.insert(uri, values);

        AppProvider.Helper.recalculatePreferredMetadata(context);

        return AppProvider.Helper.findSpecificApp(context.getContentResolver(), id, repoId, Cols.ALL);
    }