summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2018-12-08 12:23:28 +0100
committerSimon Rettberg2018-12-08 12:23:28 +0100
commit44baf82c8587a3d56c92b32023bf6301710eccc7 (patch)
treec8b199cf955018bcd6efe63dd51f8f33be2c8e1d
parent[client] date woes... *g* (diff)
downloadtutor-module-44baf82c8587a3d56c92b32023bf6301710eccc7.tar.gz
tutor-module-44baf82c8587a3d56c92b32023bf6301710eccc7.tar.xz
tutor-module-44baf82c8587a3d56c92b32023bf6301710eccc7.zip
[server] DB Updater: Use helper methods
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java64
1 files changed, 14 insertions, 50 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java
index 3750ab2d..8fcd70a9 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java
@@ -23,13 +23,8 @@ public class Updater {
private static void addLectureLocationMapTable() throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement tablesStmt = connection.prepareStatement("SHOW TABLES");
- ResultSet tables = tablesStmt.executeQuery();
- while (tables.next()) {
- if (tables.getString(1).equals("lecture_x_location")) {
- return; // Table exists, don't do anything
- }
- }
+ if (tableExists(connection, "lecture_x_location"))
+ return;
// Add table
MysqlStatement tableAddStmt = connection.prepareStatement("CREATE TABLE `lecture_x_location` ("
+ " `lectureid` char(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,"
@@ -52,13 +47,8 @@ public class Updater {
private static void addLocationPrivateField() throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement checkStmt = connection.prepareStatement("DESCRIBE lecture");
- ResultSet cols = checkStmt.executeQuery();
- while (cols.next()) {
- if (cols.getString("Field").equals("islocationprivate")) {
- return; // Field exists, don't do anything
- }
- }
+ if (getColumnType(connection, "lecture", "islocationprivate") != null)
+ return; // Field exists, don't do anything
// Add field to table
MysqlStatement columnAddStmt = connection.prepareStatement("ALTER TABLE lecture"
+ " ADD islocationprivate TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 AFTER isprivate");
@@ -73,13 +63,8 @@ public class Updater {
private static void addHasUsbAccessField() throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement checkStmt = connection.prepareStatement("DESCRIBE lecture");
- ResultSet cols = checkStmt.executeQuery();
- while (cols.next()) {
- if (cols.getString("Field").equals("hasusbaccess")) {
- return; // Field exists, don't do anything
- }
- }
+ if (getColumnType(connection, "lecture", "hasusbaccess") != null)
+ return; // Field exists, don't do anything
// Add field to table
MysqlStatement columnAddStmt = connection.prepareStatement("ALTER TABLE lecture"
+ " ADD hasusbaccess TINYINT(1) UNSIGNED NOT NULL DEFAULT 1 AFTER hasinternetaccess");
@@ -94,13 +79,8 @@ public class Updater {
private static void addLogTable() throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement tablesStmt = connection.prepareStatement("SHOW TABLES");
- ResultSet tables = tablesStmt.executeQuery();
- while (tables.next()) {
- if (tables.getString(1).equals("actionlog")) {
- return; // Table exists, don't do anything
- }
- }
+ if (tableExists(connection, "actionlog"))
+ return;
// Add table
MysqlStatement tableAddStmt = connection.prepareStatement("CREATE TABLE `actionlog` ("
+ " `actionid` int(11) NOT NULL AUTO_INCREMENT,"
@@ -133,14 +113,8 @@ public class Updater {
*/
private static void fixEmailFieldLength() throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement checkStmt = connection.prepareStatement("DESCRIBE user");
- ResultSet cols = checkStmt.executeQuery();
- while (cols.next()) {
- if (cols.getString("Field").equals("email")
- && "varchar(100)".equalsIgnoreCase(cols.getString("Type"))) {
- return; // Field exists and has proper type, don't do anything
- }
- }
+ if ("varchar(100)".equals(getColumnType(connection, "user", "email")))
+ return; // Already 100 chars long, don'T do anything
MysqlStatement upStmt = connection.prepareStatement("ALTER TABLE user CHANGE email"
+ " email VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL");
upStmt.executeUpdate();
@@ -154,13 +128,8 @@ public class Updater {
private static void addNetworkShares() throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement tablesStmt = connection.prepareStatement("SHOW TABLES");
- ResultSet tables = tablesStmt.executeQuery();
- while (tables.next()) {
- if (tables.getString(1).equals("networkshare")) {
- return; // Table exists, don't do anything
- }
- }
+ if (tableExists(connection, "networkshare"))
+ return;
// Add table
MysqlStatement tableAddStmt = connection.prepareStatement(
"CREATE TABLE `networkshare` ("
@@ -187,13 +156,8 @@ public class Updater {
private static void addLectureFilter() throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement tablesStmt = connection.prepareStatement("SHOW TABLES");
- ResultSet tables = tablesStmt.executeQuery();
- while (tables.next()) {
- if (tables.getString(1).equals("lecturefilter")) {
- return; // Table exists, don't do anything
- }
- }
+ if (tableExists(connection, "lecturefilter"))
+ return;
// Add table
MysqlStatement tableAddStmt = connection.prepareStatement(
"CREATE TABLE `lecturefilter` ("