try to fix issues with HomeProjectService

Signed-off-by: MiniDigger <admin@benndorf.dev>
This commit is contained in:
MiniDigger 2021-12-17 21:45:14 +01:00
parent f3da597397
commit 3f863253c1

View File

@ -2,6 +2,8 @@ package io.papermc.hangar.service.internal.projects;
import com.impossibl.postgres.jdbc.PGDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@ -11,12 +13,14 @@ import java.sql.SQLException;
@Service
public class HomeProjectService {
private static final Logger logger = LoggerFactory.getLogger(HomeProjectService.class);
private final String url;
private final String username;
private final String password;
public HomeProjectService(@Value("${spring.datasource.url}") String url, @Value("${spring.datasource.username}") String username, @Value("${spring.datasource.password}") String password) {
this.url = url;
this.url = url.replace("postgresql", "pgsql");
this.username = username;
this.password = password;
}
@ -24,7 +28,7 @@ public class HomeProjectService {
private Connection getConnection() throws SQLException {
// force using pgjdbc-ng since that doesn't do dum begin queries that break cockroach
PGDataSource ds = new PGDataSource();
ds.setDatabaseUrl(url.replace("postgresql", "pgsql"));
ds.setDatabaseUrl(url);
// ds.setSqlTrace(true);
return ds.getConnection(username, password);
}
@ -35,7 +39,11 @@ public class HomeProjectService {
var stmt = con.createStatement()) {
stmt.execute("REFRESH MATERIALIZED VIEW home_projects");
} catch (SQLException e) {
e.printStackTrace();
if (e.getMessage().contains("Unsupported database URL")) {
logger.warn("Unsupported database URL: {}", url);
} else {
e.printStackTrace();
}
}
}
}