Android Open Source - spiderreddit R S S D B Helper






From Project

Back to project page spiderreddit.

License

The source code is released under:

MIT License

If you think the Android project spiderreddit 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.davepayne.blogcrawler.db;
// w w w  .jav  a 2 s  . c  om
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.davepayne.blogcrawler.R;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.RuntimeExceptionDao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;

import java.sql.SQLException;

/**
 * Database helper class used to manage the creation and upgrading of your database. This class also usually provides
 * the DAOs used by the other classes.
 */
public class RSSDBHelper extends OrmLiteSqliteOpenHelper {

    private static final String DATABASE_NAME = "blogcrawler.db";
    private static final int DATABASE_VERSION = 1; // Here in case you go through DB transitions.

    // the DAO object we use to access the RSSDBData table
    private Dao<RSSDBData, Integer> simpleDao = null;
    private RuntimeExceptionDao<RSSDBData, Integer> simpleRuntimeDao = null;

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

    /**
     * This is called when the database is first created. Usually you should call createTable statements here to create
     * the tables that will store your data.
     */
    @Override
    public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
        try {
            Log.i(RSSDBHelper.class.getName(), "onCreate");
            TableUtils.createTable(connectionSource, RSSDBData.class);
        } catch (SQLException e) {
            Log.e(RSSDBHelper.class.getName(), "Can't create database", e);
            throw new RuntimeException(e);
        }
    }

    /**
     * This is called when your application is upgraded and it has a higher version number. This allows you to adjust
     * the various data to match the new version number.
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
        try {
            Log.i(RSSDBHelper.class.getName(), "onUpgrade");
            TableUtils.dropTable(connectionSource, RSSDBData.class, true);
            // after we drop the old databases, we create the new ones
            onCreate(db, connectionSource);
        } catch (SQLException e) {
            Log.e(RSSDBHelper.class.getName(), "Can't drop databases", e);
            throw new RuntimeException(e);
        }
    }

    /**
     * Returns the Database Access Object (DAO) for our RSSDBData class. It will create it or just give the cached
     * value.
     */
    public Dao<RSSDBData, Integer> getDao() throws SQLException {
        if (simpleDao == null) {
            simpleDao = getDao(RSSDBData.class);
        }
        return simpleDao;
    }

    /**
     * Returns the RuntimeExceptionDao (Database Access Object) version of a Dao for our RSSDBData class. It will
     * create it or just give the cached value. RuntimeExceptionDao only through RuntimeExceptions.
     */
    public RuntimeExceptionDao<RSSDBData, Integer> getRSSDBDataDao() {
        if (simpleRuntimeDao == null) {
            simpleRuntimeDao = getRuntimeExceptionDao(RSSDBData.class);
        }
        return simpleRuntimeDao;
    }

    /**
     * Close the database connections and clear any cached DAOs.
     */
    @Override
    public void close() {
        super.close();
        simpleDao = null;
        simpleRuntimeDao = null;
    }
}




Java Source Code List

com.davepayne.blogcrawler.EntryDialog.java
com.davepayne.blogcrawler.activity.ItemDetailActivity.java
com.davepayne.blogcrawler.activity.ItemListActivity.java
com.davepayne.blogcrawler.db.RSSDBConfigUtil.java
com.davepayne.blogcrawler.db.RSSDBData.java
com.davepayne.blogcrawler.db.RSSDBHelper.java
com.davepayne.blogcrawler.db.RSSDBManager.java
com.davepayne.blogcrawler.fragment.ItemDetailFragment.java
com.davepayne.blogcrawler.fragment.ItemListFragment.java
com.davepayne.blogcrawler.model.ItemListAdapter.java
com.davepayne.blogcrawler.util.GfxUtil.java