feat(rds-data): adding data-api for postgresql (#1720)

* feat(rds-data): adding data-api for postgresql

* Moving wrongly place test file under src/test
This commit is contained in:
Anders Wasen authored and GitHub committed 2026-07-05 09:05:04 -05:00
1 parent 068b76a195
commit 272e4136e5
5 files changed
+589 -11

No files matched your search

@@ -1,6 +1,5 @@
package io.github.hectorvent.floci.services.rdsdata;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.rds.model.DatabaseEngine;
import jakarta.enterprise.context.ApplicationScoped;
@@ -16,16 +15,28 @@ class RdsDataConnectionFactory {
String username,
String password,
String database) throws SQLException {
if (target.engine() != DatabaseEngine.MYSQL && target.engine() != DatabaseEngine.MARIADB) {
throw new AwsException("BadRequestException",
"RDS Data API currently supports local MySQL and MariaDB resources only.", 400);
}
String url = "jdbc:mysql://" + target.host() + ":" + target.port() + "/" + database
+ "?useSSL=false&allowPublicKeyRetrieval=true";
String url = buildUrl(target.engine(), target.host(), target.port(), database);
Properties props = new Properties();
props.setProperty("user", username);
props.setProperty("password", password);
props.setProperty("connectTimeout", "5000");
props.setProperty("connectTimeout", connectTimeout(target.engine()));
return DriverManager.getConnection(url, props);
}
static String buildUrl(DatabaseEngine engine, String host, int port, String database) {
return switch (engine) {
case MYSQL, MARIADB -> "jdbc:mysql://" + host + ":" + port + "/" + database
+ "?useSSL=false&allowPublicKeyRetrieval=true";
case POSTGRES -> "jdbc:postgresql://" + host + ":" + port + "/" + database
+ "?sslmode=disable";
};
}
private static String connectTimeout(DatabaseEngine engine) {
// MySQL Connector/J expects milliseconds; the PostgreSQL driver expects seconds.
return switch (engine) {
case MYSQL, MARIADB -> "5000";
case POSTGRES -> "5";
};
}
}