Bug 1428434: Using Framework methods instead of DBUtils for concatenateWhere/appendSelectionArgs r=JanH

MozReview-Commit-ID: JF3Wsx9IYfs

--HG--
extra : rebase_source : 9826b6b17f09fdb303bd9d17f044c73ab80b95d6
This commit is contained in:
Constantine Filin 2018-05-01 18:00:15 -07:00
Родитель 666cfd2969
Коммит ce614f2cb3
6 изменённых файлов: 72 добавлений и 101 удалений

Просмотреть файл

@ -580,8 +580,8 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
case BOOKMARKS_ID:
trace("Delete on BOOKMARKS_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, TABLE_BOOKMARKS + "._id = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, TABLE_BOOKMARKS + "._id = ?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case BOOKMARKS: {
@ -595,8 +595,8 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
case HISTORY_ID:
trace("Delete on HISTORY_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, TABLE_HISTORY + "._id = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, TABLE_HISTORY + "._id = ?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case HISTORY: {
@ -645,8 +645,8 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
case FAVICON_ID:
debug("Delete on FAVICON_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, TABLE_FAVICONS + "._id = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, TABLE_FAVICONS + "._id = ?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case FAVICONS: {
@ -659,8 +659,8 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
case THUMBNAIL_ID:
debug("Delete on THUMBNAIL_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, TABLE_THUMBNAILS + "._id = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, TABLE_THUMBNAILS + "._id = ?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case THUMBNAILS: {
@ -683,8 +683,8 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
case REMOTE_DEVICES_ID:
debug("Delete on REMOTE_DEVICES_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, TABLE_REMOTE_DEVICES + "._ID = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, TABLE_REMOTE_DEVICES + "._ID = ?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case REMOTE_DEVICES: {
@ -843,8 +843,8 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
case BOOKMARKS_ID:
debug("Update on BOOKMARKS_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, TABLE_BOOKMARKS + "._id = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, TABLE_BOOKMARKS + "._id = ?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case BOOKMARKS: {
@ -860,8 +860,8 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
case HISTORY_ID:
debug("Update on HISTORY_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, TABLE_HISTORY + "._id = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, TABLE_HISTORY + "._id = ?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case HISTORY: {
@ -1065,12 +1065,12 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
" ? AS " + Bookmarks.URL + "," +
" ? AS " + Bookmarks.TITLE);
suggestedSiteArgs = DBUtils.appendSelectionArgs(suggestedSiteArgs,
new String[] {
suggestedSitesCursor.getString(idColumnIndex),
suggestedSitesCursor.getString(urlColumnIndex),
suggestedSitesCursor.getString(titleColumnIndex)
});
suggestedSiteArgs = DatabaseUtils.appendSelectionArgs(suggestedSiteArgs,
new String[] {
suggestedSitesCursor.getString(idColumnIndex),
suggestedSitesCursor.getString(urlColumnIndex),
suggestedSitesCursor.getString(titleColumnIndex)
});
}
suggestedSitesCursor.close();
@ -1288,17 +1288,17 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
debug("Query is on bookmarks: " + uri);
if (match == BOOKMARKS_ID) {
selection = DBUtils.concatenateWhere(selection, Bookmarks._ID + " = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, Bookmarks._ID + " = ?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
} else if (match == BOOKMARKS_FOLDER_ID) {
selection = DBUtils.concatenateWhere(selection, Bookmarks.PARENT + " = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, Bookmarks.PARENT + " = ?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
}
if (!shouldShowDeleted(uri))
selection = DBUtils.concatenateWhere(Bookmarks.IS_DELETED + " = 0", selection);
selection = DatabaseUtils.concatenateWhere(Bookmarks.IS_DELETED + " = 0", selection);
if (TextUtils.isEmpty(sortOrder)) {
sortOrder = DEFAULT_BOOKMARKS_SORT_ORDER;
@ -1322,15 +1322,15 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
}
case HISTORY_ID:
selection = DBUtils.concatenateWhere(selection, History._ID + " = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, History._ID + " = ?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case HISTORY: {
debug("Query is on history: " + uri);
if (!shouldShowDeleted(uri))
selection = DBUtils.concatenateWhere(History.IS_DELETED + " = 0", selection);
selection = DatabaseUtils.concatenateWhere(History.IS_DELETED + " = 0", selection);
if (TextUtils.isEmpty(sortOrder))
sortOrder = DEFAULT_HISTORY_SORT_ORDER;
@ -1356,8 +1356,8 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
break;
case FAVICON_ID:
selection = DBUtils.concatenateWhere(selection, Favicons._ID + " = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, Favicons._ID + " = ?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case FAVICONS: {
@ -1370,8 +1370,8 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
}
case THUMBNAIL_ID:
selection = DBUtils.concatenateWhere(selection, Thumbnails._ID + " = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, Thumbnails._ID + " = ?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case THUMBNAILS: {
@ -1431,8 +1431,8 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
}
case REMOTE_DEVICES_ID:
selection = DBUtils.concatenateWhere(selection, RemoteDevices._ID + " = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, RemoteDevices._ID + " = ?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case REMOTE_DEVICES: {

Просмотреть файл

@ -33,38 +33,6 @@ public class DBUtils {
return table + "." + column;
}
// This is available in Android >= 11. Implemented locally to be
// compatible with older versions.
public static String concatenateWhere(String a, String b) {
if (TextUtils.isEmpty(a)) {
return b;
}
if (TextUtils.isEmpty(b)) {
return a;
}
return "(" + a + ") AND (" + b + ")";
}
// This is available in Android >= 11. Implemented locally to be
// compatible with older versions.
public static String[] appendSelectionArgs(String[] originalValues, String[] newValues) {
if (originalValues == null || originalValues.length == 0) {
return newValues;
}
if (newValues == null || newValues.length == 0) {
return originalValues;
}
String[] result = new String[originalValues.length + newValues.length];
System.arraycopy(originalValues, 0, result, 0, originalValues.length);
System.arraycopy(newValues, 0, result, originalValues.length, newValues.length);
return result;
}
/**
* Concatenate multiple lists of selection arguments. <code>values</code> may be <code>null</code>.
*/

Просмотреть файл

@ -19,6 +19,7 @@ import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.MatrixCursor;
import android.net.Uri;
import android.util.Log;
@ -81,9 +82,9 @@ public class HomeProvider extends SQLiteBridgeContentProvider {
throw new IllegalArgumentException("All queries should contain a dataset ID parameter");
}
selection = DBUtils.concatenateWhere(selection, HomeItems.DATASET_ID + " = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
new String[] { datasetId });
selection = DatabaseUtils.concatenateWhere(selection, HomeItems.DATASET_ID + " = ?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { datasetId });
// Otherwise, let the SQLiteContentProvider implementation take care of this query for us!
Cursor c = super.query(uri, projection, selection, selectionArgs, sortOrder);

Просмотреть файл

@ -53,6 +53,7 @@ import android.content.ContentValues;
import android.content.Context;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.MatrixCursor;
import android.database.MergeCursor;
import android.graphics.Bitmap;
@ -662,17 +663,17 @@ public class LocalBrowserDB extends BrowserDB {
// Only create a filter query with a maximum of 10 constraint words.
final int constraintCount = Math.min(constraintWords.length, 10);
for (int i = 0; i < constraintCount; i++) {
selection = DBUtils.concatenateWhere(selection, "(" + Combined.URL + " LIKE ? OR " +
Combined.TITLE + " LIKE ?)");
selection = DatabaseUtils.concatenateWhere(selection, "(" + Combined.URL + " LIKE ? OR " +
Combined.TITLE + " LIKE ?)");
String constraintWord = "%" + constraintWords[i] + "%";
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
new String[] { constraintWord, constraintWord });
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { constraintWord, constraintWord });
}
}
if (urlFilter != null) {
selection = DBUtils.concatenateWhere(selection, "(" + Combined.URL + " NOT LIKE ?)");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs, new String[] { urlFilter.toString() });
selection = DatabaseUtils.concatenateWhere(selection, "(" + Combined.URL + " NOT LIKE ?)");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs, new String[] { urlFilter.toString() });
}
// Order by combined remote+local frecency score.

Просмотреть файл

@ -158,8 +158,8 @@ public class LoginsProvider extends SharedBrowserDatabaseProvider {
switch (match) {
case LOGINS_ID:
trace("Delete on LOGINS_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, selectColumn(TABLE_LOGINS, Logins._ID));
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, selectColumn(TABLE_LOGINS, Logins._ID));
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[]{Long.toString(ContentUris.parseId(uri))});
// Store the deleted client in deleted-logins table.
final String guid = getLoginGUIDByID(selection, selectionArgs, db);
@ -180,8 +180,8 @@ public class LoginsProvider extends SharedBrowserDatabaseProvider {
case DELETED_LOGINS_ID:
trace("Delete on DELETED_LOGINS_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, selectColumn(TABLE_DELETED_LOGINS, DeletedLogins._ID));
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, selectColumn(TABLE_DELETED_LOGINS, DeletedLogins._ID));
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[]{Long.toString(ContentUris.parseId(uri))});
// fall through
case DELETED_LOGINS:
@ -191,8 +191,8 @@ public class LoginsProvider extends SharedBrowserDatabaseProvider {
case DISABLED_HOSTS_HOSTNAME:
trace("Delete on DISABLED_HOSTS_HOSTNAME: " + uri);
selection = DBUtils.concatenateWhere(selection, selectColumn(TABLE_DISABLED_HOSTS, LoginsDisabledHosts.HOSTNAME));
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, selectColumn(TABLE_DISABLED_HOSTS, LoginsDisabledHosts.HOSTNAME));
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[]{uri.getLastPathSegment()});
// fall through
case DISABLED_HOSTS:
@ -221,8 +221,8 @@ public class LoginsProvider extends SharedBrowserDatabaseProvider {
switch (match) {
case LOGINS_ID:
trace("Update on LOGINS_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, selectColumn(TABLE_LOGINS, Logins._ID));
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, selectColumn(TABLE_LOGINS, Logins._ID));
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[]{Long.toString(ContentUris.parseId(uri))});
case LOGINS:
@ -255,8 +255,8 @@ public class LoginsProvider extends SharedBrowserDatabaseProvider {
switch (match) {
case LOGINS_ID:
trace("Query is on LOGINS_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, selectColumn(TABLE_LOGINS, Logins._ID));
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, selectColumn(TABLE_LOGINS, Logins._ID));
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
@ -274,8 +274,8 @@ public class LoginsProvider extends SharedBrowserDatabaseProvider {
case DELETED_LOGINS_ID:
trace("Query is on DELETED_LOGINS_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, selectColumn(TABLE_DELETED_LOGINS, DeletedLogins._ID));
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, selectColumn(TABLE_DELETED_LOGINS, DeletedLogins._ID));
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
@ -293,8 +293,8 @@ public class LoginsProvider extends SharedBrowserDatabaseProvider {
case DISABLED_HOSTS_HOSTNAME:
trace("Query is on DISABLED_HOSTS_HOSTNAME: " + uri);
selection = DBUtils.concatenateWhere(selection, selectColumn(TABLE_DISABLED_HOSTS, LoginsDisabledHosts.HOSTNAME));
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, selectColumn(TABLE_DISABLED_HOSTS, LoginsDisabledHosts.HOSTNAME));
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { uri.getLastPathSegment() });
// fall through

Просмотреть файл

@ -15,6 +15,7 @@ import android.content.ContentUris;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
@ -161,8 +162,8 @@ public class TabsProvider extends SharedBrowserDatabaseProvider {
switch (match) {
case CLIENTS_ID:
trace("Delete on CLIENTS_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, selectColumn(TABLE_CLIENTS, Clients._ID));
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, selectColumn(TABLE_CLIENTS, Clients._ID));
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case CLIENTS:
@ -172,8 +173,8 @@ public class TabsProvider extends SharedBrowserDatabaseProvider {
case TABS_ID:
trace("Delete on TABS_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, selectColumn(TABLE_TABS, Tabs._ID));
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, selectColumn(TABLE_TABS, Tabs._ID));
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case TABS:
@ -234,8 +235,8 @@ public class TabsProvider extends SharedBrowserDatabaseProvider {
switch (match) {
case CLIENTS_ID:
trace("Update on CLIENTS_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, selectColumn(TABLE_CLIENTS, Clients._ID));
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, selectColumn(TABLE_CLIENTS, Clients._ID));
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case CLIENTS:
@ -245,8 +246,8 @@ public class TabsProvider extends SharedBrowserDatabaseProvider {
case TABS_ID:
trace("Update on TABS_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, selectColumn(TABLE_TABS, Tabs._ID));
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, selectColumn(TABLE_TABS, Tabs._ID));
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case TABS:
@ -277,8 +278,8 @@ public class TabsProvider extends SharedBrowserDatabaseProvider {
switch (match) {
case TABS_ID:
trace("Query is on TABS_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, selectColumn(TABLE_TABS, Tabs._ID));
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, selectColumn(TABLE_TABS, Tabs._ID));
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case TABS:
@ -298,8 +299,8 @@ public class TabsProvider extends SharedBrowserDatabaseProvider {
case CLIENTS_ID:
trace("Query is on CLIENTS_ID: " + uri);
selection = DBUtils.concatenateWhere(selection, selectColumn(TABLE_CLIENTS, Clients._ID));
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
selection = DatabaseUtils.concatenateWhere(selection, selectColumn(TABLE_CLIENTS, Clients._ID));
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
new String[] { Long.toString(ContentUris.parseId(uri)) });
// fall through
case CLIENTS: