mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 15:44:49 +08:00
Refactored WorldTable
This commit is contained in:
parent
94ba4fa0e9
commit
5433116cdb
@ -3,10 +3,11 @@ package main.java.com.djrapitops.plan.database.tables;
|
|||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
|
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||||
|
import main.java.com.djrapitops.plan.database.processing.ExecStatement;
|
||||||
|
import main.java.com.djrapitops.plan.database.processing.QueryAllStatement;
|
||||||
import main.java.com.djrapitops.plan.database.sql.Sql;
|
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||||
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -25,7 +26,6 @@ public class WorldTable extends Table {
|
|||||||
public final String statementSelectID;
|
public final String statementSelectID;
|
||||||
private final String columnWorldId = "id";
|
private final String columnWorldId = "id";
|
||||||
private final String columnWorldName = "world_name";
|
private final String columnWorldName = "world_name";
|
||||||
private final String columnServerID = "server_id";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -55,20 +55,19 @@ public class WorldTable extends Table {
|
|||||||
* @throws SQLException Database error occurs.
|
* @throws SQLException Database error occurs.
|
||||||
*/
|
*/
|
||||||
public List<String> getWorlds() throws SQLException {
|
public List<String> getWorlds() throws SQLException {
|
||||||
PreparedStatement statement = null;
|
String sql = "SELECT * FROM " + tableName;
|
||||||
ResultSet set = null;
|
|
||||||
try (Connection connection = getConnection()) {
|
return query(new QueryAllStatement<List<String>>(sql) {
|
||||||
statement = connection.prepareStatement("SELECT * FROM " + tableName);
|
@Override
|
||||||
set = statement.executeQuery();
|
public List<String> processResults(ResultSet set) throws SQLException {
|
||||||
List<String> worldNames = new ArrayList<>();
|
List<String> worldNames = new ArrayList<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
String worldName = set.getString(columnWorldName);
|
String worldName = set.getString(columnWorldName);
|
||||||
worldNames.add(worldName);
|
worldNames.add(worldName);
|
||||||
|
}
|
||||||
|
return worldNames;
|
||||||
}
|
}
|
||||||
return worldNames;
|
});
|
||||||
} finally {
|
|
||||||
close(set, statement);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,21 +88,19 @@ public class WorldTable extends Table {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PreparedStatement statement = null;
|
String sql = "INSERT INTO " + tableName + " ("
|
||||||
try (Connection connection = getConnection()) {
|
+ columnWorldName
|
||||||
statement = connection.prepareStatement("INSERT INTO " + tableName + " ("
|
+ ") VALUES (?)";
|
||||||
+ columnWorldName
|
|
||||||
+ ") VALUES (?)");
|
|
||||||
for (String world : worldsToSave) {
|
|
||||||
statement.setString(1, world);
|
|
||||||
statement.addBatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
statement.executeBatch();
|
executeBatch(new ExecStatement(sql) {
|
||||||
commit(connection);
|
@Override
|
||||||
} finally {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
close(statement);
|
for (String world : worldsToSave) {
|
||||||
}
|
statement.setString(1, world);
|
||||||
|
statement.addBatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getColumnID() {
|
public String getColumnID() {
|
||||||
|
Loading…
Reference in New Issue
Block a user