mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-24 03:05:28 +01:00
Update DB schemas for bigger blobs - make MySQL/MariaDB more common
This commit is contained in:
parent
ebb312c90e
commit
bbdebbffa6
File diff suppressed because it is too large
Load Diff
@ -31,13 +31,13 @@ import org.dynmap.utils.BufferInputStream;
|
|||||||
import org.dynmap.utils.BufferOutputStream;
|
import org.dynmap.utils.BufferOutputStream;
|
||||||
|
|
||||||
public class MySQLMapStorage extends MapStorage {
|
public class MySQLMapStorage extends MapStorage {
|
||||||
private String connectionString;
|
protected String connectionString;
|
||||||
private String userid;
|
private String userid;
|
||||||
private String password;
|
private String password;
|
||||||
private String database;
|
protected String database;
|
||||||
private String hostname;
|
protected String hostname;
|
||||||
private String prefix = "";
|
private String prefix = "";
|
||||||
private String flags;
|
protected String flags;
|
||||||
private String tableTiles;
|
private String tableTiles;
|
||||||
private String tableMaps;
|
private String tableMaps;
|
||||||
private String tableFaces;
|
private String tableFaces;
|
||||||
@ -46,7 +46,7 @@ public class MySQLMapStorage extends MapStorage {
|
|||||||
private String tableStandaloneFiles;
|
private String tableStandaloneFiles;
|
||||||
private String tableSchemaVersion;
|
private String tableSchemaVersion;
|
||||||
|
|
||||||
private int port;
|
protected int port;
|
||||||
private static final int POOLSIZE = 5;
|
private static final int POOLSIZE = 5;
|
||||||
private Connection[] cpool = new Connection[POOLSIZE];
|
private Connection[] cpool = new Connection[POOLSIZE];
|
||||||
private int cpoolCount = 0;
|
private int cpoolCount = 0;
|
||||||
@ -270,6 +270,18 @@ public class MySQLMapStorage extends MapStorage {
|
|||||||
public MySQLMapStorage() {
|
public MySQLMapStorage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MySQL specific driver check
|
||||||
|
protected boolean checkDriver() {
|
||||||
|
connectionString = "jdbc:mysql://" + hostname + ":" + port + "/" + database + flags;
|
||||||
|
Log.info("Opening MySQL database " + hostname + ":" + port + "/" + database + " as map store");
|
||||||
|
|
||||||
|
if(!hasClass("com.mysql.cj.jdbc.Driver") && !hasClass("com.mysql.jdbc.Driver")){
|
||||||
|
Log.severe("MySQL-JDBC classes not found - MySQL data source not usable");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean init(DynmapCore core) {
|
public boolean init(DynmapCore core) {
|
||||||
if (!super.init(core)) {
|
if (!super.init(core)) {
|
||||||
@ -290,13 +302,8 @@ public class MySQLMapStorage extends MapStorage {
|
|||||||
tableStandaloneFiles = prefix + "StandaloneFiles";
|
tableStandaloneFiles = prefix + "StandaloneFiles";
|
||||||
tableSchemaVersion = prefix + "SchemaVersion";
|
tableSchemaVersion = prefix + "SchemaVersion";
|
||||||
|
|
||||||
connectionString = "jdbc:mysql://" + hostname + ":" + port + "/" + database + flags;
|
if (!checkDriver()) return false;
|
||||||
Log.info("Opening MySQL database " + hostname + ":" + port + "/" + database + " as map store");
|
|
||||||
|
|
||||||
if(!hasClass("com.mysql.cj.jdbc.Driver") && !hasClass("com.mysql.jdbc.Driver")){
|
|
||||||
Log.severe("MySQL-JDBC classes not found - MySQL data source not usable");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Initialize/update tables, if needed
|
// Initialize/update tables, if needed
|
||||||
if(!initializeTables()) {
|
if(!initializeTables()) {
|
||||||
return false;
|
return false;
|
||||||
@ -465,12 +472,13 @@ public class MySQLMapStorage extends MapStorage {
|
|||||||
c = getConnection();
|
c = getConnection();
|
||||||
doUpdate(c, "CREATE TABLE " + tableMaps + " (ID INTEGER PRIMARY KEY AUTO_INCREMENT, WorldID VARCHAR(64) NOT NULL, MapID VARCHAR(64) NOT NULL, Variant VARCHAR(16) NOT NULL, ServerID BIGINT NOT NULL DEFAULT 0)");
|
doUpdate(c, "CREATE TABLE " + tableMaps + " (ID INTEGER PRIMARY KEY AUTO_INCREMENT, WorldID VARCHAR(64) NOT NULL, MapID VARCHAR(64) NOT NULL, Variant VARCHAR(16) NOT NULL, ServerID BIGINT NOT NULL DEFAULT 0)");
|
||||||
doUpdate(c, "CREATE TABLE " + tableTiles + " (MapID INT NOT NULL, x INT NOT NULL, y INT NOT NULL, zoom INT NOT NULL, HashCode BIGINT NOT NULL, LastUpdate BIGINT NOT NULL, Format INT NOT NULL, Image MEDIUMBLOB, PRIMARY KEY(MapID, x, y, zoom))");
|
doUpdate(c, "CREATE TABLE " + tableTiles + " (MapID INT NOT NULL, x INT NOT NULL, y INT NOT NULL, zoom INT NOT NULL, HashCode BIGINT NOT NULL, LastUpdate BIGINT NOT NULL, Format INT NOT NULL, Image MEDIUMBLOB, PRIMARY KEY(MapID, x, y, zoom))");
|
||||||
doUpdate(c, "CREATE TABLE " + tableFaces + " (PlayerName VARCHAR(64) NOT NULL, TypeID INT NOT NULL, Image BLOB, PRIMARY KEY(PlayerName, TypeID))");
|
doUpdate(c, "CREATE TABLE " + tableFaces + " (PlayerName VARCHAR(64) NOT NULL, TypeID INT NOT NULL, Image MEDIUMBLOB, PRIMARY KEY(PlayerName, TypeID))");
|
||||||
doUpdate(c, "CREATE TABLE " + tableMarkerIcons + " (IconName VARCHAR(128) PRIMARY KEY NOT NULL, Image BLOB)");
|
doUpdate(c, "CREATE TABLE " + tableMarkerIcons + " (IconName VARCHAR(128) PRIMARY KEY NOT NULL, Image MEDIUMBLOB)");
|
||||||
doUpdate(c, "CREATE TABLE " + tableMarkerFiles + " (FileName VARCHAR(128) PRIMARY KEY NOT NULL, Content MEDIUMTEXT)");
|
doUpdate(c, "CREATE TABLE " + tableMarkerFiles + " (FileName VARCHAR(128) PRIMARY KEY NOT NULL, Content MEDIUMTEXT)");
|
||||||
doUpdate(c, "CREATE TABLE " + tableStandaloneFiles + " (FileName VARCHAR(128) NOT NULL, ServerID BIGINT NOT NULL DEFAULT 0, Content MEDIUMTEXT, PRIMARY KEY (FileName, ServerID))");
|
doUpdate(c, "CREATE TABLE " + tableStandaloneFiles + " (FileName VARCHAR(128) NOT NULL, ServerID BIGINT NOT NULL DEFAULT 0, Content MEDIUMTEXT, PRIMARY KEY (FileName, ServerID))");
|
||||||
doUpdate(c, "CREATE TABLE " + tableSchemaVersion + " (level INT PRIMARY KEY NOT NULL)");
|
doUpdate(c, "CREATE TABLE " + tableSchemaVersion + " (level INT PRIMARY KEY NOT NULL)");
|
||||||
doUpdate(c, "INSERT INTO " + tableSchemaVersion + " (level) VALUES (3)");
|
doUpdate(c, "INSERT INTO " + tableSchemaVersion + " (level) VALUES (4)");
|
||||||
|
version = 4; // Initial - we have all the following updates already
|
||||||
} catch (SQLException x) {
|
} catch (SQLException x) {
|
||||||
Log.severe("Error creating tables - " + x.getMessage());
|
Log.severe("Error creating tables - " + x.getMessage());
|
||||||
err = true;
|
err = true;
|
||||||
@ -480,12 +488,13 @@ public class MySQLMapStorage extends MapStorage {
|
|||||||
c = null;
|
c = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (version == 1) {
|
if (version == 1) {
|
||||||
try {
|
try {
|
||||||
c = getConnection();
|
c = getConnection();
|
||||||
doUpdate(c, "CREATE TABLE " + tableStandaloneFiles + " (FileName VARCHAR(128) NOT NULL, ServerID BIGINT NOT NULL DEFAULT 0, Content MEDIUMTEXT, PRIMARY KEY (FileName, ServerID))");
|
doUpdate(c, "CREATE TABLE " + tableStandaloneFiles + " (FileName VARCHAR(128) NOT NULL, ServerID BIGINT NOT NULL DEFAULT 0, Content MEDIUMTEXT, PRIMARY KEY (FileName, ServerID))");
|
||||||
doUpdate(c, "ALTER TABLE " + tableMaps + " ADD COLUMN ServerID BIGINT NOT NULL DEFAULT 0 AFTER Variant");
|
doUpdate(c, "ALTER TABLE " + tableMaps + " ADD COLUMN ServerID BIGINT NOT NULL DEFAULT 0 AFTER Variant");
|
||||||
doUpdate(c, "UPDATE " + tableSchemaVersion + " SET level=3 WHERE level = 1;");
|
doUpdate(c, "UPDATE " + tableSchemaVersion + " SET level=2 WHERE level = 1;");
|
||||||
|
version = 2;
|
||||||
} catch (SQLException x) {
|
} catch (SQLException x) {
|
||||||
Log.severe("Error creating tables - " + x.getMessage());
|
Log.severe("Error creating tables - " + x.getMessage());
|
||||||
err = true;
|
err = true;
|
||||||
@ -495,13 +504,14 @@ public class MySQLMapStorage extends MapStorage {
|
|||||||
c = null;
|
c = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (version == 2) {
|
if (version == 2) {
|
||||||
try {
|
try {
|
||||||
c = getConnection();
|
c = getConnection();
|
||||||
doUpdate(c, "DELETE FROM " + tableStandaloneFiles + ";");
|
doUpdate(c, "DELETE FROM " + tableStandaloneFiles + ";");
|
||||||
doUpdate(c, "ALTER TABLE " + tableStandaloneFiles + " DROP COLUMN Content;");
|
doUpdate(c, "ALTER TABLE " + tableStandaloneFiles + " DROP COLUMN Content;");
|
||||||
doUpdate(c, "ALTER TABLE " + tableStandaloneFiles + " ADD COLUMN Content MEDIUMTEXT;");
|
doUpdate(c, "ALTER TABLE " + tableStandaloneFiles + " ADD COLUMN Content MEDIUMTEXT;");
|
||||||
doUpdate(c, "UPDATE " + tableSchemaVersion + " SET level=3 WHERE level = 2;");
|
doUpdate(c, "UPDATE " + tableSchemaVersion + " SET level=3 WHERE level = 2;");
|
||||||
|
version = 3;
|
||||||
} catch (SQLException x) {
|
} catch (SQLException x) {
|
||||||
Log.severe("Error creating tables - " + x.getMessage());
|
Log.severe("Error creating tables - " + x.getMessage());
|
||||||
err = true;
|
err = true;
|
||||||
@ -511,12 +521,29 @@ public class MySQLMapStorage extends MapStorage {
|
|||||||
c = null;
|
c = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (version == 3) {
|
||||||
|
try {
|
||||||
|
c = getConnection();
|
||||||
|
doUpdate(c, "ALTER TABLE " + tableTiles + " ALTER COLUMN Image MEDIUMBLOB;");
|
||||||
|
doUpdate(c, "ALTER TABLE " + tableFaces + " ALTER COLUMN Image MEDIUMBLOB;");
|
||||||
|
doUpdate(c, "ALTER TABLE " + tableMarkerIcons + " ALTER COLUMN Image MEDIUMBLOB;");
|
||||||
|
doUpdate(c, "UPDATE " + tableSchemaVersion + " SET level=4 WHERE level = 3;");
|
||||||
|
} catch (SQLException x) {
|
||||||
|
Log.severe("Error creating tables - " + x.getMessage());
|
||||||
|
err = true;
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
releaseConnection(c, err);
|
||||||
|
c = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
// Load maps table - cache results
|
// Load maps table - cache results
|
||||||
doLoadMaps();
|
doLoadMaps();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection getConnection() throws SQLException {
|
private Connection getConnection() throws SQLException {
|
||||||
Connection c = null;
|
Connection c = null;
|
||||||
synchronized (cpool) {
|
synchronized (cpool) {
|
||||||
|
@ -464,6 +464,7 @@ public class PostgreSQLMapStorage extends MapStorage {
|
|||||||
doUpdate(c, "CREATE TABLE " + tableStandaloneFiles + " (FileName VARCHAR(128) NOT NULL, ServerID BIGINT NOT NULL DEFAULT 0, Content BYTEA, PRIMARY KEY (FileName, ServerID))");
|
doUpdate(c, "CREATE TABLE " + tableStandaloneFiles + " (FileName VARCHAR(128) NOT NULL, ServerID BIGINT NOT NULL DEFAULT 0, Content BYTEA, PRIMARY KEY (FileName, ServerID))");
|
||||||
doUpdate(c, "CREATE TABLE " + tableSchemaVersion + " (level INT PRIMARY KEY NOT NULL)");
|
doUpdate(c, "CREATE TABLE " + tableSchemaVersion + " (level INT PRIMARY KEY NOT NULL)");
|
||||||
doUpdate(c, "INSERT INTO " + tableSchemaVersion + " (level) VALUES (3)");
|
doUpdate(c, "INSERT INTO " + tableSchemaVersion + " (level) VALUES (3)");
|
||||||
|
version = 3; // initialzed to current schema
|
||||||
} catch (SQLException x) {
|
} catch (SQLException x) {
|
||||||
Log.severe("Error creating tables - " + x.getMessage());
|
Log.severe("Error creating tables - " + x.getMessage());
|
||||||
err = true;
|
err = true;
|
||||||
@ -473,12 +474,13 @@ public class PostgreSQLMapStorage extends MapStorage {
|
|||||||
c = null;
|
c = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (version == 1) {
|
if (version == 1) {
|
||||||
try {
|
try {
|
||||||
c = getConnection();
|
c = getConnection();
|
||||||
doUpdate(c, "CREATE TABLE " + tableStandaloneFiles + " (FileName VARCHAR(128) NOT NULL, ServerID BIGINT NOT NULL DEFAULT 0, Content TEXT, PRIMARY KEY (FileName, ServerID))");
|
doUpdate(c, "CREATE TABLE " + tableStandaloneFiles + " (FileName VARCHAR(128) NOT NULL, ServerID BIGINT NOT NULL DEFAULT 0, Content TEXT, PRIMARY KEY (FileName, ServerID))");
|
||||||
doUpdate(c, "ALTER TABLE " + tableMaps + " ADD COLUMN ServerID BIGINT NOT NULL DEFAULT 0 AFTER Variant");
|
doUpdate(c, "ALTER TABLE " + tableMaps + " ADD COLUMN ServerID BIGINT NOT NULL DEFAULT 0 AFTER Variant");
|
||||||
doUpdate(c, "UPDATE " + tableSchemaVersion + " SET level=3 WHERE level = 1;");
|
doUpdate(c, "UPDATE " + tableSchemaVersion + " SET level=2 WHERE level = 1;");
|
||||||
|
version = 2;
|
||||||
} catch (SQLException x) {
|
} catch (SQLException x) {
|
||||||
Log.severe("Error creating tables - " + x.getMessage());
|
Log.severe("Error creating tables - " + x.getMessage());
|
||||||
err = true;
|
err = true;
|
||||||
@ -488,13 +490,14 @@ public class PostgreSQLMapStorage extends MapStorage {
|
|||||||
c = null;
|
c = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (version == 2) {
|
if (version == 2) {
|
||||||
try {
|
try {
|
||||||
c = getConnection();
|
c = getConnection();
|
||||||
doUpdate(c, "DELETE FROM " + tableStandaloneFiles + ";");
|
doUpdate(c, "DELETE FROM " + tableStandaloneFiles + ";");
|
||||||
doUpdate(c, "ALTER TABLE " + tableStandaloneFiles + " DROP COLUMN Content;");
|
doUpdate(c, "ALTER TABLE " + tableStandaloneFiles + " DROP COLUMN Content;");
|
||||||
doUpdate(c, "ALTER TABLE " + tableStandaloneFiles + " ADD COLUMN Content BYTEA;");
|
doUpdate(c, "ALTER TABLE " + tableStandaloneFiles + " ADD COLUMN Content BYTEA;");
|
||||||
doUpdate(c, "UPDATE " + tableSchemaVersion + " SET level=3 WHERE level = 2;");
|
doUpdate(c, "UPDATE " + tableSchemaVersion + " SET level=3 WHERE level = 2;");
|
||||||
|
version = 3;
|
||||||
} catch (SQLException x) {
|
} catch (SQLException x) {
|
||||||
Log.severe("Error creating tables - " + x.getMessage());
|
Log.severe("Error creating tables - " + x.getMessage());
|
||||||
err = true;
|
err = true;
|
||||||
|
@ -402,6 +402,7 @@ public class SQLiteMapStorage extends MapStorage {
|
|||||||
doUpdate(c, "CREATE TABLE MarkerFiles (FileName STRING PRIMARY KEY NOT NULL, Content CLOB)");
|
doUpdate(c, "CREATE TABLE MarkerFiles (FileName STRING PRIMARY KEY NOT NULL, Content CLOB)");
|
||||||
doUpdate(c, "CREATE TABLE SchemaVersion (level INT PRIMARY KEY NOT NULL)");
|
doUpdate(c, "CREATE TABLE SchemaVersion (level INT PRIMARY KEY NOT NULL)");
|
||||||
doUpdate(c, "INSERT INTO SchemaVersion (level) VALUES (2)");
|
doUpdate(c, "INSERT INTO SchemaVersion (level) VALUES (2)");
|
||||||
|
version = 2; // Initializes to current schema
|
||||||
} catch (SQLException x) {
|
} catch (SQLException x) {
|
||||||
Log.severe("Error creating tables - " + x.getMessage());
|
Log.severe("Error creating tables - " + x.getMessage());
|
||||||
err = true;
|
err = true;
|
||||||
@ -411,13 +412,14 @@ public class SQLiteMapStorage extends MapStorage {
|
|||||||
c = null;
|
c = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (version == 1) { // Add ImageLen columns
|
if (version == 1) { // Add ImageLen columns
|
||||||
try {
|
try {
|
||||||
c = getConnection();
|
c = getConnection();
|
||||||
doUpdate(c, "ALTER TABLE Tiles ADD ImageLen INT");
|
doUpdate(c, "ALTER TABLE Tiles ADD ImageLen INT");
|
||||||
doUpdate(c, "ALTER TABLE Faces ADD ImageLen INT");
|
doUpdate(c, "ALTER TABLE Faces ADD ImageLen INT");
|
||||||
doUpdate(c, "ALTER TABLE MarkerIcons ADD ImageLen INT");
|
doUpdate(c, "ALTER TABLE MarkerIcons ADD ImageLen INT");
|
||||||
doUpdate(c, "UPDATE SchemaVersion SET level=2");
|
doUpdate(c, "UPDATE SchemaVersion SET level=2");
|
||||||
|
version = 2;
|
||||||
} catch (SQLException x) {
|
} catch (SQLException x) {
|
||||||
Log.severe("Error creating tables - " + x.getMessage());
|
Log.severe("Error creating tables - " + x.getMessage());
|
||||||
err = true;
|
err = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user