Fix datasource connection leak when using the JdbcChatMemoryRepository
Signed-off-by: Dan Sarlo <81384153+dsarlo-viso@users.noreply.github.com>
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package org.springframework.ai.chat.memory.repository.jdbc;
|
package org.springframework.ai.chat.memory.repository.jdbc;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstraction for database-specific SQL for chat memory repository.
|
* Abstraction for database-specific SQL for chat memory repository.
|
||||||
@@ -53,8 +54,8 @@ public interface JdbcChatMemoryRepositoryDialect {
|
|||||||
*/
|
*/
|
||||||
static JdbcChatMemoryRepositoryDialect from(DataSource dataSource) {
|
static JdbcChatMemoryRepositoryDialect from(DataSource dataSource) {
|
||||||
// Simple detection (could be improved)
|
// Simple detection (could be improved)
|
||||||
try {
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
String url = dataSource.getConnection().getMetaData().getURL().toLowerCase();
|
String url = connection.getMetaData().getURL().toLowerCase();
|
||||||
if (url.contains("postgresql")) {
|
if (url.contains("postgresql")) {
|
||||||
return new PostgresChatMemoryRepositoryDialect();
|
return new PostgresChatMemoryRepositoryDialect();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user