Android Open Source - whoisit-android Database Manager






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;
//w w  w .j  a  v  a 2  s  .c om
import android.content.Context;
import android.util.Log;
import com.mitchbarry.android.whoisit.core.PhoneGroup;
import com.mitchbarry.android.whoisit.core.PhoneMatch;

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

/**
 * Created by Mitchell on 12/13/13.
 */
public class DatabaseManager {
    private final String TAG = this.getClass().getSimpleName();

    static private DatabaseManager instance;
    private DatabaseHelper helper;
    private DatabaseManager (Context context) {
        helper = new DatabaseHelper(context);
    }
    static public void init(Context context) {
        if (instance == null) {
            instance = new DatabaseManager(context);
        }
    }
    static public DatabaseManager getInstance() {
        return instance;
    }
    private DatabaseHelper getHelper() {
        return helper;
    }

    public List<PhoneGroup> getPhoneGroups() {
        List<PhoneGroup> phoneGroups = null;
        try {
            phoneGroups = getHelper().getPhoneGroupDao().queryForAll();
        } catch (SQLException sqle) {
            Log.e(TAG, "Failed to get PhoneGroups", sqle);
        }
        return phoneGroups;
    }
    public PhoneGroup getPhoneGroup(int id) {
        PhoneGroup phoneGroup = null;
        try {
            phoneGroup = getHelper().getPhoneGroupDao().queryForId(id);
        } catch (SQLException sqle) {
            Log.e(TAG, "Failed to get PhoneGroup", sqle);
        }
        return phoneGroup;
    }
    public int addPhoneGroup(PhoneGroup group) {
        int id = -1;
        try {
            getHelper().getPhoneGroupDao().create(group);
            id = group.getId();
        } catch (SQLException sqle) {
            Log.e(TAG, "Error when creating PhoneGroup", sqle);
        }
        return id;
    }
    public void updatePhoneGroup(PhoneGroup group) {
        try {
            getHelper().getPhoneGroupDao().update(group);
        } catch (SQLException sqle) {
            Log.e(TAG, "Error when updating PhoneGroup", sqle);
        }
    }
    public void deletePhoneGroup(PhoneGroup group) {
        try {
            getHelper().getPhoneGroupDao().delete(group);
        } catch (SQLException sqle) {
            Log.e(TAG, "Error when deleting PhoneGroup", sqle);
        }
    }

    public List<PhoneMatch> getPhoneMatches() {
        List<PhoneMatch> phoneMatches = null;
        try {
            phoneMatches = getHelper().getPhoneMatchDao().queryForAll();
            if (phoneMatches.size() > 0) {
                for (PhoneMatch match : phoneMatches) {

                }
            }
        } catch (SQLException sqle) {
            Log.e(TAG, "Failed to get PhoneMatches", sqle);
        }
        return phoneMatches;
    }
    public int addPhoneMatch(PhoneMatch match) {
        int id = -1;
        try {
            getHelper().getPhoneMatchDao().create(match);
            id = match.getId();
        } catch (SQLException sqle) {
            Log.e(TAG, "Error when creating PhoneMatch", sqle);
        }
        return id;
    }
    public void updatePhoneMatch(PhoneMatch match) {
        try {
            getHelper().getPhoneMatchDao().update(match);
        } catch (SQLException sqle) {
            Log.e(TAG, "Error when updating PhoneMatch", sqle);
        }
    }
    public void deletePhoneMatch(PhoneMatch match) {
        try {
            getHelper().getPhoneMatchDao().delete(match);
        } catch (SQLException sqle) {
            Log.e(TAG, "Error when deleting PhoneMatch", sqle);
        }
    }
}




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