mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-09-28 23:27:33 +02:00
Refactor : wrap every single SQL query inside an interface
This commit is contained in:
parent
c807699c7c
commit
50ac4d6ed5
@ -30,6 +30,8 @@
|
|||||||
import de.bluecolored.bluemap.core.BlueMap;
|
import de.bluecolored.bluemap.core.BlueMap;
|
||||||
import de.bluecolored.bluemap.core.logger.Logger;
|
import de.bluecolored.bluemap.core.logger.Logger;
|
||||||
import de.bluecolored.bluemap.core.storage.*;
|
import de.bluecolored.bluemap.core.storage.*;
|
||||||
|
import de.bluecolored.bluemap.core.storage.sql.dialect.MariaDBFactory;
|
||||||
|
import de.bluecolored.bluemap.core.storage.sql.dialect.SQLQueryAbstractFactory;
|
||||||
import de.bluecolored.bluemap.core.util.WrappedOutputStream;
|
import de.bluecolored.bluemap.core.util.WrappedOutputStream;
|
||||||
import org.apache.commons.dbcp2.*;
|
import org.apache.commons.dbcp2.*;
|
||||||
import org.apache.commons.pool2.ObjectPool;
|
import org.apache.commons.pool2.ObjectPool;
|
||||||
@ -50,6 +52,7 @@
|
|||||||
|
|
||||||
public class SQLStorage extends Storage {
|
public class SQLStorage extends Storage {
|
||||||
|
|
||||||
|
private final SQLQueryAbstractFactory concreteSQL;
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
private final Compression hiresCompression;
|
private final Compression hiresCompression;
|
||||||
|
|
||||||
@ -64,7 +67,7 @@ public class SQLStorage extends Storage {
|
|||||||
|
|
||||||
public SQLStorage(SQLStorageSettings config) throws MalformedURLException, SQLDriverException {
|
public SQLStorage(SQLStorageSettings config) throws MalformedURLException, SQLDriverException {
|
||||||
this.closed = false;
|
this.closed = false;
|
||||||
|
this.concreteSQL = new MariaDBFactory();
|
||||||
try {
|
try {
|
||||||
if (config.getDriverClass().isPresent()) {
|
if (config.getDriverClass().isPresent()) {
|
||||||
if (config.getDriverJar().isPresent()) {
|
if (config.getDriverJar().isPresent()) {
|
||||||
@ -115,9 +118,7 @@ public OutputStream writeMapTile(String mapId, int lod, Vector2i tile) throws IO
|
|||||||
byteOut.writeTo(blobOut);
|
byteOut.writeTo(blobOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
executeUpdate(connection,
|
executeUpdate(connection,this.concreteSQL.writeMapTile(),
|
||||||
"REPLACE INTO `bluemap_map_tile` (`map`, `lod`, `x`, `z`, `compression`, `data`) " +
|
|
||||||
"VALUES (?, ?, ?, ?, ?, ?)",
|
|
||||||
mapFK,
|
mapFK,
|
||||||
lod,
|
lod,
|
||||||
tile.getX(),
|
tile.getX(),
|
||||||
@ -139,17 +140,7 @@ public Optional<CompressedInputStream> readMapTile(String mapId, int lod, Vector
|
|||||||
try {
|
try {
|
||||||
byte[] data = recoveringConnection(connection -> {
|
byte[] data = recoveringConnection(connection -> {
|
||||||
ResultSet result = executeQuery(connection,
|
ResultSet result = executeQuery(connection,
|
||||||
"SELECT t.`data` " +
|
this.concreteSQL.readMapTile(),
|
||||||
"FROM `bluemap_map_tile` t " +
|
|
||||||
" INNER JOIN `bluemap_map` m " +
|
|
||||||
" ON t.`map` = m.`id` " +
|
|
||||||
" INNER JOIN `bluemap_map_tile_compression` c " +
|
|
||||||
" ON t.`compression` = c.`id` " +
|
|
||||||
"WHERE m.`map_id` = ? " +
|
|
||||||
"AND t.`lod` = ? " +
|
|
||||||
"AND t.`x` = ? " +
|
|
||||||
"AND t.`z` = ? " +
|
|
||||||
"AND c.`compression` = ?",
|
|
||||||
mapId,
|
mapId,
|
||||||
lod,
|
lod,
|
||||||
tile.getX(),
|
tile.getX(),
|
||||||
@ -179,17 +170,7 @@ public Optional<TileInfo> readMapTileInfo(final String mapId, int lod, final Vec
|
|||||||
try {
|
try {
|
||||||
TileInfo tileInfo = recoveringConnection(connection -> {
|
TileInfo tileInfo = recoveringConnection(connection -> {
|
||||||
ResultSet result = executeQuery(connection,
|
ResultSet result = executeQuery(connection,
|
||||||
"SELECT t.`changed`, LENGTH(t.`data`) as 'size' " +
|
this.concreteSQL.readMapTileInfo(),
|
||||||
"FROM `bluemap_map_tile` t " +
|
|
||||||
" INNER JOIN `bluemap_map` m " +
|
|
||||||
" ON t.`map` = m.`id` " +
|
|
||||||
" INNER JOIN `bluemap_map_tile_compression` c " +
|
|
||||||
" ON t.`compression` = c.`id` " +
|
|
||||||
"WHERE m.`map_id` = ? " +
|
|
||||||
"AND t.`lod` = ? " +
|
|
||||||
"AND t.`x` = ? " +
|
|
||||||
"AND t.`z` = ? " +
|
|
||||||
"AND c.`compression` = ?",
|
|
||||||
mapId,
|
mapId,
|
||||||
lod,
|
lod,
|
||||||
tile.getX(),
|
tile.getX(),
|
||||||
@ -238,15 +219,7 @@ public long getLastModified() {
|
|||||||
public void deleteMapTile(String mapId, int lod, Vector2i tile) throws IOException {
|
public void deleteMapTile(String mapId, int lod, Vector2i tile) throws IOException {
|
||||||
try {
|
try {
|
||||||
recoveringConnection(connection ->
|
recoveringConnection(connection ->
|
||||||
executeUpdate(connection,
|
executeUpdate(connection,this.concreteSQL.deleteMapTile(),
|
||||||
"DELETE t " +
|
|
||||||
"FROM `bluemap_map_tile` t " +
|
|
||||||
" INNER JOIN `bluemap_map` m " +
|
|
||||||
" ON t.`map` = m.`id` " +
|
|
||||||
"WHERE m.`map_id` = ? " +
|
|
||||||
"AND t.`lod` = ? " +
|
|
||||||
"AND t.`x` = ? " +
|
|
||||||
"AND t.`z` = ?",
|
|
||||||
mapId,
|
mapId,
|
||||||
lod,
|
lod,
|
||||||
tile.getX(),
|
tile.getX(),
|
||||||
@ -271,8 +244,7 @@ public OutputStream writeMeta(String mapId, String name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
executeUpdate(connection,
|
executeUpdate(connection,
|
||||||
"REPLACE INTO `bluemap_map_meta` (`map`, `key`, `value`) " +
|
this.concreteSQL.writeMeta(),
|
||||||
"VALUES (?, ?, ?)",
|
|
||||||
mapFK,
|
mapFK,
|
||||||
escapeMetaName(name),
|
escapeMetaName(name),
|
||||||
dataBlob
|
dataBlob
|
||||||
@ -289,12 +261,7 @@ public Optional<InputStream> readMeta(String mapId, String name) throws IOExcept
|
|||||||
try {
|
try {
|
||||||
byte[] data = recoveringConnection(connection -> {
|
byte[] data = recoveringConnection(connection -> {
|
||||||
ResultSet result = executeQuery(connection,
|
ResultSet result = executeQuery(connection,
|
||||||
"SELECT t.`value` " +
|
this.concreteSQL.readMeta(),
|
||||||
"FROM `bluemap_map_meta` t " +
|
|
||||||
" INNER JOIN `bluemap_map` m " +
|
|
||||||
" ON t.`map` = m.`id` " +
|
|
||||||
"WHERE m.`map_id` = ? " +
|
|
||||||
"AND t.`key` = ?",
|
|
||||||
mapId,
|
mapId,
|
||||||
escapeMetaName(name)
|
escapeMetaName(name)
|
||||||
);
|
);
|
||||||
@ -319,12 +286,7 @@ public Optional<MetaInfo> readMetaInfo(String mapId, String name) throws IOExcep
|
|||||||
try {
|
try {
|
||||||
MetaInfo tileInfo = recoveringConnection(connection -> {
|
MetaInfo tileInfo = recoveringConnection(connection -> {
|
||||||
ResultSet result = executeQuery(connection,
|
ResultSet result = executeQuery(connection,
|
||||||
"SELECT LENGTH(t.`value`) as 'size' " +
|
this.concreteSQL.readMetaSize(),
|
||||||
"FROM `bluemap_map_meta` t " +
|
|
||||||
" INNER JOIN `bluemap_map` m " +
|
|
||||||
" ON t.`map` = m.`id` " +
|
|
||||||
"WHERE m.`map_id` = ? " +
|
|
||||||
"AND t.`key` = ?",
|
|
||||||
mapId,
|
mapId,
|
||||||
escapeMetaName(name)
|
escapeMetaName(name)
|
||||||
);
|
);
|
||||||
@ -361,12 +323,7 @@ public void deleteMeta(String mapId, String name) throws IOException {
|
|||||||
try {
|
try {
|
||||||
recoveringConnection(connection ->
|
recoveringConnection(connection ->
|
||||||
executeUpdate(connection,
|
executeUpdate(connection,
|
||||||
"DELETE t " +
|
this.concreteSQL.purgeMeta(),
|
||||||
"FROM `bluemap_map_meta` t " +
|
|
||||||
" INNER JOIN `bluemap_map` m " +
|
|
||||||
" ON t.`map` = m.`id` " +
|
|
||||||
"WHERE m.`map_id` = ? " +
|
|
||||||
"AND t.`key` = ?",
|
|
||||||
mapId,
|
mapId,
|
||||||
escapeMetaName(name)
|
escapeMetaName(name)
|
||||||
), 2);
|
), 2);
|
||||||
@ -381,28 +338,18 @@ public void purgeMap(String mapId, Function<ProgressInfo, Boolean> onProgress) t
|
|||||||
try {
|
try {
|
||||||
recoveringConnection(connection -> {
|
recoveringConnection(connection -> {
|
||||||
executeUpdate(connection,
|
executeUpdate(connection,
|
||||||
"DELETE t " +
|
this.concreteSQL.purgeMapTile(),
|
||||||
"FROM `bluemap_map_tile` t " +
|
|
||||||
" INNER JOIN `bluemap_map` m " +
|
|
||||||
" ON t.`map` = m.`id` " +
|
|
||||||
"WHERE m.`map_id` = ?",
|
|
||||||
mapId
|
mapId
|
||||||
);
|
);
|
||||||
|
|
||||||
executeUpdate(connection,
|
executeUpdate(connection,
|
||||||
"DELETE t " +
|
this.concreteSQL.purgeMapMeta(),
|
||||||
"FROM `bluemap_map_meta` t " +
|
|
||||||
" INNER JOIN `bluemap_map` m " +
|
|
||||||
" ON t.`map` = m.`id` " +
|
|
||||||
"WHERE m.`map_id` = ?",
|
|
||||||
mapId
|
mapId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
executeUpdate(connection,
|
executeUpdate(connection,
|
||||||
"DELETE " +
|
this.concreteSQL.purgeMap(),
|
||||||
"FROM `bluemap_map` " +
|
|
||||||
"WHERE `map_id` = ?",
|
|
||||||
mapId
|
mapId
|
||||||
);
|
);
|
||||||
}, 2);
|
}, 2);
|
||||||
@ -420,7 +367,7 @@ public Collection<String> collectMapIds() throws IOException {
|
|||||||
try {
|
try {
|
||||||
return recoveringConnection(connection -> {
|
return recoveringConnection(connection -> {
|
||||||
ResultSet result = executeQuery(connection,
|
ResultSet result = executeQuery(connection,
|
||||||
"SELECT `map_id` FROM `bluemap_map`"
|
this.concreteSQL.selectMapIds()
|
||||||
);
|
);
|
||||||
Collection<String> mapIds = new ArrayList<>();
|
Collection<String> mapIds = new ArrayList<>();
|
||||||
while (result.next()) {
|
while (result.next()) {
|
||||||
@ -440,15 +387,10 @@ public void initialize() throws IOException {
|
|||||||
// initialize and get schema-version
|
// initialize and get schema-version
|
||||||
String schemaVersionString = recoveringConnection(connection -> {
|
String schemaVersionString = recoveringConnection(connection -> {
|
||||||
connection.createStatement().executeUpdate(
|
connection.createStatement().executeUpdate(
|
||||||
"CREATE TABLE IF NOT EXISTS `bluemap_storage_meta` (" +
|
this.concreteSQL.initializeStorageMeta());
|
||||||
"`key` varchar(255) NOT NULL, " +
|
|
||||||
"`value` varchar(255) DEFAULT NULL, " +
|
|
||||||
"PRIMARY KEY (`key`)" +
|
|
||||||
")");
|
|
||||||
|
|
||||||
ResultSet result = executeQuery(connection,
|
ResultSet result = executeQuery(connection,
|
||||||
"SELECT `value` FROM `bluemap_storage_meta` " +
|
this.concreteSQL.selectStorageMeta(),
|
||||||
"WHERE `key` = ?",
|
|
||||||
"schema_version"
|
"schema_version"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -456,8 +398,7 @@ public void initialize() throws IOException {
|
|||||||
return result.getString("value");
|
return result.getString("value");
|
||||||
} else {
|
} else {
|
||||||
executeUpdate(connection,
|
executeUpdate(connection,
|
||||||
"INSERT INTO `bluemap_storage_meta` (`key`, `value`) " +
|
this.concreteSQL.insertStorageMeta(),
|
||||||
"VALUES (?, ?)",
|
|
||||||
"schema_version", "0"
|
"schema_version", "0"
|
||||||
);
|
);
|
||||||
return "0";
|
return "0";
|
||||||
@ -482,51 +423,22 @@ public void initialize() throws IOException {
|
|||||||
recoveringConnection(connection -> {
|
recoveringConnection(connection -> {
|
||||||
|
|
||||||
connection.createStatement().executeUpdate(
|
connection.createStatement().executeUpdate(
|
||||||
"CREATE TABLE `bluemap_map` (" +
|
this.concreteSQL.initializeMap()
|
||||||
"`id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT," +
|
|
||||||
"`map_id` VARCHAR(255) NOT NULL," +
|
|
||||||
"PRIMARY KEY (`id`)," +
|
|
||||||
"UNIQUE INDEX `map_id` (`map_id`)" +
|
|
||||||
");"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
connection.createStatement().executeUpdate(
|
connection.createStatement().executeUpdate(
|
||||||
"CREATE TABLE `bluemap_map_tile_compression` (" +
|
this.concreteSQL.initializeMapTileCompression()
|
||||||
"`id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT," +
|
|
||||||
"`compression` VARCHAR(255) NOT NULL," +
|
|
||||||
"PRIMARY KEY (`id`)," +
|
|
||||||
"UNIQUE INDEX `compression` (`compression`)" +
|
|
||||||
");"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
connection.createStatement().executeUpdate(
|
connection.createStatement().executeUpdate(
|
||||||
"CREATE TABLE `bluemap_map_meta` (" +
|
this.concreteSQL.initializeMapMeta());
|
||||||
"`map` SMALLINT UNSIGNED NOT NULL," +
|
|
||||||
"`key` varchar(255) NOT NULL," +
|
|
||||||
"`value` LONGBLOB NOT NULL," +
|
|
||||||
"PRIMARY KEY (`map`, `key`)," +
|
|
||||||
"CONSTRAINT `fk_bluemap_map_meta_map` FOREIGN KEY (`map`) REFERENCES `bluemap_map` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT" +
|
|
||||||
")");
|
|
||||||
|
|
||||||
connection.createStatement().executeUpdate(
|
connection.createStatement().executeUpdate(
|
||||||
"CREATE TABLE `bluemap_map_tile` (" +
|
this.concreteSQL.initializeMapTile()
|
||||||
"`map` SMALLINT UNSIGNED NOT NULL," +
|
|
||||||
"`lod` SMALLINT UNSIGNED NOT NULL," +
|
|
||||||
"`x` INT NOT NULL," +
|
|
||||||
"`z` INT NOT NULL," +
|
|
||||||
"`compression` SMALLINT UNSIGNED NOT NULL," +
|
|
||||||
"`changed` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP," +
|
|
||||||
"`data` LONGBLOB NOT NULL," +
|
|
||||||
"PRIMARY KEY (`map`, `lod`, `x`, `z`)," +
|
|
||||||
"CONSTRAINT `fk_bluemap_map_tile_map` FOREIGN KEY (`map`) REFERENCES `bluemap_map` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT," +
|
|
||||||
"CONSTRAINT `fk_bluemap_map_tile_compression` FOREIGN KEY (`compression`) REFERENCES `bluemap_map_tile_compression` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT" +
|
|
||||||
");"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
executeUpdate(connection,
|
executeUpdate(connection,
|
||||||
"UPDATE `bluemap_storage_meta` " +
|
this.concreteSQL.updateStorageMeta(),
|
||||||
"SET `value` = ? " +
|
|
||||||
"WHERE `key` = ?",
|
|
||||||
"3", "schema_version"
|
"3", "schema_version"
|
||||||
);
|
);
|
||||||
}, 2);
|
}, 2);
|
||||||
@ -544,36 +456,27 @@ public void initialize() throws IOException {
|
|||||||
|
|
||||||
// delete potential files that are already in the new format to avoid constraint-issues
|
// delete potential files that are already in the new format to avoid constraint-issues
|
||||||
executeUpdate(connection,
|
executeUpdate(connection,
|
||||||
"DELETE FROM `bluemap_map_meta`" +
|
this.concreteSQL.deleteMapMeta(),
|
||||||
"WHERE `key` IN (?, ?, ?)",
|
|
||||||
"settings.json", "textures.json", ".rstate"
|
"settings.json", "textures.json", ".rstate"
|
||||||
);
|
);
|
||||||
|
|
||||||
// rename files
|
// rename files
|
||||||
executeUpdate(connection,
|
executeUpdate(connection,
|
||||||
"UPDATE `bluemap_map_meta` " +
|
this.concreteSQL.updateMapMeta(),
|
||||||
"SET `key` = ? " +
|
|
||||||
"WHERE `key` = ?",
|
|
||||||
"settings.json", "settings"
|
"settings.json", "settings"
|
||||||
);
|
);
|
||||||
executeUpdate(connection,
|
executeUpdate(connection,
|
||||||
"UPDATE `bluemap_map_meta` " +
|
this.concreteSQL.updateMapMeta(),
|
||||||
"SET `key` = ? " +
|
|
||||||
"WHERE `key` = ?",
|
|
||||||
"textures.json", "textures"
|
"textures.json", "textures"
|
||||||
);
|
);
|
||||||
executeUpdate(connection,
|
executeUpdate(connection,
|
||||||
"UPDATE `bluemap_map_meta` " +
|
this.concreteSQL.updateMapMeta(),
|
||||||
"SET `key` = ? " +
|
|
||||||
"WHERE `key` = ?",
|
|
||||||
".rstate", "render_state"
|
".rstate", "render_state"
|
||||||
);
|
);
|
||||||
|
|
||||||
// update schemaVersion
|
// update schemaVersion
|
||||||
executeUpdate(connection,
|
executeUpdate(connection,
|
||||||
"UPDATE `bluemap_storage_meta` " +
|
this.concreteSQL.updateStorageMeta(),
|
||||||
"SET `value` = ? " +
|
|
||||||
"WHERE `key` = ?",
|
|
||||||
"3", "schema_version"
|
"3", "schema_version"
|
||||||
);
|
);
|
||||||
}, 2);
|
}, 2);
|
||||||
@ -699,8 +602,7 @@ private int lookupFK(String table, String idField, String valueField, String val
|
|||||||
int key;
|
int key;
|
||||||
ResultSet result = executeQuery(connection,
|
ResultSet result = executeQuery(connection,
|
||||||
//language=SQL
|
//language=SQL
|
||||||
"SELECT `" + idField + "` FROM `" + table + "` " +
|
this.concreteSQL.lookupFK(table,idField,valueField),
|
||||||
"WHERE `" + valueField + "` = ?",
|
|
||||||
value
|
value
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -708,8 +610,7 @@ private int lookupFK(String table, String idField, String valueField, String val
|
|||||||
key = result.getInt("id");
|
key = result.getInt("id");
|
||||||
} else {
|
} else {
|
||||||
PreparedStatement statement = connection.prepareStatement(
|
PreparedStatement statement = connection.prepareStatement(
|
||||||
"INSERT INTO `" + table + "` (`" + valueField + "`) " +
|
this.concreteSQL.insertFK(table,valueField),
|
||||||
"VALUES (?)",
|
|
||||||
Statement.RETURN_GENERATED_KEYS
|
Statement.RETURN_GENERATED_KEYS
|
||||||
);
|
);
|
||||||
statement.setString(1, value);
|
statement.setString(1, value);
|
||||||
|
@ -0,0 +1,246 @@
|
|||||||
|
package de.bluecolored.bluemap.core.storage.sql.dialect;
|
||||||
|
|
||||||
|
import org.intellij.lang.annotations.Language;
|
||||||
|
|
||||||
|
public class MariaDBFactory implements SQLQueryAbstractFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String writeMapTile() {
|
||||||
|
return "REPLACE INTO `bluemap_map_tile` (`map`, `lod`, `x`, `z`, `compression`, `data`) " +
|
||||||
|
"VALUES (?, ?, ?, ?, ?, ?)";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String readMapTile() {
|
||||||
|
return "SELECT t.`data` " +
|
||||||
|
"FROM `bluemap_map_tile` t " +
|
||||||
|
" INNER JOIN `bluemap_map` m " +
|
||||||
|
" ON t.`map` = m.`id` " +
|
||||||
|
" INNER JOIN `bluemap_map_tile_compression` c " +
|
||||||
|
" ON t.`compression` = c.`id` " +
|
||||||
|
"WHERE m.`map_id` = ? " +
|
||||||
|
"AND t.`lod` = ? " +
|
||||||
|
"AND t.`x` = ? " +
|
||||||
|
"AND t.`z` = ? " +
|
||||||
|
"AND c.`compression` = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String readMapTileInfo() {
|
||||||
|
return "SELECT t.`changed`, LENGTH(t.`data`) as 'size' " +
|
||||||
|
"FROM `bluemap_map_tile` t " +
|
||||||
|
" INNER JOIN `bluemap_map` m " +
|
||||||
|
" ON t.`map` = m.`id` " +
|
||||||
|
" INNER JOIN `bluemap_map_tile_compression` c " +
|
||||||
|
" ON t.`compression` = c.`id` " +
|
||||||
|
"WHERE m.`map_id` = ? " +
|
||||||
|
"AND t.`lod` = ? " +
|
||||||
|
"AND t.`x` = ? " +
|
||||||
|
"AND t.`z` = ? " +
|
||||||
|
"AND c.`compression` = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String deleteMapTile() {
|
||||||
|
return "DELETE t " +
|
||||||
|
"FROM `bluemap_map_tile` t " +
|
||||||
|
" INNER JOIN `bluemap_map` m " +
|
||||||
|
" ON t.`map` = m.`id` " +
|
||||||
|
"WHERE m.`map_id` = ? " +
|
||||||
|
"AND t.`lod` = ? " +
|
||||||
|
"AND t.`x` = ? " +
|
||||||
|
"AND t.`z` = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String writeMeta() {
|
||||||
|
return "REPLACE INTO `bluemap_map_meta` (`map`, `key`, `value`) " +
|
||||||
|
"VALUES (?, ?, ?)";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String readMeta() {
|
||||||
|
return "SELECT t.`value` " +
|
||||||
|
"FROM `bluemap_map_meta` t " +
|
||||||
|
" INNER JOIN `bluemap_map` m " +
|
||||||
|
" ON t.`map` = m.`id` " +
|
||||||
|
"WHERE m.`map_id` = ? " +
|
||||||
|
"AND t.`key` = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String readMetaSize() {
|
||||||
|
return "SELECT LENGTH(t.`value`) as 'size' " +
|
||||||
|
"FROM `bluemap_map_meta` t " +
|
||||||
|
" INNER JOIN `bluemap_map` m " +
|
||||||
|
" ON t.`map` = m.`id` " +
|
||||||
|
"WHERE m.`map_id` = ? " +
|
||||||
|
"AND t.`key` = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String purgeMeta() {
|
||||||
|
return "DELETE t " +
|
||||||
|
"FROM `bluemap_map_meta` t " +
|
||||||
|
" INNER JOIN `bluemap_map` m " +
|
||||||
|
" ON t.`map` = m.`id` " +
|
||||||
|
"WHERE m.`map_id` = ? " +
|
||||||
|
"AND t.`key` = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String purgeMapTile() {
|
||||||
|
return "DELETE t " +
|
||||||
|
"FROM `bluemap_map_tile` t " +
|
||||||
|
" INNER JOIN `bluemap_map` m " +
|
||||||
|
" ON t.`map` = m.`id` " +
|
||||||
|
"WHERE m.`map_id` = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String purgeMapMeta() {
|
||||||
|
return "DELETE t " +
|
||||||
|
"FROM `bluemap_map_meta` t " +
|
||||||
|
" INNER JOIN `bluemap_map` m " +
|
||||||
|
" ON t.`map` = m.`id` " +
|
||||||
|
"WHERE m.`map_id` = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String purgeMap() {
|
||||||
|
return "DELETE " +
|
||||||
|
"FROM `bluemap_map` " +
|
||||||
|
"WHERE `map_id` = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String selectMapIds() {
|
||||||
|
return "SELECT `map_id` FROM `bluemap_map`";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String initializeStorageMeta() {
|
||||||
|
return "CREATE TABLE IF NOT EXISTS `bluemap_storage_meta` (" +
|
||||||
|
"`key` varchar(255) NOT NULL, " +
|
||||||
|
"`value` varchar(255) DEFAULT NULL, " +
|
||||||
|
"PRIMARY KEY (`key`)" +
|
||||||
|
")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String selectStorageMeta() {
|
||||||
|
return "SELECT `value` FROM `bluemap_storage_meta` " +
|
||||||
|
"WHERE `key` = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String insertStorageMeta() {
|
||||||
|
return "INSERT INTO `bluemap_storage_meta` (`key`, `value`) " +
|
||||||
|
"VALUES (?, ?)";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String initializeMap() {
|
||||||
|
return "CREATE TABLE `bluemap_map` (" +
|
||||||
|
"`id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT," +
|
||||||
|
"`map_id` VARCHAR(255) NOT NULL," +
|
||||||
|
"PRIMARY KEY (`id`)," +
|
||||||
|
"UNIQUE INDEX `map_id` (`map_id`)" +
|
||||||
|
");";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String initializeMapTileCompression() {
|
||||||
|
return "CREATE TABLE `bluemap_map_tile_compression` (" +
|
||||||
|
"`id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT," +
|
||||||
|
"`compression` VARCHAR(255) NOT NULL," +
|
||||||
|
"PRIMARY KEY (`id`)," +
|
||||||
|
"UNIQUE INDEX `compression` (`compression`)" +
|
||||||
|
");";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String initializeMapMeta() {
|
||||||
|
return "CREATE TABLE `bluemap_map_meta` (" +
|
||||||
|
"`map` SMALLINT UNSIGNED NOT NULL," +
|
||||||
|
"`key` varchar(255) NOT NULL," +
|
||||||
|
"`value` LONGBLOB NOT NULL," +
|
||||||
|
"PRIMARY KEY (`map`, `key`)," +
|
||||||
|
"CONSTRAINT `fk_bluemap_map_meta_map` FOREIGN KEY (`map`) REFERENCES `bluemap_map` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT" +
|
||||||
|
")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String initializeMapTile() {
|
||||||
|
return "CREATE TABLE `bluemap_map_tile` (" +
|
||||||
|
"`map` SMALLINT UNSIGNED NOT NULL," +
|
||||||
|
"`lod` SMALLINT UNSIGNED NOT NULL," +
|
||||||
|
"`x` INT NOT NULL," +
|
||||||
|
"`z` INT NOT NULL," +
|
||||||
|
"`compression` SMALLINT UNSIGNED NOT NULL," +
|
||||||
|
"`changed` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP," +
|
||||||
|
"`data` LONGBLOB NOT NULL," +
|
||||||
|
"PRIMARY KEY (`map`, `lod`, `x`, `z`)," +
|
||||||
|
"CONSTRAINT `fk_bluemap_map_tile_map` FOREIGN KEY (`map`) REFERENCES `bluemap_map` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT," +
|
||||||
|
"CONSTRAINT `fk_bluemap_map_tile_compression` FOREIGN KEY (`compression`) REFERENCES `bluemap_map_tile_compression` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT" +
|
||||||
|
");";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String updateStorageMeta() {
|
||||||
|
return "UPDATE `bluemap_storage_meta` " +
|
||||||
|
"SET `value` = ? " +
|
||||||
|
"WHERE `key` = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String deleteMapMeta() {
|
||||||
|
return "DELETE FROM `bluemap_map_meta`" +
|
||||||
|
"WHERE `key` IN (?, ?, ?)";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String updateMapMeta() {
|
||||||
|
return "UPDATE `bluemap_map_meta` " +
|
||||||
|
"SET `key` = ? " +
|
||||||
|
"WHERE `key` = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String lookupFK(String table, String idField, String valueField) {
|
||||||
|
return "SELECT `" + idField + "` FROM `" + table + "` " +
|
||||||
|
"WHERE `" + valueField + "` = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Language("MariaDB")
|
||||||
|
public String insertFK(String table, String valueField) {
|
||||||
|
return "INSERT INTO `" + table + "` (`" + valueField + "`) " +
|
||||||
|
"VALUES (?)";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
package de.bluecolored.bluemap.core.storage.sql.dialect;
|
||||||
|
|
||||||
|
import org.intellij.lang.annotations.Language;
|
||||||
|
|
||||||
|
public interface SQLQueryAbstractFactory {
|
||||||
|
@Language("sql")
|
||||||
|
String writeMapTile();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String readMapTile();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String readMapTileInfo();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String deleteMapTile();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String writeMeta();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String readMeta();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String readMetaSize();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String purgeMeta();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String purgeMapTile();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String purgeMapMeta();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String purgeMap();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String selectMapIds();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String initializeStorageMeta();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String selectStorageMeta();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String insertStorageMeta();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String initializeMap();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String initializeMapTileCompression();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String initializeMapMeta();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String initializeMapTile();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String updateStorageMeta(); // can be use twice in init
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String deleteMapMeta();
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String updateMapMeta(); // can be used twice in init
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String lookupFK(String table, String idField, String valueField);
|
||||||
|
|
||||||
|
@Language("sql")
|
||||||
|
String insertFK(String table, String valueField);
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user