Android Open Source - RUflow Flow Db Adapter






From Project

Back to project page RUflow.

License

The source code is released under:

GNU General Public License

If you think the Android project RUflow 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 is.ru.app;
//from  w  w  w  . j a  v a  2s  . c o  m
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.sql.Timestamp;

/**
 * Created by rur on 23.9.2014.
 */
public class FlowDbAdapter {

    SQLiteDatabase db;
    DbHelper dbHelper;
    Context context;


    public FlowDbAdapter( Context c ) {
        context = c;
    }

    public FlowDbAdapter openToRead() {
        dbHelper = new DbHelper( context );
        db = dbHelper.getReadableDatabase();
        return this;
    }

    public FlowDbAdapter openToWrite() {
        dbHelper = new DbHelper( context );
        db = dbHelper.getWritableDatabase();
        return this;
    }

    public void close() {
        db.close();
    }

    public long insertFlow( int boardId, Timestamp bestTime, String type, boolean finished ) {
        String[] cols = DbHelper.TableFlowCols;
        ContentValues contentValues = new ContentValues();
        contentValues.put( cols[1], ((Integer)boardId).toString() );
        contentValues.put( cols[2], type);
        contentValues.put( cols[3], String.valueOf(bestTime));
        contentValues.put( cols[4], finished);
        openToWrite();
        long value = db.insert(DbHelper.TableFlow, null, contentValues );
        close();
        return value;
    }

    public long updateFlow( int boardId, Timestamp bestTime, String type, boolean finished ) {
        String[] cols = DbHelper.TableFlowCols;
        ContentValues contentValues = new ContentValues();
        contentValues.put( cols[1], ((Integer)boardId).toString() );
        contentValues.put( cols[2], type);
        contentValues.put( cols[3], String.valueOf(bestTime));
        contentValues.put( cols[4], finished);
        openToWrite();
        long value = db.update(DbHelper.TableFlow,
                contentValues,
                cols[1] + "=" + boardId, null );
        close();
        return value;
    }

    public long updateFlowFinished( int id, String type, double bestTime, boolean finished ) {
        String[] cols = DbHelper.TableFlowCols;
        ContentValues contentValues = new ContentValues();
        contentValues.put( cols[4], finished);
        contentValues.put(cols[3], bestTime);
        openToWrite();
        long value = db.update(DbHelper.TableFlow,
                contentValues,
                "type LIKE '" + type + "' AND boardId = " + id, null );
        close();
        return value;
    }


    public Cursor queryFlows(int id, String type) {
        openToRead();
        Cursor cursor = db.query( DbHelper.TableFlow,
                DbHelper.TableFlowCols, "type LIKE '" + type + "' AND boardId = " + id, null  , null, null, null);
        return cursor;
    }

}




Java Source Code List

is.ru.app.Board.java
is.ru.app.Cellpath.java
is.ru.app.ColorListActivity.java
is.ru.app.Coordinate.java
is.ru.app.DbHelper.java
is.ru.app.FlowDbAdapter.java
is.ru.app.Global.java
is.ru.app.MainActivity.java
is.ru.app.MapPack.java
is.ru.app.Pack.java
is.ru.app.PlayActivity.java
is.ru.app.PuzzleSelectActivity.java
is.ru.app.Puzzle.java
is.ru.app.SelectActivity.java
is.ru.app.SuperPath.java