|
20 | 20 |
|
21 | 21 | import javax.sql.DataSource; |
22 | 22 |
|
| 23 | +import org.slf4j.Logger; |
| 24 | +import org.slf4j.LoggerFactory; |
| 25 | + |
23 | 26 | import org.springframework.jdbc.support.JdbcUtils; |
24 | 27 |
|
25 | 28 | /** |
26 | 29 | * Abstraction for database-specific SQL for chat memory repository. |
27 | 30 | */ |
28 | 31 | public interface JdbcChatMemoryRepositoryDialect { |
29 | 32 |
|
| 33 | + Logger logger = LoggerFactory.getLogger(JdbcChatMemoryRepositoryDialect.class); |
| 34 | + |
30 | 35 | /** |
31 | 36 | * Returns the SQL to fetch messages for a conversation, ordered by timestamp, with |
32 | 37 | * limit. |
@@ -56,12 +61,17 @@ public interface JdbcChatMemoryRepositoryDialect { |
56 | 61 | * Detects the dialect from the DataSource. |
57 | 62 | */ |
58 | 63 | static JdbcChatMemoryRepositoryDialect from(DataSource dataSource) { |
59 | | - String productName; |
| 64 | + String productName = null; |
60 | 65 | try { |
61 | 66 | productName = JdbcUtils.extractDatabaseMetaData(dataSource, DatabaseMetaData::getDatabaseProductName); |
62 | 67 | } |
63 | 68 | catch (Exception e) { |
64 | | - throw new RuntimeException("Failed to obtain JDBC product name or establish JDBC connection", e); |
| 69 | + logger.warn("Due to failure in establishing JDBC connection or parsing metadata, the JDBC database vendor " |
| 70 | + + "could not be determined", e); |
| 71 | + } |
| 72 | + if (productName == null || productName.trim().isEmpty()) { |
| 73 | + logger.warn("Database product name is null or empty, defaulting to Postgres dialect."); |
| 74 | + return new PostgresChatMemoryRepositoryDialect(); |
65 | 75 | } |
66 | 76 | return switch (productName) { |
67 | 77 | case "PostgreSQL" -> new PostgresChatMemoryRepositoryDialect(); |
|
0 commit comments