diff options
author | Fred Quintana <fredq@google.com> | 2009-06-04 10:28:49 -0700 |
---|---|---|
committer | Fred Quintana <fredq@google.com> | 2009-06-04 12:23:54 -0700 |
commit | d8dfeb5ee82d679f491cd20e776907a69fb4f27c (patch) | |
tree | d9bdc91053e247e2c9c7b8513b8b4ecf5cf4ec4c /core/java/android/content/ContentProviderOperation.java | |
parent | a41d3856fafff0e92cc85586c7d2a414036f85ac (diff) | |
download | frameworks_base-d8dfeb5ee82d679f491cd20e776907a69fb4f27c.zip frameworks_base-d8dfeb5ee82d679f491cd20e776907a69fb4f27c.tar.gz frameworks_base-d8dfeb5ee82d679f491cd20e776907a69fb4f27c.tar.bz2 |
- make it easier to add content values to the ContentProviderOperation
- add the group membership common kind as well as some IM utilities to the ContactsContract
Diffstat (limited to 'core/java/android/content/ContentProviderOperation.java')
-rw-r--r-- | core/java/android/content/ContentProviderOperation.java | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/core/java/android/content/ContentProviderOperation.java b/core/java/android/content/ContentProviderOperation.java index 07be017..001af16 100644 --- a/core/java/android/content/ContentProviderOperation.java +++ b/core/java/android/content/ContentProviderOperation.java @@ -20,6 +20,7 @@ import android.net.Uri; import android.database.Cursor; import android.os.Parcelable; import android.os.Parcel; +import android.os.Debug; import java.util.Map; import java.util.HashMap; @@ -428,7 +429,8 @@ public class ContentProviderOperation implements Parcelable { /** * The ContentValues to use. This may be null. These values may be overwritten by - * the corresponding value specified by {@link #withValueBackReferences(ContentValues)}. + * the corresponding value specified by {@link #withValueBackReference} or by + * future calls to {@link #withValues} or {@link #withValue}. * This can only be used with builders of type insert or update. * @return this builder, to allow for chaining. */ @@ -436,11 +438,56 @@ public class ContentProviderOperation implements Parcelable { if (mType != TYPE_INSERT && mType != TYPE_UPDATE) { throw new IllegalArgumentException("only inserts and updates can have values"); } - mValues = values; + if (mValues == null) { + mValues = new ContentValues(); + } + mValues.putAll(values); return this; } /** + * A value to insert or update. This value may be overwritten by + * the corresponding value specified by {@link #withValueBackReference}. + * This can only be used with builders of type insert or update. + * @param key the name of this value + * @param value the value itself. the type must be acceptable for insertion by + * {@link ContentValues#put} + * @return this builder, to allow for chaining. + */ + public Builder withValue(String key, Object value) { + if (mType != TYPE_INSERT && mType != TYPE_UPDATE) { + throw new IllegalArgumentException("only inserts and updates can have values"); + } + if (mValues == null) { + mValues = new ContentValues(); + } + if (value == null) { + mValues.putNull(key); + } else if (value instanceof String) { + mValues.put(key, (String) value); + } else if (value instanceof Byte) { + mValues.put(key, (Byte) value); + } else if (value instanceof Short) { + mValues.put(key, (Short) value); + } else if (value instanceof Integer) { + mValues.put(key, (Integer) value); + } else if (value instanceof Long) { + mValues.put(key, (Long) value); + } else if (value instanceof Float) { + mValues.put(key, (Float) value); + } else if (value instanceof Double) { + mValues.put(key, (Double) value); + } else if (value instanceof Boolean) { + mValues.put(key, (Boolean) value); + } else if (value instanceof byte[]) { + mValues.put(key, (byte[]) value); + } else { + throw new IllegalArgumentException("bad value type: " + value.getClass().getName()); + } + return this; + } + + /** * The selection and arguments to use. An occurrence of '?' in the selection will be * replaced with the corresponding occurence of the selection argument. Any of the * selection arguments may be overwritten by a selection argument back reference as |