Android Open Source - MentalMathX Database Helper From Project Back to project page MentalMathX .
License The source code is released under:
GNU General Public License
If you think the Android project MentalMathX 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 net.schlingel.bplaced.mentalmathx.utils;
/ / w w w . j a v a 2 s . c o m
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import net.schlingel.bplaced.mentalmathx.model.Score;
import java.sql.SQLException;
import java.util.List;
/**
* Created by zombie on 01.08.14.
*/
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private static final String TAG = DatabaseHelper.class.getSimpleName();
private static final String DATABASE_NAME = "mentalmathx.db" ;
private static final int VERSION = 1;
private final Context context;
private Dao<Score, Long> dao;
public DatabaseHelper(Context context) {
super (context, DATABASE_NAME, null, VERSION);
this.context = context;
}
public Dao<Score, Long> getDao() throws SQLException {
if (dao == null) {
dao = getDao(Score.class);
}
return dao;
}
public List<Score> fetchAll() throws SQLException {
return getDao().queryForAll();
}
public void persist(Score score) throws SQLException {
getDao().createOrUpdate(score);
}
public void delete(Score score) throws SQLException {
if (score == null || score.getId() == null) {
throw new IllegalArgumentException("Delete must not be called on null or objects without ID." );
}
getDao().delete(score);
Log.i(TAG, String.format("Deleted score %d" , score.getId()));
}
@Override
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
try {
TableUtils.createTable(connectionSource, Score.class);
Log.i(TAG, "Created scores database" );
} catch (SQLException e) {
Log.e(TAG, "Couldn't create score database" , e);
}
}
@Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
try {
TableUtils.dropTable(connectionSource, Score.class, true);
onCreate(database, connectionSource);
Log.i(TAG, "Updated scores database" );
} catch (SQLException e) {
Log.e(TAG, "Couldn't update scores database" , e);
}
}
}
Java Source Code List net.schlingel.bplaced.mentalmathx.AboutActivity.java net.schlingel.bplaced.mentalmathx.GameActivity.java net.schlingel.bplaced.mentalmathx.HighscoresActivity.java net.schlingel.bplaced.mentalmathx.NewGameActivity.java net.schlingel.bplaced.mentalmathx.SelectDifficultyActivity.java net.schlingel.bplaced.mentalmathx.controller.GameController.java net.schlingel.bplaced.mentalmathx.controller.HighscoreController.java net.schlingel.bplaced.mentalmathx.controller.impl.GameControllerImpl.java net.schlingel.bplaced.mentalmathx.controller.impl.HighscoreControllerImpl.java net.schlingel.bplaced.mentalmathx.game.Difficulty.java net.schlingel.bplaced.mentalmathx.game.Mode.java net.schlingel.bplaced.mentalmathx.game.logic.FiniteGameLogic.java net.schlingel.bplaced.mentalmathx.game.logic.GameLogic.java net.schlingel.bplaced.mentalmathx.game.logic.HoundredRoundsGameLogic.java net.schlingel.bplaced.mentalmathx.game.logic.InfiniteGameLogic.java net.schlingel.bplaced.mentalmathx.game.logic.TenExercisesGameLogic.java net.schlingel.bplaced.mentalmathx.game.logic.TenRoundsGameLogic.java net.schlingel.bplaced.mentalmathx.game.strategy.EasyExerciseStrategy.java net.schlingel.bplaced.mentalmathx.game.strategy.ExerciseStrategyFactory.java net.schlingel.bplaced.mentalmathx.game.strategy.ExerciseStrategy.java net.schlingel.bplaced.mentalmathx.game.strategy.HardExerciseStrategy.java net.schlingel.bplaced.mentalmathx.game.strategy.MediumExerciseStrategy.java net.schlingel.bplaced.mentalmathx.game.strategy.OneOOneExerciseStrategy.java net.schlingel.bplaced.mentalmathx.math.Calculation.java net.schlingel.bplaced.mentalmathx.math.Calculations.java net.schlingel.bplaced.mentalmathx.math.Number.java net.schlingel.bplaced.mentalmathx.math.Operator.java net.schlingel.bplaced.mentalmathx.math.Term.java net.schlingel.bplaced.mentalmathx.model.Result.java net.schlingel.bplaced.mentalmathx.model.Score.java net.schlingel.bplaced.mentalmathx.model.adapters.ScoreAdapter.java net.schlingel.bplaced.mentalmathx.utils.DatabaseHelper.java net.schlingel.bplaced.mentalmathx.utils.DelayedTask.java net.schlingel.bplaced.mentalmathx.utils.LabelHelper.java net.schlingel.bplaced.mentalmathx.utils.MarathonScoreComparator.java net.schlingel.bplaced.mentalmathx.utils.RegularScoreComparator.java net.schlingel.bplaced.mentalmathx.view.DisplayMode.java net.schlingel.bplaced.mentalmathx.view.GameView.java net.schlingel.bplaced.mentalmathx.view.HighscoresView.java net.schlingel.bplaced.mentalmathx.view.ResultsView.java net.schlingel.bplaced.mentalmathx.view.impl.DialogResultsView.java net.schlingel.bplaced.mentalmathx.view.impl.FragmentHighscoresSubView.java