Skip to content

Commit

Permalink
Set default for poolName and executorService
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim203 committed Feb 11, 2024
1 parent aad5cb6 commit 4262164
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/org/geysermc/databaseutils/DatabaseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.geysermc.databaseutils.codec.TypeCodec;
import org.geysermc.databaseutils.codec.TypeCodecRegistry;
import org.geysermc.databaseutils.sql.SqlDialect;
Expand Down Expand Up @@ -78,7 +79,7 @@ public static class Builder {
private String uri;
private String username;
private String password;
private String poolName;
private String poolName = "database-utils";
private int connectionPoolSize = 0;
private SqlDialect dialect;

Expand Down Expand Up @@ -202,6 +203,11 @@ public DatabaseUtils build() {
"Cannot use credentialsFile in combination with not using default credentials");
}

var service = executorService;
if (service == null) {
service = Executors.newCachedThreadPool();
}

var actual = config;
if (credentialsFile != null) {
actual = new CredentialsFileHandler().handle(dialect, credentialsFile);
Expand All @@ -211,7 +217,7 @@ public DatabaseUtils build() {
actual = new DatabaseConfig(uri, username, password, connectionPoolSize);
}

return new DatabaseUtils(new DatabaseContext(actual, poolName, dialect, executorService, registry));
return new DatabaseUtils(new DatabaseContext(actual, poolName, dialect, service, registry));
}
}
}
2 changes: 0 additions & 2 deletions core/src/test/java/org/geysermc/databaseutils/SqlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ final class SqlTest {
void hello() throws ExecutionException, InterruptedException {
var utils = DatabaseUtils.builder()
.useDefaultCredentials(true)
.poolName("test")
.connectionPoolSize(2)
.dialect(SqlDialect.H2)
.executorService(Executors.newCachedThreadPool())
.build();
Expand Down

0 comments on commit 4262164

Please sign in to comment.