Skip to content

Commit

Permalink
style: optimize imports in database related classes
Browse files Browse the repository at this point in the history
SpraxDev committed Oct 23, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 2f6d21c commit 8cde264
Showing 4 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Core/src/main/java/com/craftaro/core/SongodaPlugin.java
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@
import java.sql.Connection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;

public abstract class SongodaPlugin extends JavaPlugin {
@@ -281,6 +280,7 @@ protected void initDatabase(List<DataMigration> migrations) {
} else {
this.dataManager = new DataManager(this, migrations);
}

if (dataManager.getDatabaseConnector().isInitialized()) {
//Check if the type is SQLite
if (dataManager.getDatabaseConnector().getType() == DatabaseType.SQLITE) {
34 changes: 18 additions & 16 deletions Core/src/main/java/com/craftaro/core/database/DataManager.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package com.craftaro.core.database;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.craftaro.core.SongodaPlugin;
import com.craftaro.core.configuration.Config;
import org.bukkit.Bukkit;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.jetbrains.annotations.NotNull;
import org.jooq.Condition;
import org.jooq.Field;
import org.jooq.Query;
import org.jooq.Record;
import org.jooq.impl.DSL;

import java.io.File;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -22,13 +18,11 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
@@ -47,7 +41,7 @@ public class DataManager {
protected DatabaseType type;
private final Map<String, AtomicInteger> autoIncrementCache = new HashMap<>();

protected final ExecutorService asyncPool = new ThreadPoolExecutor(1, 5, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat(getClass().getSimpleName()+"-Database-Async-%d").build());
protected final ExecutorService asyncPool = new ThreadPoolExecutor(1, 5, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat(getClass().getSimpleName() + "-Database-Async-%d").build());

@Deprecated
private static final Map<String, LinkedList<Runnable>> queues = new HashMap<>();
@@ -206,7 +200,6 @@ public void runMigrations() throws SQLException {
statement.execute();
}
}

}

/**
@@ -368,7 +361,9 @@ public void delete(Data data, String uuidColumn) {

/**
* Loads the data from the database
*
* @param id The id of the data
*
* @return The loaded data
*/
@SuppressWarnings("unchecked")
@@ -402,9 +397,11 @@ public <T extends Data> T load(int id, Class<?> clazz, String table) {

/**
* Loads the data from the database
* @param uuid The uuid of the data
*
* @param uuid The uuid of the data
* @param clazz The class of the data
* @param table The table of the data without prefix
*
* @return The loaded data
*/
@SuppressWarnings("unchecked")
@@ -438,10 +435,12 @@ public <T extends Data> T load(UUID uuid, Class<?> clazz, String table) {

/**
* Loads the data from the database
* @param uuid The uuid of the data
* @param clazz The class of the data
* @param table The table of the data without prefix
*
* @param uuid The uuid of the data
* @param clazz The class of the data
* @param table The table of the data without prefix
* @param uuidColumn The column of the uuid
*
* @return The loaded data
*/
@SuppressWarnings("unchecked")
@@ -475,6 +474,7 @@ public <T extends Data> T load(UUID uuid, Class<?> clazz, String table, String u

/**
* Loads the data in batch from the database
*
* @return The loaded data
*/
@SuppressWarnings("unchecked")
@@ -486,7 +486,7 @@ public <T extends Data> List<T> loadBatch(Class<?> clazz, String table) {
for (@NotNull Record record : Objects.requireNonNull(context.select()
.from(DSL.table(getTablePrefix() + table))
.fetchArray())) {
Data data = (Data)clazz.getDeclaredConstructor().newInstance();
Data data = (Data) clazz.getDeclaredConstructor().newInstance();
dataList.add(data.deserialize(record.intoMap()));
}
} catch (Exception ex) {
@@ -501,6 +501,7 @@ public <T extends Data> List<T> loadBatch(Class<?> clazz, String table) {

/**
* Loads the data in batch from the database
*
* @return The loaded data
*/
@SuppressWarnings("unchecked")
@@ -511,9 +512,9 @@ public <T extends Data> List<T> loadBatch(Class<?> clazz, String table, Conditio
try {
for (@NotNull Record record : Objects.requireNonNull(context.select()
.from(DSL.table(getTablePrefix() + table))
.where(conditions)
.where(conditions)
.fetchArray())) {
Data data = (Data)clazz.getDeclaredConstructor().newInstance();
Data data = (Data) clazz.getDeclaredConstructor().newInstance();
dataList.add(data.deserialize(record.intoMap()));
}
} catch (Exception ex) {
@@ -536,6 +537,7 @@ public void shutdown() {

/**
* Force shutdown the async pool and close the database
*
* @return Tasks that didn't finish in the async pool
*/
public List<Runnable> shutdownNow() {
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package com.craftaro.core.database;

import com.craftaro.core.SongodaCore;
import com.craftaro.core.SongodaPlugin;

import java.io.File;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public abstract class DataMigration {
private final int revision;
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.craftaro.core.database;

import com.craftaro.core.SongodaCore;
import eu.decentsoftware.holograms.api.utils.scheduler.S;
import org.bukkit.plugin.Plugin;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;

0 comments on commit 8cde264

Please sign in to comment.