Commit 474c5b24 authored by Matyáš Latner's avatar Matyáš Latner

Merge branch 'feature-db-migrate' into 'V3.2.1'

#310 Feature db migrate



See merge request !398
parents eedcb330 d72bd376
......@@ -192,7 +192,7 @@ public class UserRankManager {
RankProgress[] result = gameRankProgressMap.get(user.getId());
if(result == null) {
refreshUserRank(user);
forceRefreshUserRank(user);
result = gameRankProgressMap.get(user.getId());
}
......@@ -206,7 +206,7 @@ public class UserRankManager {
RankProgress[] result = gameRankProgressMap.get(user.getId());
if(result == null) {
refreshUserRank(user);
forceRefreshUserRank(user);
result = gameRankProgressMap.get(user.getId());
}
......
......@@ -31,7 +31,7 @@ public class DatabaseManager {
};
private enum VersionScript {
VERSION_01( 1, "ALTER TABLE game ADD language INTEGER NOT NULL DEFAULT " + Game.DEFAULT_GAME_LANGUAGE),
VERSION_01( 1, "ALTER TABLE game ADD locale INTEGER NOT NULL DEFAULT " + Game.DEFAULT_GAME_LOCALE),
VERSION_02( 2, "ALTER TABLE game ADD version TEXT NOT NULL DEFAULT '" + Game.DEFAULT_GAME_VERSION + "'");
private int version;
......
......@@ -240,7 +240,7 @@ public class UserDAO {
continue;
}
Long gameId = GameDAO.importGame(dbUser, game.getGameDifficulty(), game.getGameNumber(), game.getGameLanguage(), game.getGameVersionName(), game.getRandomSeed(), game.getStartTime(), game.getEndTime());
Long gameId = GameDAO.importGame(dbUser, game.getGameDifficulty(), game.getGameNumber(), game.getGameLocale(), game.getGameVersionName(), game.getRandomSeed(), game.getStartTime(), game.getEndTime());
if (gameId == null) {
continue;
......
......@@ -150,25 +150,25 @@ public class GameDAO {
// prepared statements
public static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS game (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, start_time INTEGER, end_time INTEGER, difficulty_number INTEGER NOT NULL, game_number INTEGER NOT NULL, random_seed INTEGER NOT NULL, sync_at INTEGER, FOREIGN KEY(user_id) REFERENCES user(id))";
public static final String NEW_GAME_INSERT = "INSERT INTO game (user_id, difficulty_number, game_number, language, version, random_seed) VALUES (?, ?, ?, ?, ?, ?)";
public static final String NEW_GAME_INSERT = "INSERT INTO game (user_id, difficulty_number, game_number, locale, version, random_seed) VALUES (?, ?, ?, ?, ?, ?)";
public static final String GAME_UPDATE_START = "UPDATE game SET start_time = ? WHERE id = ?";
public static final String GAME_UPDATE_END = "UPDATE game SET end_time = ? WHERE id = ?";
public static final String GAME_UPDATE_SYNC_AT = "UPDATE game SET sync_at = ? WHERE id = ?";
public static final String GAME_SELECT_FOR_ID = "SELECT id, user_id, difficulty_number, game_number, language, version, random_seed, start_time, end_time FROM game WHERE id = ?";
public static final String GAME_SELECT_FOR_ID = "SELECT id, user_id, difficulty_number, game_number, locale, version, random_seed, start_time, end_time FROM game WHERE id = ?";
public static final String GAME_SELECT_LAST_ID = "SELECT max(id) FROM game";
public static final String GAME_SELECT_COUNT_FOR_GAME_AND_DIFFICULTY = "SELECT count(id) FROM game WHERE game_number = ? AND difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL";
public static final String GAME_SELECT_FOR_USER_AND_DEFINITION = "SELECT id, user_id, difficulty_number, game_number, language, random_seed, start_time, end_time FROM game WHERE user_id = ? AND game_number = ? AND end_time IS NOT NULL AND end_time != 0 ORDER BY start_time ASC";
public static final String GAME_SELECT_FOR_USER_AND_DEFINITION = "SELECT id, user_id, difficulty_number, game_number, locale, random_seed, start_time, end_time FROM game WHERE user_id = ? AND game_number = ? AND end_time IS NOT NULL AND end_time != 0 ORDER BY start_time ASC";
public static final String GAME_SELECT_COUNT_FOR_GAME = "SELECT count(id) FROM game WHERE game_number = ? AND user_id = ?";
public static final String GAME_SELECT_ALL_FOR_USER_SYNC = "SELECT id, user_id, difficulty_number, game_number, language, version, random_seed, start_time, end_time FROM game where user_id = ? AND sync_at is null";
public static final String GAME_SELECT_ALL_FOR_USER_SYNC = "SELECT id, user_id, difficulty_number, game_number, locale, version, random_seed, start_time, end_time FROM game where user_id = ? AND sync_at is null";
public static final String GAME_SELECT_BY_START_AND_END = "SELECT id FROM game WHERE user_id = ? AND start_time = ? AND end_time = ?";
public static final String GAME_SELECT_BY_START_AND_NULL_END = "SELECT id FROM game WHERE user_id = ? AND start_time = ? AND end_time IS NULL";
public static final String GAME_SELECT_LAST_SCORES_FOR_USER_AND_GAME = "SELECT value FROM game_score INNER JOIN game ON game_score.game_id=game.id AND game.user_id=? AND game.game_number=? WHERE game_score.key=? AND end_time IS NOT NULL ORDER BY game_id DESC LIMIT 1";
public static final String GAME_SELECT_FOR_RANK_MANAGER = "SELECT id, difficulty_number, game_number, version, start_time, end_time FROM game WHERE user_id = ? AND start_time IS NOT NULL AND start_time != 0 end_time IS NOT NULL AND end_time != 0 ORDER BY end_time ASC";
public static final String GAME_SELECT_FOR_RANK_MANAGER = "SELECT id, difficulty_number, game_number, version, start_time, end_time FROM game WHERE user_id = ? AND start_time IS NOT NULL AND start_time != 0 AND end_time IS NOT NULL AND end_time != 0 ORDER BY end_time ASC";
// classic statements
public static final String IMPORT_GAME_INSERT = "INSERT INTO game (user_id, difficulty_number, game_number, language, version, random_seed, start_time, end_time, sync_at) VALUES (%d, %d, %d, %d, %s, %d, %d, %d, %d)";
public static final String IMPORT_GAME_INSERT = "INSERT INTO game (user_id, difficulty_number, game_number, locale, version, random_seed, start_time, end_time, sync_at) VALUES (%d, %d, %d, %d, %s, %d, %d, %d, %d)";
private static Long insertNewGame(User user, GameDifficulty difficulty, GameDefinition gameDefinition, TablexiaSettings.LocaleDefinition localeDefinition, String versionName, TablexiaRandom random) {
......@@ -212,13 +212,13 @@ public class GameDAO {
return result;
}
public static Long importGame(User user, int difficulty, int gameNumber, int gameLanguage, String version, long randomSeed, long startTime, long endTime) {
public static Long importGame(User user, int difficulty, int gameNumber, int gameLocale, String version, long randomSeed, long startTime, long endTime) {
try {
Long gameId = null;
Statement st = TablexiaStorage.getInstance().createStatement();
// workaround for sync error -> serialized JSON from server contains 0 instead of NULL
// String sql = String.format(IMPORT_GAME_INSERT, user.getId(), difficulty, gameNumber, randomSeed, startTime, endTime, System.currentTimeMillis());
String sql = String.format(IMPORT_GAME_INSERT, user.getId(), difficulty, gameNumber, gameLanguage, version, randomSeed, startTime, endTime != 0 ? String.valueOf(endTime) : "NULL", System.currentTimeMillis());
String sql = String.format(IMPORT_GAME_INSERT, user.getId(), difficulty, gameNumber, gameLocale, version, randomSeed, startTime, endTime != 0 ? String.valueOf(endTime) : "NULL", System.currentTimeMillis());
st.executeUpdate(sql);
gameId = selectLastGameId();
st.close();
......@@ -351,7 +351,7 @@ public class GameDAO {
UserDAO.selectUser(userId),
diff,
gameNum,
Game.DEFAULT_GAME_LANGUAGE,
Game.DEFAULT_GAME_LOCALE,
version,
0L, //Don't need seed
startTimeLong,
......
......@@ -55,7 +55,7 @@ public class GameTrophy {
public static class ThreeStarsReceived implements GameTrophyResolver {
public static final String GAME_SELECT_FOR_GAME_AND_DIFFICULTY = "SELECT id, user_id, difficulty_number, game_number, language, random_seed, start_time, end_time FROM game WHERE game_number = ? AND difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL";
public static final String GAME_SELECT_FOR_GAME_AND_DIFFICULTY = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time FROM game WHERE game_number = ? AND difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL";
private static List<Game> getGamesForGameAndDifficulty(User user, GameTrophyDefinition trophyDef) {
List<Game> games = new ArrayList<Game>();
......@@ -67,14 +67,13 @@ public class GameTrophy {
try {
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
String startTimeStr = resultSet.getString(7);
String endTimeStr = resultSet.getString(8);
String startTimeStr = resultSet.getString(6);
String endTimeStr = resultSet.getString(7);
Game game = new Game(resultSet.getLong(1),
UserDAO.selectUser(resultSet.getLong(2)),
resultSet.getInt(3),
resultSet.getInt(4),
resultSet.getInt(5),
resultSet.getLong(6),
resultSet.getLong(5),
startTimeStr != null ? Long.valueOf(startTimeStr) : null,
endTimeStr != null ? Long.valueOf(endTimeStr) : null);
game.setGamePauses(GamePauseDAO.selectGamePausesForGame(game));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment