Example usage for android.database.sqlite SQLiteOpenHelper close

List of usage examples for android.database.sqlite SQLiteOpenHelper close

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteOpenHelper close.

Prototype

public synchronized void close() 

Source Link

Document

Close any open database object.

Usage

From source file:com.hemou.android.core.sync.persistence.DatabaseCache.java

/**
 * Request and store given resources//from w ww.  j  a  v a  2s.com
 * 
 * @param persistableResource
 * @return resources
 * @throws IOException
 */
public <E> List<E> requestAndStore(PersistableResource<E> persistableResource) throws IOException {
    SQLiteOpenHelper helper = helperProvider.get();
    try {
        return requestAndStore(helper, persistableResource);
    } finally {
        helper.close();
    }
}

From source file:com.hemou.android.core.sync.persistence.DatabaseCache.java

public <Key, E> void del(PersistableResource<E> persistableResource, Key... keys) {
    if (keys == null || keys.length == 0)
        return;/*from www . j  a  v  a  2 s  . co  m*/
    SQLiteOpenHelper helper = helperProvider.get();
    final SQLiteDatabase db = getWritable(helper);
    if (db == null)
        return;

    db.beginTransaction();
    try {
        persistableResource.del(db, keys);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        helper.close();
    }
}

From source file:com.hemou.android.core.sync.persistence.DatabaseCache.java

public <E> void add(PersistableResource<E> persistableResource, E... datas) {
    if (datas == null || datas.length == 0)
        return;/*from  w  ww  . j ava 2 s  . co  m*/
    SQLiteOpenHelper helper = helperProvider.get();
    final SQLiteDatabase db = getWritable(helper);
    if (db == null)
        return;

    db.beginTransaction();
    try {
        persistableResource.add(db, datas);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        helper.close();
    }
}

From source file:com.hemou.android.core.sync.persistence.DatabaseCache.java

/**
 * Load or request given resources//from ww w  . j  ava 2s  . c o  m
 * 
 * @param persistableResource
 * @return resource
 * @throws IOException
 */
public <E> List<E> loadOrRequest(PersistableResource<E> persistableResource) throws IOException {
    SQLiteOpenHelper helper = helperProvider.get();
    try {
        List<E> items = loadFromDB(helper, persistableResource);
        if (items != null) {
            Log.d(TAG, "CACHE HIT: Found " + items.size() + " items for " + persistableResource);
            return items;
        }
        return requestAndStore(helper, persistableResource);
    } finally {
        helper.close();
    }
}