From f1c0e03e71b6b8129bce88772c8e7b57d03c2d9c Mon Sep 17 00:00:00 2001 From: riking Date: Sat, 5 Oct 2013 18:07:11 -0700 Subject: [PATCH] SQL database - split loadProfile to have retry flag Instead of assuming that newUser() worked as intended, we cycle back around into the method. This also removes the possibility of infinite loops from the writeMissingRows() code path. --- .../nossr50/database/SQLDatabaseManager.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java index 8d6311c87..a975d7ced 100644 --- a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java @@ -347,6 +347,10 @@ public final class SQLDatabaseManager implements DatabaseManager { } public PlayerProfile loadPlayerProfile(String playerName, boolean create) { + return _loadPlayerProfile(playerName, create, true); + } + + private PlayerProfile _loadPlayerProfile(String playerName, boolean create, boolean retry) { if (!checkConnected()) { return new PlayerProfile(playerName, false); // return fake profile if not connected } @@ -396,6 +400,11 @@ public final class SQLDatabaseManager implements DatabaseManager { // Problem, nothing was returned + // Quit if this is second time around + if (!retry) { + return new PlayerProfile(playerName, false); + } + // First, read User Id - this is to check for orphans int id = readId(playerName); @@ -404,14 +413,16 @@ public final class SQLDatabaseManager implements DatabaseManager { // There is no such user if (create) { newUser(playerName); + return _loadPlayerProfile(playerName, false, false); } - return new PlayerProfile(playerName, create); + // Return unloaded profile if can't create + return new PlayerProfile(playerName, false); } // There is such a user writeMissingRows(id); // Retry, and abort on re-failure - return loadPlayerProfile(playerName, false); + return _loadPlayerProfile(playerName, create, false); } public void convertUsers(DatabaseManager destination) {