Skip to content

Commit

Permalink
add more config
Browse files Browse the repository at this point in the history
  • Loading branch information
InkerBot committed Aug 23, 2024
1 parent 3b4de9d commit 6d47fe5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions database/src/main/java/org/inksnow/cputil/db/AuroraDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Driver;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public class AuroraDatabase extends HikariDataSource {
Expand All @@ -32,6 +34,8 @@ public static Builder builder() {

public static final class Builder {
private static final Path DEFAULT_CACHE_DIRECTORY = Paths.get("plugins", ".aurora", "cache");
private final List<Consumer<HikariConfig>> extensions = new ArrayList<>();

private Path cacheDirectory = DEFAULT_CACHE_DIRECTORY;
private String jdbcUrl;
private Properties driverProperties = new Properties();
Expand Down Expand Up @@ -72,6 +76,15 @@ public Builder databaseType(Database databaseType) {
return this;
}

public Builder extension(Consumer<HikariConfig> extension) {
extensions.add(extension);
return this;
}

public Builder clearExtensions() {
extensions.clear();
return this;
}

private List<Path> downloadDriverClasses() throws IOException {
if (databaseType == null) {
Expand Down Expand Up @@ -112,6 +125,7 @@ private HikariConfig createConfig(Class<? extends Driver> driverClass) {
config.setPassword(driverProperties.getProperty(PASSWORD));
config.setMaximumPoolSize(Math.min(4, Runtime.getRuntime().availableProcessors() * 2));
config.setPoolName("aurora-pool");
extensions.forEach(it -> it.accept(config));
return config;
}

Expand Down

0 comments on commit 6d47fe5

Please sign in to comment.