Android Open Source - Gloggr Database Manager






From Project

Back to project page Gloggr.

License

The source code is released under:

GNU General Public License

If you think the Android project Gloggr 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 com.JordHan.Gloggr.db;
/*from  w w w .j a  v  a2  s.  c o  m*/
import android.content.Context;
import android.database.SQLException;
import java.util.List;
import com.JordHan.Gloggr.Model.Game;

public class DatabaseManager {

    static private DatabaseManager instance;

    // Singleton
    static public void init(Context ctx) {
        if (instance == null) {
            instance = new DatabaseManager(ctx);
        }
    }

    static public DatabaseManager getInstance() {
        return instance;
    }

    private DatabaseHelper helper;

    private DatabaseManager(Context ctx) {
        helper = new DatabaseHelper(ctx);
    }

    private DatabaseHelper getHelper() {
        return this.helper;
    }

    // Get all games from database
    public List<Game> getAllgames() throws SQLException {
        List<Game> games = null;

        try {
            games = getHelper().getGameDao().queryForAll();
        } catch (java.sql.SQLException ex) {
            ex.printStackTrace();
        }

        return games;
    }

    // Add new game to database
    public void addNewGame(Game newGame) {
        try {
            getHelper().getGameDao().create(newGame);
        } catch (java.sql.SQLException ex) {
            ex.printStackTrace();
        }
    }
    
    // Delete game from database
    public void deleteGame(Game game) {
        try {
            getHelper().getGameDao().delete(game);
        } catch (java.sql.SQLException ex) {
            ex.printStackTrace();
        }
    }
}




Java Source Code List

com.JordHan.Gloggr.Activities.CurrentlyPlayingActivity.java
com.JordHan.Gloggr.Activities.GameListActivity.java
com.JordHan.Gloggr.Activities.MainActivity.java
com.JordHan.Gloggr.Activities.PreferencesActivity.java
com.JordHan.Gloggr.Activities.SearchActivity.java
com.JordHan.Gloggr.Activities.Notification.AboutAppActivity.java
com.JordHan.Gloggr.Activities.Notification.AboutDeveloperActivity.java
com.JordHan.Gloggr.Helper.MenuHelper.java
com.JordHan.Gloggr.Model.Game.java
com.JordHan.Gloggr.Services.AbstractService.java
com.JordHan.Gloggr.Services.GameSearchService.java
com.JordHan.Gloggr.Services.IServiceListener.java
com.JordHan.Gloggr.db.DatabaseHelper.java
com.JordHan.Gloggr.db.DatabaseManager.java