Skip to content

Commit ae41f04

Browse files
committed
fix: Fix UT
Signed-off-by: Sun Yuhan <[email protected]>
1 parent 7518f0f commit ae41f04

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/main/java/org/springframework/ai/chat/memory/repository/jdbc/JdbcChatMemoryRepositoryDialect.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@
2020

2121
import javax.sql.DataSource;
2222

23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
2326
import org.springframework.jdbc.support.JdbcUtils;
2427

2528
/**
2629
* Abstraction for database-specific SQL for chat memory repository.
2730
*/
2831
public interface JdbcChatMemoryRepositoryDialect {
2932

33+
Logger logger = LoggerFactory.getLogger(JdbcChatMemoryRepositoryDialect.class);
34+
3035
/**
3136
* Returns the SQL to fetch messages for a conversation, ordered by timestamp, with
3237
* limit.
@@ -56,12 +61,17 @@ public interface JdbcChatMemoryRepositoryDialect {
5661
* Detects the dialect from the DataSource.
5762
*/
5863
static JdbcChatMemoryRepositoryDialect from(DataSource dataSource) {
59-
String productName;
64+
String productName = null;
6065
try {
6166
productName = JdbcUtils.extractDatabaseMetaData(dataSource, DatabaseMetaData::getDatabaseProductName);
6267
}
6368
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();
6575
}
6676
return switch (productName) {
6777
case "PostgreSQL" -> new PostgresChatMemoryRepositoryDialect();

0 commit comments

Comments
 (0)