Android Open Source - allblue-all-in-one Database Helper






From Project

Back to project page allblue-all-in-one.

License

The source code is released under:

MIT License

If you think the Android project allblue-all-in-one 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 org.allblue.database;
// ww w. jav  a2 s .  c  om
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 org.allblue.R;
import org.allblue.metadata.*;

import java.sql.SQLException;

public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
    private static String DATABASE_NAME = "allblue.db";
    private static int DATABASE_VERSION = 1;

    private Dao<Account, Integer> accountDao;
    private Dao<TweetItem, Integer> tweetItemDao;

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION, R.raw.ormlite_conf);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource) {
        try {
            Log.i(DatabaseHelper.class.getName(), "create tables");
            TableUtils.createTable(connectionSource, Account.class);
            TableUtils.createTable(connectionSource, TweetItem.class);
        } catch (SQLException e) {
            throw new RuntimeException("Failed to create tables");
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource, int i, int i2) {
    }

    public Dao<Account, Integer> getAccountDao() throws SQLException {
        if (accountDao == null) {
            synchronized (this) {
                if (accountDao == null) {
                    accountDao = getDao(Account.class);
                }
            }
        }
        return accountDao;
    }

    public Dao<TweetItem, Integer> getTweetItemDao() throws SQLException {
        if (tweetItemDao == null) {
            synchronized (this) {
                if (tweetItemDao == null) {
                    tweetItemDao = getDao(TweetItem.class);
                }
            }
        }
        return tweetItemDao;
    }
}




Java Source Code List

org.allblue.DashBoard.java
org.allblue.activity.GlobalActivity.java
org.allblue.activity.HomeActivity.java
org.allblue.activity.OAuthActivity.java
org.allblue.activity.SettingActivity.java
org.allblue.activity.SingleTabActivity.java
org.allblue.adapter.SettingAdapter.java
org.allblue.adapter.SingleTabCursorAdapter.java
org.allblue.database.DatabaseConfig.java
org.allblue.database.DatabaseHelper.java
org.allblue.metadata.AccountTypes.java
org.allblue.metadata.Account.java
org.allblue.metadata.SinaAccount.java
org.allblue.metadata.TweetItem.java
org.allblue.metadata.TwitterAccount.java
org.allblue.util.OAuthUtil.java
org.allblue.util.SharedOAuthToken.java
org.allblue.util.XMLUtil.java