diff options
author | Fred Quintana <fredq@google.com> | 2009-09-15 18:17:07 -0700 |
---|---|---|
committer | Fred Quintana <fredq@google.com> | 2009-09-15 18:57:17 -0700 |
commit | 5ab78057a35dc71b2847920031cd707a7e2c6c64 (patch) | |
tree | 1515d05f53d391db2b05b5ff3004172b19c88351 /core/java/android/content/ContentProviderOperation.java | |
parent | 7c3e493d7b2db7f28d6fdb52d79c4d99ef1502b8 (diff) | |
download | frameworks_base-5ab78057a35dc71b2847920031cd707a7e2c6c64.zip frameworks_base-5ab78057a35dc71b2847920031cd707a7e2c6c64.tar.gz frameworks_base-5ab78057a35dc71b2847920031cd707a7e2c6c64.tar.bz2 |
add the ability to do a newAssert with no values
Diffstat (limited to 'core/java/android/content/ContentProviderOperation.java')
-rw-r--r-- | core/java/android/content/ContentProviderOperation.java | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/core/java/android/content/ContentProviderOperation.java b/core/java/android/content/ContentProviderOperation.java index 238792b..60b406d 100644 --- a/core/java/android/content/ContentProviderOperation.java +++ b/core/java/android/content/ContentProviderOperation.java @@ -221,26 +221,30 @@ public class ContentProviderOperation implements Parcelable { } else if (mType == TYPE_UPDATE) { numRows = provider.update(mUri, values, mSelection, selectionArgs); } else if (mType == TYPE_ASSERT) { - // Build projection map from expected values - final ArrayList<String> projectionList = new ArrayList<String>(); - for (Map.Entry<String, Object> entry : values.valueSet()) { - projectionList.add(entry.getKey()); - } - // Assert that all rows match expected values - final String[] projection = projectionList.toArray(new String[projectionList.size()]); + String[] projection = null; + if (values != null) { + // Build projection map from expected values + final ArrayList<String> projectionList = new ArrayList<String>(); + for (Map.Entry<String, Object> entry : values.valueSet()) { + projectionList.add(entry.getKey()); + } + projection = projectionList.toArray(new String[projectionList.size()]); + } final Cursor cursor = provider.query(mUri, projection, mSelection, selectionArgs, null); - numRows = cursor.getCount(); try { - while (cursor.moveToNext()) { - for (int i = 0; i < projection.length; i++) { - final String cursorValue = cursor.getString(i); - final String expectedValue = values.getAsString(projection[i]); - if (!TextUtils.equals(cursorValue, expectedValue)) { - // Throw exception when expected values don't match - throw new OperationApplicationException("Found value " + cursorValue - + " when expected " + expectedValue + " for column " - + projection[i]); + numRows = cursor.getCount(); + if (projection != null) { + while (cursor.moveToNext()) { + for (int i = 0; i < projection.length; i++) { + final String cursorValue = cursor.getString(i); + final String expectedValue = values.getAsString(projection[i]); + if (!TextUtils.equals(cursorValue, expectedValue)) { + // Throw exception when expected values don't match + throw new OperationApplicationException("Found value " + cursorValue + + " when expected " + expectedValue + " for column " + + projection[i]); + } } } } @@ -395,12 +399,19 @@ public class ContentProviderOperation implements Parcelable { /** Create a ContentProviderOperation from this {@link Builder}. */ public ContentProviderOperation build() { - if (mType == TYPE_UPDATE || mType == TYPE_ASSERT) { + if (mType == TYPE_UPDATE) { if ((mValues == null || mValues.size() == 0) && (mValuesBackReferences == null || mValuesBackReferences.size() == 0)) { throw new IllegalArgumentException("Empty values"); } } + if (mType == TYPE_ASSERT) { + if ((mValues == null || mValues.size() == 0) + && (mValuesBackReferences == null || mValuesBackReferences.size() == 0) + && (mExpectedCount == null)) { + throw new IllegalArgumentException("Empty values"); + } + } return new ContentProviderOperation(this); } |