1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.bordeaux.services;
18
19import android.content.Context;
20import android.database.SQLException;
21import android.database.sqlite.SQLiteDatabase;
22import android.database.sqlite.SQLiteOpenHelper;
23import android.util.Log;
24
25// Base Helper class for aggregator storage database
26class AggregatorStorage {
27    private static final String TAG = "AggregatorStorage";
28    private static final String DATABASE_NAME = "aggregator";
29    private static final int DATABASE_VERSION = 1;
30
31    protected DBHelper mDbHelper;
32    protected SQLiteDatabase mDatabase;
33
34    class DBHelper extends SQLiteOpenHelper {
35        private String mTableCmd;
36        private String mTableName;
37        DBHelper(Context context, String tableName, String tableCmd) {
38            super(context, DATABASE_NAME, null, DATABASE_VERSION);
39            mTableName = tableName;
40            mTableCmd = tableCmd;
41        }
42
43        @Override
44        public void onCreate(SQLiteDatabase db) {
45            db.execSQL(mTableCmd);
46        }
47
48        @Override
49        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
50            Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
51                  + newVersion + ", which will destroy all old data");
52
53            db.execSQL("DROP TABLE IF EXISTS " + mTableName);
54            onCreate(db);
55        }
56    }
57}
58