mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-09 19:24:21 +01:00
## Purpose * Implement JDBC4 stream binding methods in JDBC4PreparedStatement for the following overloads: * `setAsciiStream(int, InputStream, long)`, `setAsciiStream(int, InputStream)` * `setBinaryStream(int, InputStream, long)`, `setBinaryStream(int, InputStream)` ## Changes ### In `(int, InputStream, long)` methods * Added a shared helper method `requireLengthIsPositiveInt(long length)` to validate stream length. * Validates `length` to fit SQLite’s 32-bit limit for compatibility with SQLite/Turso engines. * After validation passes, delegates to the `(int, InputStream, int)` overload for actual binding logic. ### In `(int, InputeStream)` methods - no length * Added a shared helper method `readBytes(InputStream x)`. * Reads the first byte before allocating the buffer to avoid unnecessary memory allocation for empty streams. * After reading, directly binds the data using` bindText()` (for ASCII) or `bindBlob()` (for binary). * Avoids re-wrapping the stream or reallocation since the byte array is already available. ## Related Issue * #615 Reviewed-by: Kim Seon Woo (@seonWKim) Closes #3937
Turso JDBC Driver
The Turso JDBC driver is a library for accessing and creating Turso database files using Java.
Project Status
The project is actively developed. Feel free to open issues and contribute.
To view related works, visit this issue.
How to use
Currently, we have not published to the maven central. Instead, you can locally build the jar and deploy it to maven local to use it.
Build jar and publish to maven local
$ cd bindings/java
# Please select the appropriate target platform, currently supports `macos_x86`, `macos_arm64`, `windows` and `linux_x86`
$ make macos_x86
# deploy to maven local
$ make publish_local
Now you can use the dependency as follows:
dependencies {
implementation("tech.turso:turso:0.0.1-SNAPSHOT")
}
Code style
- Favor composition over inheritance. For example,
JDBC4Connectiondoesn't implementTursoConnection. Instead, it includesTursoConnectionas a field. This approach allows us to preserve the characteristics of Turso usingTursoConnectioneasily while maintaining interoperability with the Java world usingJDBC4Connection.