Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.infernalsuite.asp.api.loaders.UpdatableLoader;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.jetbrains.annotations.ApiStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -65,18 +66,13 @@ public MysqlLoader(String sqlURL, String host, int port, String database, boolea
hikariConfig.addDataSourceProperty("maintainTimeStats", "false");

source = new HikariDataSource(hikariConfig);
init();
}

try (Connection con = source.getConnection()) {
// Create worlds table
try (PreparedStatement statement = con.prepareStatement(CREATE_WORLDS_TABLE_QUERY)) {
statement.execute();
}

// Create versioning table
try (PreparedStatement statement = con.prepareStatement(CREATE_VERSIONING_TABLE_QUERY)) {
statement.execute();
}
}
@ApiStatus.Experimental
public MysqlLoader(HikariDataSource hikariDataSource) throws SQLException {
source = hikariDataSource;
init();
}

@Override
Expand Down Expand Up @@ -199,4 +195,18 @@ public void deleteWorld(String worldName) throws IOException, UnknownWorldExcept
}
}

private void init() throws SQLException {
try (Connection con = source.getConnection()) {
// Create worlds table
try (PreparedStatement statement = con.prepareStatement(CREATE_WORLDS_TABLE_QUERY)) {
statement.execute();
}

// Create versioning table
try (PreparedStatement statement = con.prepareStatement(CREATE_VERSIONING_TABLE_QUERY)) {
statement.execute();
}
}
}

}