Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@
<artifactId>spring-jdbc</artifactId>
</dependency>

<dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this dependency for the other JDBC implementations.

<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>

<!-- TESTING -->

<dependency>
Expand Down Expand Up @@ -85,6 +80,18 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
<version>23.4.0.24.05</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static JdbcChatMemoryRepositoryDialect from(DataSource dataSource) {
case "MySQL", "MariaDB" -> new MysqlChatMemoryRepositoryDialect();
case "Microsoft SQL Server" -> new SqlServerChatMemoryRepositoryDialect();
case "HSQL Database Engine" -> new HsqldbChatMemoryRepositoryDialect();
case "Oracle" -> new OracleChatMemoryRepositoryDialect();
default -> // Add more as needed
new PostgresChatMemoryRepositoryDialect();
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.springframework.ai.chat.memory.repository.jdbc;

public class OracleChatMemoryRepositoryDialect implements JdbcChatMemoryRepositoryDialect {

@Override
public String getSelectMessagesSql() {
return "SELECT content, type FROM SPRING_AI_CHAT_MEMORY WHERE CONVERSATION_ID = ? ORDER BY \"TIMESTAMP\"";
}

@Override
public String getInsertMessageSql() {
return "INSERT INTO SPRING_AI_CHAT_MEMORY (CONVERSATION_ID, CONTENT, TYPE, \"TIMESTAMP\") VALUES (?, ?, ?, ?)";
}

@Override
public String getSelectConversationIdsSql() {
return "SELECT DISTINCT conversation_id FROM SPRING_AI_CHAT_MEMORY";
}

@Override
public String getDeleteMessagesSql() {
return "DELETE FROM SPRING_AI_CHAT_MEMORY WHERE CONVERSATION_ID = ?";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
DROP TABLE SPRING_AI_CHAT_MEMORY;

CREATE TABLE SPRING_AI_CHAT_MEMORY (
CONVERSATION_ID VARCHAR2(36 CHAR) NOT NULL,
CONTENT CLOB NOT NULL,
"TYPE" VARCHAR2(10 CHAR) NOT NULL CHECK (
"TYPE" IN (
'USER',
'ASSISTANT',
'SYSTEM',
'TOOL'
)
),
"TIMESTAMP" TIMESTAMP NOT NULL
);

CREATE INDEX SPRING_AI_CHAT_MEMORY_CONVERSATION_ID_TIMESTAMP_IDX
ON SPRING_AI_CHAT_MEMORY(
CONVERSATION_ID,
'TIMESTAMP'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.springframework.ai.chat.memory.repository.jdbc;

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.jdbc.Sql;

@SpringBootTest
@TestPropertySource(properties = {
"spring.datasource.url=jdbc:oracle:thin:@localhost:1521/FREEPDB1",
"spring.datasource.username=scott",
"spring.datasource.password=tiger"})

@Sql(scripts = "classpath:org/springframework/ai/chat/memory/repository/jdbc/schema-oracle.sql")
class JdbcChatMemoryRepositoryOracleIT extends AbstractJdbcChatMemoryRepositoryIT {

}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Spring AI supports multiple relational databases via a dialect abstraction. The
- MySQL / MariaDB
- SQL Server
- HSQLDB
- Oracle Database

The correct dialect can be auto-detected from the JDBC URL when using `JdbcChatMemoryRepositoryDialect.from(DataSource)`. You can extend support for other databases by implementing the `JdbcChatMemoryRepositoryDialect` interface.

Expand Down