ether-database-sqlite añade utilidades específicas de SQLite sobre la pila ether-database-core + ether-jdbc: cliente JDBC especializado, parámetros SQLite, clasificación de errores y configuración de PRAGMAs como WAL, foreign keys y busy timeout.
Instalación
<dependency>
<groupId>dev.rafex.ether.database</groupId>
<artifactId>ether-database-sqlite</artifactId>
<version>9.5.5</version>
</dependency>
Para ejecutar contra SQLite también necesitas el driver JDBC en runtime:
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.45.3.0</version>
<scope>runtime</scope>
</dependency>
Cliente SQLite
SQLiteConfig config = SQLiteConfig.builder()
.journalMode(JournalMode.WAL)
.synchronousMode(SynchronousMode.NORMAL)
.foreignKeys(true)
.busyTimeout(5000)
.build();
SQLiteDatabaseClient db = SQLiteDatabaseClient.builder(dataSource)
.withConfig(config)
.build();
SQLiteDatabaseClient delega las operaciones base a JdbcDatabaseClient, pero permite aplicar configuración SQLite al inicializar conexiones.
PRAGMAs recomendados
try (Connection connection = dataSource.getConnection()) {
SQLitePragmas.apply(connection, SQLiteConfig.defaults());
}
Los modos principales son:
| Configuración | Uso |
| JournalMode.WAL | Mejora concurrencia de lecturas/escrituras |
| SynchronousMode.NORMAL | Balance entre rendimiento y durabilidad |
| foreignKeys(true) | Activa validación de claves foráneas |
| busyTimeout(5000) | Espera antes de fallar por base bloqueada |
Parámetros SQLite
SqlQuery query = SqlQuery.of(
"INSERT INTO audit_log (payload, created_at) VALUES (?, ?)",
List.of(
SQLiteParameters.json("{\"event\":\"login\"}"),
SQLiteParameters.integer(System.currentTimeMillis())
)
);
db.execute(query);
SQLiteParameters cubre las clases de almacenamiento habituales: BLOB, INTEGER, REAL, TEXT y JSON vía la extensión JSON1 cuando está disponible.
Errores SQLite
try {
db.execute(insertQuery);
} catch (SQLException e) {
throw SQLiteErrorClassifier.classify(e);
}
SQLiteErrorCodes expone constantes para códigos frecuentes como unique, foreign key, not null, check, busy y locked.
Más información