Android Open Source - game_guess_lib Guess Game B D D Handler

From Project

Back to project page game_guess_lib.


The source code is released under:

MIT License

If you think the Android project game_guess_lib 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

//from  w w w  . j a  v  a  2s .  co  m
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

import com.wkmf.guess.lib.common.api.GuessApi;
import com.wkmf.guess.lib.structure.GuessGame;
import com.wkmf.lib.bdd.E_BDDHandler;

 * Created by ernestofndz on 9/02/14.
public class GuessGameBDDHandler extends E_BDDHandler {

    public static final String tableName = "BDDGG"; // tabla
    private GuessSQL sql;

    // constructor
    public GuessGameBDDHandler(Context context, String bddName) {
        super(context, bddName);

    public void initialize() {
        // abrimos la base de datos en modo escritura
        this.sql = new GuessSQL(getContext(), getBddName(), null, 1);

    // intentamos recuperar los datos de bdd, concretamente el json
    public GuessGame getGuessGame() {
        GuessGame guessGame = null;
        // sql
        String query = "SELECT * FROM " + tableName;
        // hacemos la consulta
        Cursor c = this.getBdd().select(sql.getReadableDatabase(), query);
        try {
            if (c.moveToFirst()) {
                // recuperamos el json y lo convertimos en objeto
                guessGame = GuessApi.fromJsonGuessGame(c.getString(1));
        } finally {
            // cerramos la conex
        // devolvemos el objeto
        return guessGame;

    // guardamos el objeto
    public void insert(GuessGame guessGame) {
        this.getBdd().insert(this.sql.getWritableDatabase(), tableName, getContentValues(guessGame));

    // modificamos el objeto
    public void update(GuessGame guessGame) {
        this.getBdd().update(this.sql.getWritableDatabase(), tableName, getContentValues(guessGame), "ID=".concat(guessGame.getAppId()));

    // borramos el objeto
    public void delete(GuessGame guessGame) {
        this.getBdd().delete(this.sql.getWritableDatabase(), tableName, "ID=".concat(guessGame.getAppId()));

    // obtenemos el content values
    private ContentValues getContentValues(GuessGame guessGame) {
        ContentValues values = new ContentValues();
        values.put("ID", guessGame.getAppId());
        values.put("VALUE", GuessApi.toJsonGuessGame(guessGame));
        return values;

Java Source Code List