Android Open Source - EvokeFramework Database Helper






From Project

Back to project page EvokeFramework.

License

The source code is released under:

Apache License

If you think the Android project EvokeFramework 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 org.fs.net.evoke.database;
/*from  w ww .j a  v  a 2s.c o  m*/
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import org.fs.net.evoke.data.Error;
import org.fs.net.evoke.data.Download;

import java.util.List;

/**
 * Created by Fatih on 30/01/15.
 * as org.fs.net.evoke.database.DatabaseHelper
 */
public class DatabaseHelper extends SQLiteOpenHelper {
    
    private final static String DATABASE_NAME       = "evoke";
    private final static int    DATABASE_VERSION    = 1;    
    
    private static DatabaseHelper instance          = null;   
    
    private DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    
    public static DatabaseHelper getInstance(Context context) {
        if(instance == null) {
            if(context == null) {
                throw new IllegalArgumentException("Context object instance is null");
            }
            instance = new DatabaseHelper(context);
        }
        return instance;
    }
    
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(Download.createSQL());
        db.execSQL(Error.createSQL());
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(Download.dropSQL());
        db.execSQL(Error.dropSQL());
        onCreate(db);
    }
    
    public long addDownload(Download download) {
        SQLiteDatabase db = getWritableDatabase();
        return db.insert(Download.TABLE_DOWNLOAD, null, download.toContentValue());
    }
    
    public List<Download> getDownloads() {
        SQLiteDatabase db = getReadableDatabase();
        Cursor cursor = db.query(Download.TABLE_DOWNLOAD, null, null, null, null, null, null);
        return Download.fromCursor(cursor);
    }
    
    public long addError(Error error) {
        SQLiteDatabase db = getWritableDatabase();
        return db.insert(Error.TABLE_NAME, null, error.toContentValue());
    }
    
    public List<Error> getErrors(int downloadId) {
        SQLiteDatabase db = getReadableDatabase();
        Cursor cursor = db.query(Error.TABLE_NAME, null, Error.COLUMN_DOWNLOAD_ID + "=?", new String[] { String.valueOf(downloadId) }, null, null, null);
        return Error.fromCursor(cursor);
    }
}




Java Source Code List

org.fs.net.ApplicationTest.java
org.fs.net.MainActivity.java
org.fs.net.evoke.ApplicationTest.java
org.fs.net.evoke.DownloadManager.java
org.fs.net.evoke.core.AbstractObject.java
org.fs.net.evoke.data.Download.java
org.fs.net.evoke.data.Error.java
org.fs.net.evoke.data.HeadObject.java
org.fs.net.evoke.data.PartObject.java
org.fs.net.evoke.data.RequestObject.java
org.fs.net.evoke.database.DatabaseHelper.java
org.fs.net.evoke.listener.HeadCallback.java
org.fs.net.evoke.listener.PartCallback.java
org.fs.net.evoke.request.HeadRequest.java
org.fs.net.evoke.request.PartRequest.java
org.fs.net.evoke.th.AbstractRunnable.java
org.fs.net.evoke.util.JsonUtility.java
org.fs.net.evoke.util.LogUtil.java
org.fs.net.evoke.util.RequestUtility.java
org.fs.net.evoke.util.StringUtility.java
org.fs.net.evoke.util.Util.java