1d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/* 2d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Copyright (C) 2008 Esmertec AG. 3d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Copyright (C) 2008 The Android Open Source Project 4d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 5d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Licensed under the Apache License, Version 2.0 (the "License"); 6d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * you may not use this file except in compliance with the License. 7d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * You may obtain a copy of the License at 8d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 9d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * http://www.apache.org/licenses/LICENSE-2.0 10d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 11d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Unless required by applicable law or agreed to in writing, software 12d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * distributed under the License is distributed on an "AS IS" BASIS, 13d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * See the License for the specific language governing permissions and 15d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * limitations under the License. 16d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 17d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 18d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpackage com.android.messaging.mmslib; 19d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 20d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.ContentResolver; 21d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.ContentValues; 22d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.Context; 23d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.database.Cursor; 24d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.database.sqlite.SQLiteException; 25d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.net.Uri; 26d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 27d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.LogUtil; 28d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 29d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd// Wrapper around content resolver methods to catch exceptions 30d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpublic final class SqliteWrapper { 31d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private static final String TAG = LogUtil.BUGLE_TAG; 32d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 33d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private SqliteWrapper() { 34d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // Forbidden being instantiated. 35d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 36d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 37d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static Cursor query(Context context, ContentResolver resolver, Uri uri, 38d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd String[] projection, String selection, String[] selectionArgs, String sortOrder) { 39d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd try { 40d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return resolver.query(uri, projection, selection, selectionArgs, sortOrder); 41d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } catch (SQLiteException e) { 42d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd LogUtil.e(TAG, "SqliteWrapper: catch an exception when query", e); 43d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return null; 44d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } catch (IllegalArgumentException e) { 45d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd LogUtil.e(TAG, "SqliteWrapper: catch an exception when query", e); 46d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return null; 47d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 48d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 49d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 50d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static int update(Context context, ContentResolver resolver, Uri uri, 51d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ContentValues values, String where, String[] selectionArgs) { 52d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd try { 53d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return resolver.update(uri, values, where, selectionArgs); 54d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } catch (SQLiteException e) { 55d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd LogUtil.e(TAG, "SqliteWrapper: catch an exception when update", e); 56d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return -1; 57d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } catch (IllegalArgumentException e) { 58d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd LogUtil.e(TAG, "SqliteWrapper: catch an exception when update", e); 59d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return -1; 60d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 61d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 62d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 63d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static int delete(Context context, ContentResolver resolver, Uri uri, 64d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd String where, String[] selectionArgs) { 65d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd try { 66d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return resolver.delete(uri, where, selectionArgs); 67d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } catch (SQLiteException e) { 68d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd LogUtil.e(TAG, "SqliteWrapper: catch an exception when delete", e); 69d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return -1; 70d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } catch (IllegalArgumentException e) { 71d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd LogUtil.e(TAG, "SqliteWrapper: catch an exception when delete", e); 72d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return -1; 73d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 74d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 75d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 76d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static Uri insert(Context context, ContentResolver resolver, 77d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd Uri uri, ContentValues values) { 78d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd try { 79d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return resolver.insert(uri, values); 80d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } catch (SQLiteException e) { 81d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd LogUtil.e(TAG, "SqliteWrapper: catch an exception when insert", e); 82d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return null; 83d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } catch (IllegalArgumentException e) { 84d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd LogUtil.e(TAG, "SqliteWrapper: catch an exception when insert", e); 85d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return null; 86d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 87d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 88d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd} 89