JDBC-based session service implementation for ADK Java.
- No ORM Dependencies: Uses JDBC with HikariCP for connection pooling
- Multi-Database Support: PostgreSQL, MySQL, H2 (SQLite not supported)
- Automatic Schema Management: Flyway migrations handle table creation/updates
- 3-Tier State Storage: Separate tables for app-level, user-level, and session-level state
- Reactive API: RxJava 3 Single/Maybe/Completable return types
- HikariCP: High-performance JDBC connection pool
- Flyway: Database schema versioning and migration
- Jackson: JSON serialization for events and state
- RxJava 3: Reactive programming support
The service creates and manages these tables:
app_states: Application-level state (shared across all users)user_states: User-level state (shared across user's sessions)sessions: Individual session dataevents: Event history for each session
// Create service with database URL
String dbUrl = "jdbc:postgresql://localhost:5432/adk?user=postgres&password=secret";
try (DatabaseSessionService sessionService = new DatabaseSessionService(dbUrl)) {
// Create a session
Session session = sessionService.createSession(
"myApp",
"user123",
new ConcurrentHashMap<>(),
null
).blockingGet();
// Append an event
Event event = Event.builder()
.id(UUID.randomUUID().toString())
.invocationId("inv-1")
.timestamp(System.currentTimeMillis())
.build();
Event appendedEvent = sessionService.appendEvent(session, event).blockingGet();
}- PostgreSQL: Full support with JSONB
- URL:
jdbc:postgresql://host:port/database?user=...&password=...
- URL:
- MySQL: Full support with JSON
- URL:
jdbc:mysql://host:port/database?user=...&password=...
- URL:
- H2: For testing and development
- URL:
jdbc:h2:mem:testdborjdbc:h2:file:./data/mydb
- URL:
- Cloud Spanner: Full support
- URL:
jdbc:cloudspanner:/projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID
- URL:
- SQLite: NOT supported (no UPSERT support)
State is stored across three tables with merge priority:
- App State (lowest priority):
app:keyprefix - User State (medium priority):
user:keyprefix - Session State (highest priority): No prefix
When retrieving a session, states are merged: app → user → session (higher priority overwrites).
Optional properties can be passed to the constructor:
Map<String, Object> props = new HashMap<>();
props.put("connectionTimeout", 30000);
props.put("maximumPoolSize", 10);
DatabaseSessionService service = new DatabaseSessionService(dbUrl, props);