Skip to content

Commit eda3c74

Browse files
authored
Remove redundant try-catch in JdbcChatMemoryRepository (#4288)
The inner method JdbcChatMemoryRepositoryDialect#from already contains exception handling logic. The outer try-catch block is unnecessary and can be safely removed to avoid redundant exception handling and improve code clarity. Fixes: #4288 Auto-cherry-pick to 1.0.x Signed-off-by: eeaters <870905780@qq.com>
1 parent 1607eb8 commit eda3c74

File tree

1 file changed

+5
-15
lines changed
  • memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/main/java/org/springframework/ai/chat/memory/repository/jdbc

1 file changed

+5
-15
lines changed

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,7 @@ private DataSource resolveDataSource() {
218218

219219
private JdbcChatMemoryRepositoryDialect resolveDialect(DataSource dataSource) {
220220
if (this.dialect == null) {
221-
try {
222-
return JdbcChatMemoryRepositoryDialect.from(dataSource);
223-
}
224-
catch (Exception ex) {
225-
throw new IllegalStateException("Could not detect dialect from datasource", ex);
226-
}
221+
return JdbcChatMemoryRepositoryDialect.from(dataSource);
227222
}
228223
else {
229224
warnIfDialectMismatch(dataSource, this.dialect);
@@ -236,15 +231,10 @@ private JdbcChatMemoryRepositoryDialect resolveDialect(DataSource dataSource) {
236231
* from the DataSource.
237232
*/
238233
private void warnIfDialectMismatch(DataSource dataSource, JdbcChatMemoryRepositoryDialect explicitDialect) {
239-
try {
240-
JdbcChatMemoryRepositoryDialect detected = JdbcChatMemoryRepositoryDialect.from(dataSource);
241-
if (!detected.getClass().equals(explicitDialect.getClass())) {
242-
logger.warn("Explicitly set dialect {} will be used instead of detected dialect {} from datasource",
243-
explicitDialect.getClass().getSimpleName(), detected.getClass().getSimpleName());
244-
}
245-
}
246-
catch (Exception ex) {
247-
logger.debug("Could not detect dialect from datasource", ex);
234+
JdbcChatMemoryRepositoryDialect detected = JdbcChatMemoryRepositoryDialect.from(dataSource);
235+
if (!detected.getClass().equals(explicitDialect.getClass())) {
236+
logger.warn("Explicitly set dialect {} will be used instead of detected dialect {} from datasource",
237+
explicitDialect.getClass().getSimpleName(), detected.getClass().getSimpleName());
248238
}
249239
}
250240

0 commit comments

Comments
 (0)