JNI Driver Manager¶
The JNI driver manager wraps the C/C++ driver manager, making it possible to use drivers written in C/C++, Go, Rust, and more from Java. As the name implies, this requires JNI.
Installation¶
To include the JNI driver manager in your Maven project, add the following dependency:
<dependency>
<groupId>org.apache.arrow.adbc</groupId>
<artifactId>adbc-driver-jni</artifactId>
<version>${adbc.version}</version>
</dependency>
Usage¶
The JNI driver manager is implemented as a “driver”; parameters for opening an
AdbcDatabase are passed to the C/C++ driver
manager, and the “real” driver is loaded. Once loaded, the Java ADBC APIs are
forwarded to the equivalent C APIs, so there is no difference from other
drivers in Java, and the resulting object can be used the same way as drivers
written in Java or another JVM language.
Drivers can be directly loaded via the
PARAM_DRIVER option. This takes
a path to a driver, a driver manifest, or
a name that will be passed to dlopen (or equivalent):
JniDriver driver = new JniDriver(allocator);
Map<String, Object> parameters = new HashMap<>();
// path to driver:
JniDriver.PARAM_DRIVER.set(parameters, "/path/to/libadbc_driver_sqlite.so");
// manifest:
JniDriver.PARAM_DRIVER.set(parameters, "sqlite");
// library name:
JniDriver.PARAM_DRIVER.set(parameters, "adbc_driver_sqlite");
AdbcDatabase db = driver.open(parameters);
Another option is to pass only a URI, in which case the URI scheme will be used to find and load the driver or driver manifest:
JniDriver driver = new JniDriver(allocator);
Map<String, Object> parameters = new HashMap<>();
// Expects a profile named "postgresql" to exist (or libpostgresql.so, etc.)
AdbcDriver.PARAM_URI.set(parameters, "postgresql://localhost:5432/dev");
AdbcDatabase db = driver.open(parameters);
To use connection profiles, pass the
PARAM_PROFILE option:
JniDriver driver = new JniDriver(allocator);
Map<String, Object> parameters = new HashMap<>();
JniDriver.PARAM_PROFILE.set(parameters, "staging_aws");
AdbcDatabase db = driver.open(parameters);