@@ -61,14 +61,14 @@ public abstract class SQLStorage implements AuthStorage {
6161 protected static final String ADD_FLOODGATE_COLUMN_STMT = "ALTER TABLE `" + PREMIUM_TABLE
6262 + "` ADD COLUMN `Floodgate` INTEGER(3)" ;
6363
64- protected static final String LOAD_BY_NAME = "SELECT * FROM `" + PREMIUM_TABLE
64+ protected static final String LOAD_BY_NAME_STMT = "SELECT * FROM `" + PREMIUM_TABLE
6565 + "` WHERE `Name`=? LIMIT 1" ;
66- protected static final String LOAD_BY_UUID = "SELECT * FROM `" + PREMIUM_TABLE
66+ protected static final String LOAD_BY_UUID_STMT = "SELECT * FROM `" + PREMIUM_TABLE
6767 + "` WHERE `UUID`=? LIMIT 1" ;
68- protected static final String INSERT_PROFILE = "INSERT INTO `" + PREMIUM_TABLE
68+ protected static final String INSERT_PROFILE_STMT = "INSERT INTO `" + PREMIUM_TABLE
6969 + "` (`UUID`, `Name`, `Premium`, `Floodgate`, `LastIp`) " + "VALUES (?, ?, ?, ?, ?) " ;
7070 // limit not necessary here, because it's unique
71- protected static final String UPDATE_PROFILE = "UPDATE `" + PREMIUM_TABLE
71+ protected static final String UPDATE_PROFILE_STMT = "UPDATE `" + PREMIUM_TABLE
7272 + "` SET `UUID`=?, `Name`=?, `Premium`=?, `Floodgate`=?, `LastIp`=?, "
7373 + "`LastLogin`=CURRENT_TIMESTAMP WHERE `UserID`=?" ;
7474
@@ -97,7 +97,7 @@ public void createTables() throws SQLException {
9797 // add Floodgate column
9898 DatabaseMetaData md = con .getMetaData ();
9999 if (isColumnMissing (md , "Floodgate" )) {
100- stmt .executeUpdate (ADD_FLOODGATE_COLUMN_STMT );
100+ stmt .executeUpdate (getAddFloodgateColumnStmt () );
101101 }
102102
103103 }
@@ -112,7 +112,7 @@ private boolean isColumnMissing(DatabaseMetaData metaData, String columnName) th
112112 @ Override
113113 public StoredProfile loadProfile (String name ) {
114114 try (Connection con = dataSource .getConnection ();
115- PreparedStatement loadStmt = con .prepareStatement (LOAD_BY_NAME )
115+ PreparedStatement loadStmt = con .prepareStatement (getLoadByNameStmt () )
116116 ) {
117117 loadStmt .setString (1 , name );
118118
@@ -130,7 +130,7 @@ public StoredProfile loadProfile(String name) {
130130 @ Override
131131 public StoredProfile loadProfile (UUID uuid ) {
132132 try (Connection con = dataSource .getConnection ();
133- PreparedStatement loadStmt = con .prepareStatement (LOAD_BY_UUID )) {
133+ PreparedStatement loadStmt = con .prepareStatement (getLoadByUuidStmt () )) {
134134 loadStmt .setString (1 , UUIDAdapter .toMojangId (uuid ));
135135
136136 try (ResultSet resultSet = loadStmt .executeQuery ()) {
@@ -177,7 +177,7 @@ public void save(StoredProfile playerProfile) {
177177 playerProfile .getSaveLock ().lock ();
178178 try {
179179 if (playerProfile .isSaved ()) {
180- try (PreparedStatement saveStmt = con .prepareStatement (UPDATE_PROFILE )) {
180+ try (PreparedStatement saveStmt = con .prepareStatement (getUpdateProfileStmt () )) {
181181 saveStmt .setString (1 , uuid );
182182 saveStmt .setString (2 , playerProfile .getName ());
183183 saveStmt .setBoolean (3 , playerProfile .isPremium ());
@@ -188,7 +188,8 @@ public void save(StoredProfile playerProfile) {
188188 saveStmt .execute ();
189189 }
190190 } else {
191- try (PreparedStatement saveStmt = con .prepareStatement (INSERT_PROFILE , RETURN_GENERATED_KEYS )) {
191+ try (PreparedStatement saveStmt = con .prepareStatement (getInsertProfileStmt (),
192+ RETURN_GENERATED_KEYS )) {
192193 saveStmt .setString (1 , uuid );
193194
194195 saveStmt .setString (2 , playerProfile .getName ());
@@ -214,13 +215,37 @@ public void save(StoredProfile playerProfile) {
214215 }
215216
216217 /**
217- * SQLite has a slightly different syntax, so this will be overridden by SQLiteStorage
218+ * SQLite and PostgreSQL have a slightly different syntax, so this will be overridden by SQLiteStorage and so on...
218219 * @return An SQL Statement to create the `premium` table
219220 */
220221 protected String getCreateTableStmt () {
221222 return CREATE_TABLE_STMT ;
222223 }
223224
225+ /**
226+ * PostgreSQL has a slightly different syntax, so this will be overridden by PostgreSQLStorage
227+ * @return An SQL Statement to create the `premium` table
228+ */
229+ protected String getAddFloodgateColumnStmt () {
230+ return ADD_FLOODGATE_COLUMN_STMT ;
231+ }
232+
233+ protected String getLoadByNameStmt () {
234+ return LOAD_BY_NAME_STMT ;
235+ }
236+
237+ protected String getLoadByUuidStmt () {
238+ return LOAD_BY_UUID_STMT ;
239+ }
240+
241+ protected String getInsertProfileStmt () {
242+ return INSERT_PROFILE_STMT ;
243+ }
244+
245+ protected String getUpdateProfileStmt () {
246+ return UPDATE_PROFILE_STMT ;
247+ }
248+
224249 @ Override
225250 public void close () {
226251 dataSource .close ();
0 commit comments