Android Open Source - forklift Abstract Resource Sqlite Open Helper






From Project

Back to project page forklift.

License

The source code is released under:

Apache License

If you think the Android project forklift 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 ch.gluecode.forklift;
//w w w  .ja v  a2 s. c  o m
import android.content.Context;
import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabase;

import java.io.InputStream;

/**
 * A helper class that allows access to SQLite databases shipped as raw resource.
 *
 * <p>To access a SQLite database that is shipped as raw resource, implement this class. Overriding the lifecycle
 * callbacks is optional.</p>
 */
public abstract class AbstractResourceSqliteOpenHelper extends AbstractBundledSqliteOpenHelper {

    private final int rawResource;

    /**
     * Creates a new helper instance that allows to access a bundled SQLite database stored in the application's assets
     * directory. The database is not actually
     * opened until {@link ch.gluecode.forklift.AbstractBundledSqliteOpenHelper#getDatabase()} is called.
     *
     * @param context Context to use to access the database.
     * @param rawResource ID of the raw resource (the bundled database).
     * @param databaseName Name of the database in the application directory to access.
     * @param version Version number of the database (>= 1).
     */
    protected AbstractResourceSqliteOpenHelper(Context context, int rawResource, String databaseName, int version) {
        super(context, databaseName, version);
        this.rawResource = rawResource;
    }

    /**
     * Creates a new helper instance that allows to access a bundled SQLite database stored in the application's assets
     * directory. The database is not actually
     * opened until {@link ch.gluecode.forklift.AbstractBundledSqliteOpenHelper#getDatabase()} is called.
     *
     * @param context Context to use to access the database.
     * @param rawResource ID of the raw resource (the bundled database).
     * @param databaseName Name of the database in the application directory to access.
     * @param version Version number of the database (>= 1).
     * @param factory Factory to use for creating cursor objects.
     */
    public AbstractResourceSqliteOpenHelper(Context context, int rawResource, String databaseName,
                                            int version, SQLiteDatabase.CursorFactory factory) {
        super(context, databaseName, version, factory);

        this.rawResource = rawResource;
    }

    @Override
    protected final InputStream getBundledDatabase() {
        try {
            return getContext().getResources().openRawResource(rawResource);
        } catch (Resources.NotFoundException e) {
            throw new BundledSqliteOpenHelperException("Failed to open given raw resource.", e);
        }
    }
}




Java Source Code List

ch.gluecode.forklift.AbstractAssetSqliteOpenHelper.java
ch.gluecode.forklift.AbstractBundledSqliteOpenHelper.java
ch.gluecode.forklift.AbstractResourceSqliteOpenHelper.java
ch.gluecode.forklift.BundledSqliteOpenHelperException.java
com.example.forklift.CantonListFragment.java
com.example.forklift.CantonsAssetSqliteOpenHelper.java
com.example.forklift.MountainCursorAdapter.java
com.example.forklift.MountainListFragment.java
com.example.forklift.MountainsResourceSqliteOpenHelper.java
com.example.forklift.SampleActivity.java