mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-12-23 01:21:47 +00:00
parent
a8f589c1b7
commit
8d459220d3
@ -209,6 +209,10 @@ public class ShopChest extends JavaPlugin {
|
||||
debug("Removed shop (#" + shop.getID() + ")");
|
||||
}
|
||||
|
||||
if (database instanceof SQLite) {
|
||||
((SQLite) database).vacuum(false);
|
||||
}
|
||||
|
||||
database.disconnect();
|
||||
}
|
||||
|
||||
|
@ -537,14 +537,14 @@ public abstract class Database {
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes a {@link PreparedStatement} and a {@link ResultSet}
|
||||
* @param ps {@link PreparedStatement} to close
|
||||
* Closes a {@link Statement} and a {@link ResultSet}
|
||||
* @param s {@link Statement} to close
|
||||
* @param rs {@link ResultSet} to close
|
||||
*/
|
||||
private void close(PreparedStatement ps, ResultSet rs) {
|
||||
void close(Statement s, ResultSet rs) {
|
||||
try {
|
||||
if (ps != null)
|
||||
ps.close();
|
||||
if (s != null)
|
||||
s.close();
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
} catch (SQLException ex) {
|
||||
|
@ -1,12 +1,15 @@
|
||||
package de.epiceric.shopchest.sql;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class SQLite extends Database {
|
||||
|
||||
@ -46,4 +49,36 @@ public class SQLite extends Database {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vacuums the database to reduce file size
|
||||
* @param async Whether the call should be executed asynchronously
|
||||
*/
|
||||
public void vacuum(boolean async) {
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Statement s = null;
|
||||
|
||||
try {
|
||||
s = connection.createStatement();
|
||||
s.executeUpdate("VACUUM");
|
||||
|
||||
plugin.debug("Vacuumed SQLite database");
|
||||
} catch (final SQLException ex) {
|
||||
plugin.getLogger().severe("Failed to access database");
|
||||
plugin.debug("Failed to vacuum database");
|
||||
plugin.debug(ex);
|
||||
} finally {
|
||||
close(s, null);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (async) {
|
||||
runnable.runTaskAsynchronously(plugin);
|
||||
} else {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user