From f63c5e3310d26f3cc63c135b4752adf5c74789cb Mon Sep 17 00:00:00 2001 From: riking Date: Fri, 28 Jun 2013 13:49:30 -0700 Subject: [PATCH] Move orphan-handling code down to bottom --- .../nossr50/database/SQLDatabaseManager.java | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java index 3f3305d58..1244ff8d8 100644 --- a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java @@ -353,27 +353,7 @@ public final class SQLDatabaseManager implements DatabaseManager { } catch (SQLException e) {} } - // Problem, no rows returned result.close(); - - // First, read User Id - this is to check for orphans - - int id = readId(playerName); - - if (id == -1) { - // There is no such user - if (create) { - newUser(playerName); - return new PlayerProfile(playerName, true); - } - else { - return new PlayerProfile(playerName, false); - } - } - // There is such a user - writeMissingRows(id); - // Retry, and abort on re-failure - return loadPlayerProfile(playerName, false); } catch (SQLException ex) { printErrors(ex); @@ -389,13 +369,26 @@ public final class SQLDatabaseManager implements DatabaseManager { } } - if (!create) { - return new PlayerProfile(playerName, false); + // Problem, nothing was returned + + // First, read User Id - this is to check for orphans + + int id = readId(playerName); + + if (id == -1) { + // There is no such user + if (create) { + newUser(playerName); + return new PlayerProfile(playerName, true); + } + else { + return new PlayerProfile(playerName, false); + } } - - newUser(playerName); - - return new PlayerProfile(playerName, true); + // There is such a user + writeMissingRows(id); + // Retry, and abort on re-failure + return loadPlayerProfile(playerName, false); } public void convertUsers(DatabaseManager destination) {