mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-23 07:41:19 +01:00
Didn't add this to last commit for some reason
This commit is contained in:
parent
18a0d26fc5
commit
9bbb0b49c3
@ -66,7 +66,7 @@ public abstract class SQLDB extends Database {
|
|||||||
*/
|
*/
|
||||||
public void startConnectionPingTask(Plan plugin) throws IllegalArgumentException, IllegalStateException {
|
public void startConnectionPingTask(Plan plugin) throws IllegalArgumentException, IllegalStateException {
|
||||||
// Maintains Connection.
|
// Maintains Connection.
|
||||||
new RslBukkitRunnable<Plan>("DBConnectionPingTask "+getName()) {
|
new RslBukkitRunnable<Plan>("DBConnectionPingTask " + getName()) {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@ -87,12 +87,14 @@ public abstract class SQLDB extends Database {
|
|||||||
@Override
|
@Override
|
||||||
public boolean init() {
|
public boolean init() {
|
||||||
super.init();
|
super.init();
|
||||||
|
setStatus("Init");
|
||||||
Benchmark.start("Database Init " + getConfigName());
|
Benchmark.start("Database Init " + getConfigName());
|
||||||
try {
|
try {
|
||||||
if (!checkConnection()) {
|
if (!checkConnection()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
convertBukkitDataToDB();
|
convertBukkitDataToDB();
|
||||||
|
clean();
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass().getName(), e);
|
||||||
@ -158,6 +160,7 @@ public abstract class SQLDB extends Database {
|
|||||||
Log.debug("No conversion necessary.");
|
Log.debug("No conversion necessary.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
setStatus("Bukkit Data Conversion");
|
||||||
Log.info("Beginning Bukkit Data -> DB Conversion for " + uuids.size() + " players");
|
Log.info("Beginning Bukkit Data -> DB Conversion for " + uuids.size() + " players");
|
||||||
int id = plugin.getBootAnalysisTaskID();
|
int id = plugin.getBootAnalysisTaskID();
|
||||||
if (id != -1) {
|
if (id != -1) {
|
||||||
@ -169,6 +172,7 @@ public abstract class SQLDB extends Database {
|
|||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
Log.toLog(this.getClass().getName(), ex);
|
Log.toLog(this.getClass().getName(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
|
setAvailable();
|
||||||
this.cancel();
|
this.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,7 +184,7 @@ public abstract class SQLDB extends Database {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Table[] getAllTables() {
|
public Table[] getAllTables() {
|
||||||
return new Table[]{usersTable, locationsTable, gmTimesTable, ipsTable, nicknamesTable, sessionsTable, killsTable, commandUseTable};
|
return new Table[]{usersTable, locationsTable, gmTimesTable, ipsTable, nicknamesTable, sessionsTable, killsTable, commandUseTable, tpsTable};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -188,7 +192,7 @@ public abstract class SQLDB extends Database {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Table[] getAllTablesInRemoveOrder() {
|
public Table[] getAllTablesInRemoveOrder() {
|
||||||
return new Table[]{locationsTable, gmTimesTable, ipsTable, nicknamesTable, sessionsTable, killsTable, usersTable, commandUseTable};
|
return new Table[]{locationsTable, gmTimesTable, ipsTable, nicknamesTable, sessionsTable, killsTable, usersTable, commandUseTable, tpsTable};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -206,6 +210,7 @@ public abstract class SQLDB extends Database {
|
|||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
connection.close();
|
connection.close();
|
||||||
}
|
}
|
||||||
|
setStatus("Closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -237,11 +242,14 @@ public abstract class SQLDB extends Database {
|
|||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
setStatus("User exist check");
|
||||||
try {
|
try {
|
||||||
return usersTable.getUserId(uuid.toString()) != -1;
|
return usersTable.getUserId(uuid.toString()) != -1;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass().getName(), e);
|
||||||
return false;
|
return false;
|
||||||
|
} finally {
|
||||||
|
setAvailable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,6 +265,7 @@ public abstract class SQLDB extends Database {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
setStatus("Remove account " + uuid);
|
||||||
Benchmark.start("Database remove Account " + uuid);
|
Benchmark.start("Database remove Account " + uuid);
|
||||||
try {
|
try {
|
||||||
checkConnection();
|
checkConnection();
|
||||||
@ -277,6 +286,7 @@ public abstract class SQLDB extends Database {
|
|||||||
&& usersTable.removeUser(uuid);
|
&& usersTable.removeUser(uuid);
|
||||||
} finally {
|
} finally {
|
||||||
Benchmark.stop("Database remove Account " + uuid);
|
Benchmark.stop("Database remove Account " + uuid);
|
||||||
|
setAvailable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,6 +309,7 @@ public abstract class SQLDB extends Database {
|
|||||||
if (!wasSeenBefore(uuid)) {
|
if (!wasSeenBefore(uuid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
setStatus("Get single userdata for " + uuid);
|
||||||
// Get the data
|
// Get the data
|
||||||
UserData data = usersTable.getUserData(uuid);
|
UserData data = usersTable.getUserData(uuid);
|
||||||
|
|
||||||
@ -322,6 +333,7 @@ public abstract class SQLDB extends Database {
|
|||||||
processor.process(data);
|
processor.process(data);
|
||||||
});
|
});
|
||||||
Benchmark.stop("DB Give userdata to processors");
|
Benchmark.stop("DB Give userdata to processors");
|
||||||
|
setAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -335,7 +347,7 @@ public abstract class SQLDB extends Database {
|
|||||||
if (uuidsCol == null || uuidsCol.isEmpty()) {
|
if (uuidsCol == null || uuidsCol.isEmpty()) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
setStatus("Get userdata (multiple) for: " + uuidsCol.size());
|
||||||
Benchmark.start("DB get UserData for " + uuidsCol.size());
|
Benchmark.start("DB get UserData for " + uuidsCol.size());
|
||||||
Map<UUID, Integer> userIds = usersTable.getAllUserIds();
|
Map<UUID, Integer> userIds = usersTable.getAllUserIds();
|
||||||
Set<UUID> remove = uuidsCol.stream()
|
Set<UUID> remove = uuidsCol.stream()
|
||||||
@ -368,6 +380,7 @@ public abstract class SQLDB extends Database {
|
|||||||
uData.setGmTimes(gmTimesTable.getGMTimes(id));
|
uData.setGmTimes(gmTimesTable.getGMTimes(id));
|
||||||
}
|
}
|
||||||
Benchmark.stop("DB get UserData for " + uuidsCol.size());
|
Benchmark.stop("DB get UserData for " + uuidsCol.size());
|
||||||
|
setAvailable();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,6 +396,7 @@ public abstract class SQLDB extends Database {
|
|||||||
if (data.isEmpty()) {
|
if (data.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
setStatus("Save userdata (multiple) for " + data.size());
|
||||||
usersTable.saveUserDataInformationBatch(data);
|
usersTable.saveUserDataInformationBatch(data);
|
||||||
// Transform to map
|
// Transform to map
|
||||||
Map<UUID, UserData> userDatas = data.stream().collect(Collectors.toMap(UserData::getUuid, Function.identity()));
|
Map<UUID, UserData> userDatas = data.stream().collect(Collectors.toMap(UserData::getUuid, Function.identity()));
|
||||||
@ -432,6 +446,7 @@ public abstract class SQLDB extends Database {
|
|||||||
uData.stopAccessing();
|
uData.stopAccessing();
|
||||||
});
|
});
|
||||||
Benchmark.stop("DB Save multiple Userdata");
|
Benchmark.stop("DB Save multiple Userdata");
|
||||||
|
setAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -448,6 +463,7 @@ public abstract class SQLDB extends Database {
|
|||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
setStatus("Save userdata: " + uuid);
|
||||||
checkConnection();
|
checkConnection();
|
||||||
Log.debug("DB_Save: " + data);
|
Log.debug("DB_Save: " + data);
|
||||||
data.access();
|
data.access();
|
||||||
@ -460,6 +476,7 @@ public abstract class SQLDB extends Database {
|
|||||||
killsTable.savePlayerKills(userId, new ArrayList<>(data.getPlayerKills()));
|
killsTable.savePlayerKills(userId, new ArrayList<>(data.getPlayerKills()));
|
||||||
gmTimesTable.saveGMTimes(userId, data.getGmTimes());
|
gmTimesTable.saveGMTimes(userId, data.getGmTimes());
|
||||||
data.stopAccessing();
|
data.stopAccessing();
|
||||||
|
setAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -470,8 +487,8 @@ public abstract class SQLDB extends Database {
|
|||||||
Log.info("Cleaning the database.");
|
Log.info("Cleaning the database.");
|
||||||
try {
|
try {
|
||||||
checkConnection();
|
checkConnection();
|
||||||
commandUseTable.clean();
|
tpsTable.clean();
|
||||||
sessionsTable.clean();
|
// sessionsTable.clean();
|
||||||
Log.info("Clean complete.");
|
Log.info("Clean complete.");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass().getName(), e);
|
||||||
@ -484,11 +501,13 @@ public abstract class SQLDB extends Database {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean removeAllData() {
|
public boolean removeAllData() {
|
||||||
|
setStatus("Clearing all data");
|
||||||
for (Table table : getAllTablesInRemoveOrder()) {
|
for (Table table : getAllTablesInRemoveOrder()) {
|
||||||
if (!table.removeAllData()) {
|
if (!table.removeAllData()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setAvailable();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,4 +526,12 @@ public abstract class SQLDB extends Database {
|
|||||||
public Connection getConnection() {
|
public Connection getConnection() {
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setStatus(String status) {
|
||||||
|
plugin.processStatus().setStatus("DB-" + getName(), status);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setAvailable() {
|
||||||
|
setStatus("Running");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user