mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-11-14 22:55:15 +01:00
Fix tile-saving errors after reloading bluemap with sql storage
This commit is contained in:
parent
60a8f5f98e
commit
98780514c6
@ -84,6 +84,12 @@ private LowresTile createTile(Vector2i tilePos) {
|
||||
private void saveTile(Vector2i tilePos, @Nullable LowresTile tile, RemovalCause removalCause) {
|
||||
if (tile == null) return;
|
||||
|
||||
// check if storage is closed
|
||||
if (mapStorage.getStorage().isClosed()){
|
||||
Logger.global.logDebug("Tried to save tile " + tilePos + " (lod: " + lod + ") but storage is already closed.");
|
||||
return;
|
||||
}
|
||||
|
||||
// save the tile
|
||||
try (OutputStream out = mapStorage.write(lod, tilePos)) {
|
||||
tile.save(out);
|
||||
|
@ -59,6 +59,8 @@ public TileStorage tileStorage(final String mapId, final int lod) {
|
||||
return new TileStorage(mapId, lod);
|
||||
}
|
||||
|
||||
public abstract boolean isClosed();
|
||||
|
||||
public class MapStorage {
|
||||
|
||||
private final String mapId;
|
||||
@ -79,6 +81,10 @@ public void delete(int lod, Vector2i tile) throws IOException {
|
||||
deleteMapTile(mapId, lod, tile);
|
||||
}
|
||||
|
||||
public Storage getStorage() {
|
||||
return Storage.this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class TileStorage {
|
||||
@ -103,6 +109,10 @@ public void delete(Vector2i tile) throws IOException {
|
||||
deleteMapTile(mapId, lod, tile);
|
||||
}
|
||||
|
||||
public Storage getStorage() {
|
||||
return Storage.this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -57,6 +57,11 @@ public FileStorage(Path root, Compression compression) {
|
||||
@Override
|
||||
public void initialize() {}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {}
|
||||
|
||||
|
@ -61,7 +61,11 @@ public class SQLStorage extends Storage {
|
||||
.executor(BlueMap.THREAD_POOL)
|
||||
.build(this::loadMapTileCompressionFK);
|
||||
|
||||
private volatile boolean closed;
|
||||
|
||||
public SQLStorage(SQLStorageSettings config) throws MalformedURLException, SQLDriverException {
|
||||
this.closed = false;
|
||||
|
||||
try {
|
||||
if (config.getDriverClass().isPresent()) {
|
||||
if (config.getDriverJar().isPresent()) {
|
||||
@ -478,8 +482,14 @@ public void initialize() throws IOException {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return closed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
this.closed = true;
|
||||
if (dataSource instanceof AutoCloseable) {
|
||||
try {
|
||||
((AutoCloseable) dataSource).close();
|
||||
|
Loading…
Reference in New Issue
Block a user