RoomDataStorage
Room-based implementation of the DataStorage interface for the KARL framework.
This class provides a robust, production-ready data persistence layer using Android's Room database library. It implements the complete DataStorage contract with support for user data isolation, efficient querying, and transactional safety guarantees.
Database Architecture:
Entity-Based Design: Uses Room entities to map domain models to SQL tables
DAO Pattern: Leverages Data Access Objects for type-safe database operations
Transaction Support: Ensures atomic operations for data consistency
Migration Support: Built-in schema versioning for database evolution
Performance Characteristics:
Thread Safety: All database operations are dispatched to IO thread pool
Connection Pooling: Leverages Room's built-in connection management
Query Optimization: Uses indexed queries for efficient data retrieval
Memory Efficiency: Minimal object allocation through entity reuse
Data Isolation: User data is strictly partitioned by userId, ensuring complete privacy isolation between different users of the same application. This supports multi-user scenarios and privacy compliance requirements.
Coroutine Integration: All operations are implemented as suspending functions that work seamlessly with Kotlin coroutines. Database operations are automatically dispatched to the IO dispatcher to prevent blocking the main thread.
Error Handling: The implementation provides robust error handling with appropriate exception propagation and recovery mechanisms for database-related failures.
Since
1.0.0
Author
KARL Development Team
Parameters
The Room DAO instance providing type-safe database access operations
Coroutine dispatcher for background database operations, defaults to Dispatchers.IO for optimal I/O performance
See also
The interface contract this implementation fulfills
The data access object providing database operations
The Room database configuration and entity definitions
Functions
Permanently removes all stored data for a specific user.
Initializes the Room-based storage system for operation.
Retrieves the most recently saved learning state for a specific user.
Retrieves recent user interactions for contextual prediction generation.
Persists the current learning state for a specific user with transactional safety.
Persists individual user interaction data for context and analysis.