Back to project page forklift.
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.
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); } } }