Android Open Source - whoisit-android Database Helper






From Project

Back to project page whoisit-android.

License

The source code is released under:

MIT License

If you think the Android project whoisit-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.mitchbarry.android.whoisit.db;
/*from   w  ww  . j av  a  2 s . c  o  m*/
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import com.mitchbarry.android.whoisit.core.PhoneGroup;
import com.mitchbarry.android.whoisit.core.PhoneMatch;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Mitchell on 12/13/13.
 */
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {

    private final String TAG = this.getClass().getSimpleName();
    public static final String DATABASE_NAME = "WhoIsIt.sqlite";
    private static final int DATABASE_VERSION = 2;

    private Dao<PhoneGroup, Integer> phoneGroupDao = null;
    private Dao<PhoneMatch, Integer> phoneMatchDao = null;

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource) {
        try {
            TableUtils.createTable(connectionSource, PhoneMatch.class);
            TableUtils.createTable(connectionSource, PhoneGroup.class);
        } catch (SQLException sqle) {
            Log.e(TAG, "Can't create database", sqle);
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource, int oldVersion, int newVersion) {
        List<String> sqlStatements = new ArrayList<String>();
        if (oldVersion < 1 && newVersion >= 1) {
            // initial database
        }

        if (oldVersion < 2 && newVersion >= 2) {
            // added ringSms column
            sqlStatements.add("ALTER TABLE `phoneGroups` ADD COLUMN ringSms BOOLEAN DEFAULT 0;");
        }

        try {
            for (String sql : sqlStatements) {
                sqLiteDatabase.execSQL(sql);
            }
        } catch (android.database.SQLException sqle) {
            Log.e(TAG, "Failure during onUpgrade", sqle);
        }
    }

    public Dao<PhoneMatch, Integer> getPhoneMatchDao() {
        if (phoneMatchDao == null) {
            try {
                phoneMatchDao = getDao(PhoneMatch.class);
            } catch (SQLException sqle) {
                Log.e(TAG, "Error generating PhoneMatch DAO", sqle);
            }
        }
        return phoneMatchDao;
    }
    public Dao<PhoneGroup, Integer> getPhoneGroupDao() {
        if (phoneGroupDao == null) {
            try {
                phoneGroupDao = getDao(PhoneGroup.class);
            } catch (SQLException sqle) {
                Log.e(TAG, "Error generating PhoneGroup DAO", sqle);
            }
        }
        return phoneGroupDao;
    }
}




Java Source Code List

com.mitchbarry.android.whoisit.AndroidModule.java
com.mitchbarry.android.whoisit.Injector.java
com.mitchbarry.android.whoisit.RootModule.java
com.mitchbarry.android.whoisit.WhoIsItApplication.java
com.mitchbarry.android.whoisit.WhoIsItModule.java
com.mitchbarry.android.whoisit.core.Constants.java
com.mitchbarry.android.whoisit.core.PhoneCallListener.java
com.mitchbarry.android.whoisit.core.PhoneCallReceiver.java
com.mitchbarry.android.whoisit.core.PhoneGroup.java
com.mitchbarry.android.whoisit.core.PhoneMatch.java
com.mitchbarry.android.whoisit.core.SMSReceiver.java
com.mitchbarry.android.whoisit.core.WhoIsItMatcher.java
com.mitchbarry.android.whoisit.db.DatabaseHelper.java
com.mitchbarry.android.whoisit.db.DatabaseManager.java
com.mitchbarry.android.whoisit.ui.AboutActivity.java
com.mitchbarry.android.whoisit.ui.AsyncLoader.java
com.mitchbarry.android.whoisit.ui.BootstrapActivity.java
com.mitchbarry.android.whoisit.ui.BootstrapFragmentActivity.java
com.mitchbarry.android.whoisit.ui.BootstrapPagerAdapter.java
com.mitchbarry.android.whoisit.ui.CarouselActivity.java
com.mitchbarry.android.whoisit.ui.HeaderFooterListAdapter.java
com.mitchbarry.android.whoisit.ui.ItemListFragment.java
com.mitchbarry.android.whoisit.ui.PhoneGroupActivity.java
com.mitchbarry.android.whoisit.ui.PhoneGroupListAdapter.java
com.mitchbarry.android.whoisit.ui.PhoneGroupListFragment.java
com.mitchbarry.android.whoisit.ui.PhoneMatchListAdapter.java
com.mitchbarry.android.whoisit.ui.PhoneMatchListFragment.java
com.mitchbarry.android.whoisit.ui.ThrowableLoader.java
com.mitchbarry.android.whoisit.ui.view.CapitalizedTextView.java
com.mitchbarry.android.whoisit.util.Ln.java
com.mitchbarry.android.whoisit.util.SafeAsyncTask.java
com.mitchbarry.android.whoisit.util.Strings.java