Example usage for android.database.sqlite SQLiteDatabase acquireReference

List of usage examples for android.database.sqlite SQLiteDatabase acquireReference

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase acquireReference.

Prototype

public void acquireReference() 

Source Link

Document

Acquires a reference to the object.

Usage

From source file:org.ttrssreader.controllers.DBHelper.java

@SuppressWarnings("deprecation")
private synchronized boolean initializeDBHelper() {
    final Context context = contextRef.get();
    if (context == null) {
        Log.e(TAG, "Can't handle internal DB without Context-Object.");
        return false;
    }/*w  w  w  .  j  a  v  a  2  s.c  om*/

    if (getOpenHelper() != null)
        closeDB();

    openHelper = new OpenHelper(context);
    SQLiteDatabase db = openHelper.getWritableDatabase();

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
        db.setLockingEnabled(true);

    if (specialUpgradeSuccessful) {
        // Re-open DB for final usage:
        closeDB();
        openHelper = new OpenHelper(context);
        db = openHelper.getWritableDatabase();

        Toast.makeText(context, "ImageCache is beeing cleaned...", Toast.LENGTH_LONG).show();
        new org.ttrssreader.utils.AsyncTask<Void, Void, Void>() {
            protected Void doInBackground(Void... params) {
                // Clear ImageCache since no files are in REMOTE_FILES anymore and we dont want to leave them
                // there forever:
                ImageCache imageCache = Controller.getInstance().getImageCache();
                imageCache.fillMemoryCacheFromDisk();
                File cacheFolder = new File(imageCache.getDiskCacheDirectory());
                if (cacheFolder.isDirectory()) {
                    try {
                        FileUtils.deleteDirectory(cacheFolder);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                return null;
            }

            protected void onPostExecute(Void result) {
                Toast.makeText(context, "ImageCache has been cleaned up...", Toast.LENGTH_LONG).show();
            }
        }.execute();
    }

    insertCategory = db.compileStatement(INSERT_CATEGORY);
    insertFeed = db.compileStatement(INSERT_FEED);
    insertArticle = db.compileStatement(INSERT_ARTICLE);
    insertLabel = db.compileStatement(INSERT_LABEL);
    insertRemoteFile = db.compileStatement(INSERT_REMOTEFILE);
    insertRemoteFile2Article = db.compileStatement(INSERT_REMOTEFILE2ARTICLE);

    db.acquireReference();
    initialized = true;
    return true;
}